我正在尝试从我添加到AOSP(7.1.1)的系统/ priv-app运行shell命令
我试图运行的命令是: ip link add dev can0 type 可以打开can总线。
我将图像构建为 -eng & -userdebug 发布。 该命令在adb shell中运行良好,并按预期成功打开CAN总线。
我的问题是我收到以下错误:
无法运行程序" su":错误= 13,权限被拒绝
当我在系统特权java app中尝试以下代码时:
//ArrayList<String> commands is passed into the method
try {
if (null != commands && commands.size() > 0) {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
for (String currCommand : commands) {
os.writeBytes(currCommand + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
BufferedReader stderr = new BufferedReader(new InputStreamReader(suProcess.getErrorStream()));
String line = "";
String errString = "";
while ((line = stderr.readLine()) != null) errString += line + "\n";
suProcess.waitFor();
if (suProcess.exitValue() != 0)
throw new Exception(errString);
} //Handle exception
答案 0 :(得分:0)
您可以尝试这样做:
Process mProcess = new ProcessBuilder()
.command("/system/xbin/su")
.redirectErrorStream(true).start();
DataOutputStream out = new DataOutputStream(mProcess.getOutputStream());