Why do I get access denied to data folder when using adb?
$ adb shell
$ cd /data
$ ls
opendir failed, Permission denied
You should do this:
$ adb shell
$ cd /data
shell@android:/data $ run-as com.your.package
shell@android:/data/data/com.your.package $ ls
OK!
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).
before we start, do you have a rooted phone? if not, I strongly suggest that it's time you make the jump. 99% of the tutorials that help you to do this require that you have a rooted phone (I know b/c I spent about an hour searching for a way to do it without having a rooted phone.. couldn't find any..) also if you think about it, your iPhone also has to be rooted to do this same task. So it's totally reasonable. More about rooting at end of answer.
from your command line type:
adb shell
this takes you to your android shell comand line (you should see something like this: shell@android:/ $
now type:
shell@android:/ $run-as com.domain.yourapp
this should take you directly to the data directory of com.domain.yourapp
:
shell@android:/data/data/com.domain.yourapp $
if it doesn't (ie if you get an error) then you probably don't have a rooted phone, or you haven't used your root user privileges. To use your root user privileges, type su
on the adb command line and see what happens, if you get an error, then you're phone is not rooted. If it's not, root it first then continue these instructions.
from there you can type ls
and you'll see all the directories including the dbs:
shell@android:/data/data/com.domain.yourapp $ ls
cache
databases
lib
shared_prefs
after that you can use sqlite3 to browse the dbase.. if you don't have it installed (you can find it out by typing sqlite3
, if you get command not found
then you'll have to install it. To install sqlite, follow instructions here.
about rooting: if you've never rooted your phone before, and you're worried about it screwing your phone, I can tell you with full confidence that there is nothing to worry about. there are tonnes of quick and easy phone rooting tutorials for pretty much all the new and old models out there, and you can root your phone even if you have a mac (I rooted my s3 with my mac).
There are two things to remember if you want to browse everything on your device.
- You need to have a phone with root access in order to browse the data folder on an Android phone. That means either you have a developer device (ADP1 or an ION from Google I/O) or you've found a way to 'root' your phone some other way.
- You need to be running ADB in root mode, do this by executing:
adb root