8

Using adb.exe that comes with the Android SDK, I can get root access to an Android device. For testing purposes, I would like to give an Android app root permissions as well. I know that app is running under a particular account called app_68. Is there an adb shell command to add app_68 to the "root group"?

Thanks in advance for your comments/solutions.

ytw
  • 1,335
  • 2
  • 20
  • 42
  • 1
    I believe the only method is to use command-line like: `Runtime.getRuntime().exec("su");` That will change the app's UID to 0 so it has root priveleges. (of course the correct binaries must already be installed). [This](http://code.google.com/p/roottools/) is a big help if you're using root in your app. – Reed Mar 05 '12 at 23:27
  • I tried to execute "Runtime.getRuntime().exec("su");" from a test Android app and got an error message "su: uid 10069 not allowed to su". I guess the app can't change itself to run under the su account. – ytw Mar 05 '12 at 23:55
  • 3
    You would have to have SuperUser and BusyBox installed. If you've done both of those, then possibly you have accidentally declined your test app in SuperUser – Reed Mar 06 '12 at 01:38
  • 1
    @Jakar: It would be interesting to know if this could be done without SuperUser and BusyBox installed. – PCoder Feb 12 '13 at 10:23
  • There is no such thing as root permission for an app, as applications cannot execute as root. Various customized alterations may have a system for running helper tasks or executables as root, and those may have authorization schemes you can target, but they are unique to those extensions - they are not part of "android". – Chris Stratton May 28 '16 at 19:18

1 Answers1

1

You need the superuser (su) binary to run your app as root user. For running as root implement this:

Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());

os.writeBytes("yourCommand\n");

os.writeBytes("exit\n");

os.flush();
os.close();
try { p.waitFor(); } catch (InterruptedException e) {}

If you get something like su: uid xxxx not allowed, then you need to update your su-binary using SuperSU.

Also see https://stackoverflow.com/a/26654728/4479004 if you want a fully detailed and working source.Just look at the code below:

Update: To get the result (the output to stdout), use:

Community
  • 1
  • 1
xdevs23
  • 3,824
  • 3
  • 20
  • 33