4

I am using adb(Android Debug Bridge) and working with shell in the Genymotion Emulator(I have mentioned every configurations at the end of this question).

I execute "adb shell" and get the shell successfully but the problem is that I get the root access on the emulator. I don't want root shell, I want the normal one as we get when we execute 'adb shell' on the actual device connected via USB. How to achieve it ?

Any help would be highly appreciated.

*Configuration :

Ubuntu 13.10, 32-bit.

Eclipse 4.2 with ADT.

Genymotion Emulator(To be specific, I was using Android 4.3 here).

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
node_analyser
  • 1,502
  • 3
  • 17
  • 34
  • 1
    IIRC is controlled by ro.secure and ro.debuggable in setprop/getprop, but you'll have to research how to actually change that. – Chris Stratton Jan 06 '14 at 16:04
  • Reverted title edit as the issue is generic to Android, not anything specific to Genymotion (and technically not specific to emulators either, though that's the only place most developers encounter unsecured installs) – Chris Stratton Jan 06 '14 at 16:06
  • @Chris Stratton : I guess the emulator will matter here. Don't you think so ? – node_analyser Jan 06 '14 at 16:12
  • 1
    No, it won't. The userid of ADBD is determined by the Android system running *inside* the emulator, not on the *emulator* containing it. Hence it is controlled by the Android configuration system. – Chris Stratton Jan 06 '14 at 16:13
  • Ok. I will research for ro.secure and ro.debuggable. – node_analyser Jan 06 '14 at 16:37
  • @ChrisStratton -- I tried playing with ro.secure and ro.debuggable. For root access ro.secure=0 so I turned it to 1 ie ro.secure=1 and kept ro.debuggable=1. But I still get the shell as root. :-( – node_analyser Jan 07 '14 at 08:14
  • I think there's also an ro.emulator or something like that, which implies root ADB as well (I remember one device where it's possible to set that to get a sort of temporary root by making the device think it is an emulator). Another idea - if you only need this for experiments, it's likely that Android default `su` when (invoked as root) could be made to give you a copy of `sh` running as the `shell` userid adbd runs it as on secured device. But that would only apply to that shell session - you'd still be able to adb push, pull, etc to places you can't on a secured device. – Chris Stratton Jan 07 '14 at 15:26
  • @ChrisStratton - Hey I found out why our idea of ro.secure is not working. For root they have set ro.secure to 0 and to solve my problem I need to do ro.secure=1. Initially I changed the ro.secure=1 in /system/build.prop BUT came to know that Android uses default.prop file during startup. I changed the ro.secure to 1 in default.prop. Now the problem is after setting the value to 1, I need to reboot but the Android settings are such that default.prop is set to its default value on every startup. Therefore again it gets ro.secure=0 and I get root access.I think we are very near to the solution – node_analyser Jan 07 '14 at 16:34
  • These files you are changing are probably in the compressed image packed alongside the kernel, so you get an unmodified version on every boot. You'll need to unpack that, modify it, and repack it - not trivial. It's possible that killing adbd would get it to restart without rebooting. – Chris Stratton Jan 07 '14 at 16:50
  • I tried killing adbd but no change. Finally,I will have to unpack recovery.img from ramdisk. I did 'cat /proc/mtd' but it doesn't show me anything(no error but displays nothing). Even tried 'cat /proc/emmc' but there's nothing like emmc in /proc so it generates error.I have 'mtd' named file inside '/proc' but its size is 0. Where can I find recovery.img now ?? – node_analyser Jan 09 '14 at 10:46
  • https://stackoverflow.com/a/25490518/1778421 – Alex P. Jun 19 '18 at 14:25

2 Answers2

7

It has been long since I posted this question but still want to answer it as it might help someone in need.

Main purpose of mine was to get a non-root shell on emulator for some testing purposes but failed to do so after many attempts.

Sometimes back, by fluke, I was fiddling around playstore app inside emulator and indirectly came across solution to above question.

I noticed while creating an emulator, if I used "Google Play" as the image, I got an emulator which was not root.

Follow below steps to get an Android emulator without root:

  1. Create a new virtual device and select the one where "playstore" column has playstore icon (small triangle) visible, as seen in screenshot below.

enter image description here

  1. In next step, download appropriate files needed for creating the device. Make sure to select the target/ABI as "Google Play" and not "Google API". It will make all the difference. In below image you can see I have 2 AVDs (Android Virtual Devices), first (andy_7) with target as "Google API" and another (nexus_5) with target as "Google Play".

enter image description here

  1. Start the avd with target Google Play, nexus_5 in our case and we will get the desired result.

enter image description here

node_analyser
  • 1,502
  • 3
  • 17
  • 34
  • Unfortunately, Google Play images are not available for Tablet devices in Android Studio. If someone realises how to do it please let me know. – Ayaz Alifov May 06 '22 at 15:13
4
adb shell setprop service.adb.root 0
adb shell setprop ctl.restart adbd

or

adb unroot

for short.

ephemient
  • 198,619
  • 38
  • 280
  • 391
  • Thanks for the reply but unfortunately this does not work. Both the commands `adb shell.....` do get executed without error but nothing seems to happen. After executing the commands, if I `adb shell` into emulator, its still giving me `uid` and `gid` zero. :( – node_analyser Feb 03 '17 at 10:02
  • What is the path to execute adb unroot command ? – max092012 Jun 02 '21 at 07:11