Aaron Thompson
Aaron Thompson

Reputation: 1889

adb root works Runtime.GetRuntime().Exec("su"); does not

I am running android 7.1.1 on a custom device with the AOSP compiled from source in the 'userdebug' configuration, which gives root access and debug.

I can connect to the device using the android device bridge.

adb root
adb shell
device_name:/ # su

All of these commands work fine and I can make changes as a super user. The problem I am having is running the same "su" command from an app

Java.Lang.Process suProcess = Runtime.GetRuntime().Exec("su");

The error I am receiving is:

Java.IO.IOException: Cannot run program "su": error=13, Permission denied

Is there a difference between the adb root/ shell su commands and the commands run from within an app?

Upvotes: 5

Views: 9555

Answers (1)

David Lev
David Lev

Reputation: 813

It looks like both linux DAC and SE-Android are blocking your application's process from accessing the 'su' executable.

Check if your system is running in enforced mode, meaning that SE-Android is enabled. If this is indeed the case, you can temporarily disable it by running:

adb root

adb shell setenforce 0

This will disable SE-Android and will not block the apps process from executing 'su'.

Additionally, your app might not have the DAC permissions necessary to launch 'su' as root. You can execute the following command:

adb shell ps

For a list of all running processes on your device. locate your app (by searching for its package name), and check its group and uid. Most probably neither are root.

Please note that building a custom userdebug image is not quite like rooting a standard Android device. The debug version is meant to allow access to the device's internals while still simulating a real functioning device with all of its default security mechanisms enabled.

Upvotes: 5

Related Questions