I connected to my live device using the adb and the following commands:
C:\>adb -s HT829GZ52000 shell
$ ls
ls
sqlite_stmt_journals
cache
sdcard
etc
system
sys
sbin
proc
logo.rle
init.trout.rc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
$ cd data
cd data
$ ls
ls
opendir failed, Permission denied
I was surprised to see that I have access denied. How come I can't browse around the directories using the commandline like this?
How do I get root access on my phone?
Starting from API level 8 (Android 2.2), for the debuggable application (the one built by Android Studio all the times unless the release build was requested), you can use the shell run-as
command to run a command or executable as a specific user/application or just switch to the UID of your application so you can access its data directory.
List directory content of yourapp:
run-as com.yourapp ls -l /data/data/com.yourapp
Switch to UID of com.yourapp and run all further commands using that uid (until you call exit
):
run-as com.yourapp
cd /data/data/com.yourapp
ls -l
exit
Note 1: there is a known issue with some HTC Desire phones. Because of a non-standard owner/permissions of the /data/data
directory, run-as
command fails to run on those phones.
Note 2: As pointed in the comments by @Avio:
run-as
has issues also with Samsung Galaxy S phones running Cyanogenmod at any version (from 7 to 10.1) because on this platform /data/data
is a symlink to /datadata
. One way to solve the issue is to replace the symlink with the actual directory (unfortunately this usually requires root access).