Obtain root access via su on the Android emulator
Ok, I solve the problem by myself :/
It works with sdk revision 10 and in an avd 2.2. The problem with the tip I have followed previously is the remount step. Here is the list of commands working for me (extract from http://forum.xda-developers.com/showthread.php?t=821742) :
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
adb push su /system/xbin/su
adb shell chmod 06755 /system
adb shell chmod 06755 /system/xbin/su
adb install superuser.apk
You can get the su binary and the superuser app here : http://forum.xda-developers.com/showthread.php?t=682828
You have to do that each time you start the emulator.
how to get root access on android 2.3 emulator
On the emulator provided with the SDK r10, you can get a root shell executing "adb shell" from your host computer. Once you have such root shell, you cat follow this steps to get a command that can log you as root from the terminal emulator:
# Remount /data to allow executables and setuids on it
mount -o remount,rw /dev/block/mtdblock1 /data
# There's no "cp" command on Android
cat /system/bin/sh > /data/su
# Give setuid permissions to the shell
chmod 7755 /data/su
Now, from the emulator, just run "/data/su" and that's it, you're root.
The normal "/system/xbin/su" command included in the SDK performs internal user id checks, so these commands...
mount -o remount,rw /dev/block/mtdblock0 /system
chmod 7755 /system/xbin/su
...just won't work. There's no way to trick /system/xbin/su to allow the normal user (UID 10018 in my case) to become root.
Please note that dealing with setuid programs can be a security risk (not higher than having a universal "su" command, though). Use this solution at your own risk.
How can I get root access on an Android 7.0 emulator?
I'm writing the json files to /data/data//files using context.getFilesDir().getPath() + "/" + fileName
That is internal storage, not external storage.
Use adb shell run-as ... ???
to run commands as your app's user, which will allow those commands to access internal storage. Here, ...
is the application ID of your app, and ???
is a command.
So, for example, to list the contents of a typical location for getFilesDir()
for an app whose user ID is com.foo.bar
, use:
adb shell run-as com.foo.bar ls /data/data/com.foo.bar/files
This only works for debuggable apps.
Related Topics
Startactivityforresult from Activitygroup
Onpagefinished() Never Called (Webview)!
How Open New Activity Clicking an Item in Listview
How to Configure Gmail in Android Emulator
Couldn't Get Connection Factory Client - Fighting with Google Maps
Onlistitemclick Is Not Working for Listview
Android 4.3 and Phonegap, Cant Tap Link
What Are The Default Color Values for The Holo Theme on Android 4.0
How to Compile Ffmpeg-2.2.2 on Windows with Cygwin and Android Ndk R9C
Android Listview with Header and Footer Buttons
Layout Problem with Button Margin
Howto Do a Simple Ftp Get File on Android
Input Has Different Style on Focus
How to Stack Firebase Cloud Messaging Notifications When the Application Is Not Running
Bordercolor Not Picking The Lineargradient Color on Android
Using Picasso Library with Listview
How to Set a Ripple Effect on Textview or Imageview on Android