I am trying to run shell commands from a system / private application that I added to AOSP (7.1.1)
The command I'm trying to run is: ip link add dev can0 type can enable the can bus.
I created an image for both -eng and -userdebug . The command works fine in the adb shell and successfully enables the CAN bus as expected.
My problem is that I get the following error:
Cannot start program "su": error = 13, Permission denied
When I try to use the following code in a system privileged java application:
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);
}
source
share