這段代碼演示了如何在Java代碼裡,通過調用su命令來臨時修改某些檔的存取權限
Runtime ex = Runtime.getRuntime();
String cmdBecomeSu = "su";
String script = "busybox chmod a+rw /dev/pmem";
try{
java.lang.Process runsum = ex.exec(cmdBecomeSu);
int exitVal = 0;
final OutputStreamWriter out = new OutputStreamWriter(runsum.getOutputStream());
// Write the script to be executed
out.write(script);
// Ensure that the last character is an "enter"
out.write("\n");
out.flush();
// Terminate the "su" process
out.write("exit\n");
out.flush();
exitVal = runsum.waitFor();
if (exitVal == 0) {
Log.e("Debug", "Successfully to su");
}
} catch ( Exception e){
Log.e("Debug", "Fails to su");
}



 

如果是測試程式,必須要root或者system許可權可以用

 

android.permission.FACTORY_TEST 作為一個工廠測試程式,運行在root使用者(Run as a manufacturer testapplication, running as the root user. )
<uses-permission android:name="android.permission.FACTORY_TEST"></uses-permission>
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()