3

I am using the current code and it will not work on a rooted phone. Can anyone tell me why?

public void setpermission()
    {
    try
    { 
    Process process1 = Runtime.getRuntime().exec("su");
    process1.waitFor();
    Process process2 = Runtime.getRuntime().exec("/system/bin/sh chmod 0777  /data/playback.bin");
    process2.waitFor();
    }
    catch((Exception e) {
    e.printStackTrace();
}
ObieMD5
  • 2,684
  • 1
  • 16
  • 26
Krishna
  • 53
  • 1
  • 5

2 Answers2

3

I think you could be encountering an issue when the command string is parsed.

/system/bin/sh chmod 0777 /data/playback.bin is treated as "/system/bin/sh" "chmod" "0777" "/data/playback.bin/" with the extra quotes. Not sure if that is the reason for failure, but try the following instead:

Process process = Runtime.getRuntime().exec("su");
DataOutputStream suStream = new DataOutputStream(process.getOutputStream());

suStream.writeBytes("/system/bin/sh chmod 0777  /data/playback.bin" + "\n");

suStream.writeBytes("exit\n");
suStream.flush();
suStream.close();

process.waitFor();

Note that you should get the app root permission popup after exec("su"), so if you don't then it never gets to the point of even attempting to execute your file permission change command.

EDIT - You could also try this variation of the above (based on this answer):

Process shell = Runtime.getRuntime().exec("su", null, new File("/system/bin/"));
OutputStream os = shell.getOutputStream();

os.write(("chmod 777 /data/playback.bin").getBytes("ASCII"));
os.flush();
os.close();
shell.waitFor();
Community
  • 1
  • 1
Ryan Weir
  • 6,377
  • 5
  • 40
  • 60
  • :Thanks for fast update, I used your code, Its asking permission(Grant or Deny) after executing Process process = Runtime.getRuntime().exec("su"); but after process.waitFor();its crashing, can you please guide me what might be the problem, in the mean time i will continue debugging. – Krishna Aug 06 '13 at 06:34
  • See my edit. Also you should try opening a terminal directly and going superuser, then executing the chmod command yourself and see if there's any error output. – Ryan Weir Aug 07 '13 at 22:58
  • 1
    We need any SuperUser Apk installed on the Phone to get the above code to work (I Installed SuperSu via adb sideload) and this is working fine. – Krishna Aug 19 '13 at 07:46
0

Are you sure all your processes do start? I doubt there's a su though I might be wrong.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158