On the SDK emulators and virtual machines like Genymotion, adbd
starts up as root and provides a root shell. Short of modifying the source code to do otherwise and rebuilding your VM images, I think you will have to use the su
approach suggested above. su shell
does indeed work on both SDK emulators as well as the Genymotion VMs. Specifically:
ubuntu$ adb shell
android# id
uid=0(root) gid=0(root) context=u:r:shell:s0
android# su shell
android$ uid=2000(shell) gid=2000(shell) context=u:r:su:s0
Note that the initial shell is running as uid 0 and after su shell
is running as uid 2000. In fact, you can su to any Linux uid (Android userId
+appId
) configured on your emulator/VM. For example, after doing adb shell
from Ubuntu:
android# su u0_a16
android$ id
uid=10016(u0_a16) gid=10016(u0_a16) context=u:r:su:s0
android$
On my emulator, uid 0010016 is the calendar app for user 0 (owner, userId
00). Remember that after you su, you only have the privileges of the new uid, and this may not include permissions to run Linux commands or view certain directories.
Finally, if you just need to do one or two operations as the non-root user, you can string the whole thing together as one command in Ubuntu. Something like:
ubuntu$ adb shell su u0_a16 id
uid=10016(u0_a16) gid=10016(u0_a16) context=u:r:su:s0
or
ubuntu$ adb shell su radio cat /data/data/com.android.phone/shared_prefs/*.xml\; su radio id
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="_has_set_default_values" value="true" />
</map>
uid=1001(radio) gid=1001(radio) context=u:r:su:s0
Above tested on SDK x86 emulator running 4.4.2 and Genymotion VM running 4.4.2.
su shell
to become the "shell user". That's the oneadb shell
normally uses on devices. But I'm not sure if it is available on the emulator, so please let us know if it works. If theshell
user is not available, you could checkls -l /data/data
to pick the user of some app to try with.