Reputation: 63
public void uninstallApp(String packageName){
try {
String[] command = new String[4];
command[0] = "su";
command[1] = "mount -o remount,rw /system";
command[2] = "rm " + packageName;
command[3] = "reboot";
Runtime run = Runtime.getRuntime();
run.exec(command);
Log.d("DELETED", packageName);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e("ERROR ON DELETE", e.getMessage());
}
}
That's my code. This method receives an apk's path, what i need to do is execute those commands but without loosing permissions. I mean, if i execute "su" in one process and then "mount" in other process. "mount" won't have "su" access. So i need to execute all those commands in a single process. And that's not working. :\
Upvotes: 1
Views: 5332
Reputation: 2113
You don't need to use ProcessBuilder pattern. just add your commands to the String array in order:
Process process = Runtime.getRuntime().exec(new String[]{"su", "-c", command1, command2});
Upvotes: 0
Reputation: 63
FOUND SOLUTION
StringBuilder cmdReturn = new StringBuilder();
try {
ProcessBuilder processBuilder = new ProcessBuilder("su","-c mount -o remount,rw /system ; rm " + packageName + " ; reboot");
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
int c;
while ((c = inputStream.read()) != -1) {
cmdReturn.append((char) c);
}
Log.d("CMD RESPONSE", cmdReturn.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1