Click here to Skip to main content
14,489,405 members

Accessing Internal Data on Android Device

Rate this:
4.92 (11 votes)
Please Sign up or sign in to vote.
4.92 (11 votes)
4 Oct 2014CPOL
This article will explain how to explore Android internal data from Eclipse DDMS perspective using adb and Linux commands.

Preface

In this tutorial, I will explain how to view your Android internal files using Eclipse DDMS perspective.

I will briefly explain about the Linux file permissions and the basic use of adb tool with illustrated examples for Windows users; however other operating system users can benefit from this article as well, because the concept is the same.

The Risks

Changing file permissions can be very dangerous if you don't know exactly what you are doing. Once you open your file/directory to the “world”, it can be observed or even changed (depends on the permission type) by someone else.

I am encouraging you to make those changes only for your application package­­­ directory. When you done, set back the default permissions for all files that you’ve changed.

Be safe.

Eclipse DDMS

In order to view Android internal device files in Eclipse, you will need to open the DDMS perspective:

If you do not already have the DDMS tab near the Java and Debug tabs, do as follows:

(In Eclipse Main Menu Bar)

Window -> Open Perspective -> DDMS

File Explorer

In DDMS, go to File Explorer tab, you should see the folder list as you click:

Image 1

There is a directory called data that we are interested in.

If you cannot open the data folder in Eclipse, that means you do not have an appropriate permission for this file.

So what we need to do is acquire this permission, in order to access it.

Using Android adb

What is Android adb?

Android adb (Android Debug Bridge) is a part of ADT (Android Development Tools) which is a command line tool that lets you communicate with Android connected devices; it can be an emulator or a real hardware device.

Opening adb

The adb tool is located in your SDK location under platform-tools directory:

[Your path to SDK directory]\ platform-tools

In my case:

C:\android_sdk\platform-tools

In order to start integration with adb, you need to open a CMD (Windows Command Line) in this directory.

You can simply press [SHIFT + Right mouse button] and select the [Open command window here] Option from the menu or navigate to your path:

Image 2

Basic Integration with adb

All the commands with adb will be performed through the adb shell prefix, which specifies that we are going to use the Linux shell ability.

The very basic command is to see the list of connected devices.

Simply type in “adb devices”.

If you do not have any connected devices or launched emulators, you will get an empty response.

However, if you connected a device or launched an emulator, you will get a similar response to mine.

The output is formatted like this:

[serial number] [state]

Image 3

Other Common adb Commands

  • adb kill-server - stops the integration port daemon process
  • adb start-server - starts the integration port daemon process
  • adb pull – gets specified file from Android to your machine
  • adb push – pushes specified file from your machine to Android
  • adb install – installs a package on your Android device
  • adb uninstall – uninstalls a package from your Android device

There are many more adb commands and abilities, such as sqlite commands, etc.

Understanding Linux File Permissions

If you are looking at the File Explorer tab in Eclipse, you will notice that for each file, there is a permissions value:

Image 4

Linux File Permission Convention

As you can see, the permission value for each file is represented by 10 characters which are a 10 bit behind the scene.

The first character identifies the file type.

Linux File Types Encoding

  • d – Directory file
  • c – Character device
  • b – Block device
  • s – Local Domain Socket
  • p – Named pipe
  • l – Symbolic link
  • - – Regular file

These are the types of the Linux files; you don't need to understand them all. In this tutorial, we will examine only the Regular file type (symbolized as ‘-‘ character) and the directory type (symbolized as ‘d’ character).

File Permission Overview

The first character in the permission value is the file type; the following 9 characters represent the file permission.

For example, we have file with this permission value: -rwxrwxrwx

We can already say that it is a regular file, thus the first character (-).

The rest of the 9 symbols are separated by 3 parts:

Image 5

  • User permission – This is the permission for the user who created the file, the file owner.
  • Group permission – In Linux, each file or directory belongs to a group. Anyone who belongs to that group has these permissions for the file.
  • World permission – This permission is granted for everyone.

In our example, this particular file is accessible with rwx (Read/Write/Execute) permission for the owner, the group and the world, in other words, for every one.

File Permission Values

As we already said, the permission value is formed by 3 groups.

The value that you see in the DDMS is human readable format, but behind it, there is a binary value.

  • --- : binary value: 000, octal value: 0
  • --x : binary value: 001, octal value: 1
  • -w- : binary value: 010, octal value: 2
  • -wx : binary value: 011, octal value: 3
  • r-- : binary value: 100, octal value: 4
  • r-x : binary value: 101, octal value: 5
  • rw- : binary value: 110, octal value: 6
  • rwx : binary value: 111, octal value: 7

In case you have rwx (Read/Write/Execute) permission on a file, the actual bits identifying that permission will be a binary value of 111, which in octal number system are 7 (as shown in the table above).

data/data Directory

Directory named data holds the main data of your Android operating system.

One level below, there is a directory called data/data which is where all of your installed applications are located, as well as their internal files, such as databases, etc.

Using adb to Change File Permission

In my case, if you look at the snapshot that I took from my DDMS File Explorer, the permission for the data directory is: drwxrw—x

Image 6

drwxrw—x means:

  • File type: d (Directory),
  • Owner permission: rwx (Read/Write/Execute),
  • Group permission: rwx (Read/Write/Execute),
  • World permission: --x (Only Execute), cannot read the internal data of the directory, or write into it.

When we use Eclipse DDMS, we are considered as those with world permission. That’s why we need to acquire read and write permission for data directory, in order to access it or to make changes.

Using chmod Command

chmod is a Linux command, it changes the specified file or directory mode (file permission) bits according to passed mode, which can be a symbolic or an octal value that represents the bit pattern of the new mode.

* In this tutorial, we will use the octal value in our chmod command implementation, but you can simply change it to a symbolic representation if you wish.

Steps

  1. Open the CMD in the [SDK location]\platform-tools directory as I described earlier.
  2. Type the chmod command:
    adb shell su -c "chmod 777 /data"

If you get “Permission denied” from the adb, ensure that you allowed adb interaction with your device from Developer options menu.

If your device is rooted and connected, you will now see the permission of the data folder changed to –rwxrwxrwx.

Image 7

Let’s examine what we just did:

The command we typed in: adb shell su -c "chmod 777 /data"

  • su - tells the adb shell that we are executing the command as the root user.
  • -c – is the su command option, which tells su to execute the command that directly follows it on the same line.
  • “chmod 777 /data” – tells to grand 777 permission to data directory, 777 is an octal number that stands for rwx (Read/Write/Execute) permission for all three parts (Owner, Group, World).

That’s it! Now we can access the data directory from the DDMS in Eclipse.

Image 8

We need to access the data/data directory, so there is another level to grant permission to.

Notice that data/data permission is drwxrwx--x. So now we will grant the rwx for world permission to data/data directory:

Type in: adb shell su -c "chmod 777 /data/data"

Image 9

Now we can see that data/data permission is changed to –rwxrwxrwx value and we can enter it:

Image 10

Here (in data/data directory), you can see all the installed applications directories on your device shown as their packages names.

For example:

If you installed Mozilla Firefox on your device, you’ll have a directory named com.mozilla.firefox on the list.

If you launched your application named “net.tutorial.crypto”, you will see this directory on the list as well.

Since the permission below is drwxr—x, you need to perform the same chmod command for each of the folders and their internal files.

Accessing Specific Application Internal Files

Let’s say that I installed my application with package name net.tutorial.crypto, the default permission value will be drwxrwx—x.

Image 11

In order to access it, I will launch this command:

adb shell su -c "chmod 777 /data/data/net.tutorial.crypto"

which will change the permission to drwxrwxrwx value.

Image 12

To access the files folder, I will specify the desired directory name in my chmod command:

adb shell su -c "chmod 777 /data/data/net.tutorial.crypto/files".

Image 13

Now you can see that there is a classified_file.txt file in the file directory with –rw------- permission. To acquire appropriate permission, I will execute the chmod command as follows:

adb shell su -c "chmod 777 /data/data/net.tutorial.crypto/files/classified_file.txt".

Image 14

Since classified_file.txt permission is changed to –rwxrwxrwx, I can pull it from the device and explore it on my PC.

Pull Command:

Convention: adb pull <remote path> <local path>

(copies the file from Android device to local machine)

I decided to pull it to my Download folder:

adb pull /data/data/net.tutorial.crypto/files/classified_file.txt C:\Users\Pavel\Downloads

Image 15

You can use the eclipse GUI button called “Pull a file from the device” that has the same functionality, as well. Simply select the desired file and click on the button. Then select the destination and finally save.

Image 16

Summary

Android is a Linux based operating system, that’s why in order to access its internal files, you need to have appropriate permission for those files.

We used adb tool through which we granted the permission for our desired files, using the chmod Linux command, and explored them in Eclipse DDMS.

adb is one of the useful tools that I came across while developing for Android platform. Using its abilities can save you a lot of time and headaches. Please consider further reading the Android documentation:

Hope it was helpful.

History

  • 4th October, 2014: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pavel Durov
Software Developer
Israel Israel
No Biography provided

Comments and Discussions

 
QuestionCan I use this to add gem in my clash f clan game Pin
Member 1352947619-Nov-17 4:00
MemberMember 1352947619-Nov-17 4:00 
QuestionECLIPSE Version Pin
dchin15-Nov-16 15:47
Memberdchin15-Nov-16 15:47 
Questionchange permission for /storage/emulated/0 Pin
img3nius6-Nov-16 20:17
Memberimg3nius6-Nov-16 20:17 
QuestionConnection to ui timed out Pin
Member 1255508630-May-16 5:29
MemberMember 1255508630-May-16 5:29 
AnswerRe: Connection to ui timed out Pin
Pavel Durov30-May-16 7:32
professionalPavel Durov30-May-16 7:32 
GeneralRe: Connection to ui timed out Pin
Member 1255508630-May-16 10:20
MemberMember 1255508630-May-16 10:20 
QuestionI love you Pin
Member 1252850117-May-16 1:11
MemberMember 1252850117-May-16 1:11 
QuestionAndroid Device Settings Pin
dchin14-May-16 18:14
Memberdchin14-May-16 18:14 
AnswerRe: Android Device Settings Pin
Pavel Durov16-May-16 0:50
professionalPavel Durov16-May-16 0:50 
QuestionThis could expose users' private data Pin
Richard MacCutchan10-Jul-15 23:30
mveRichard MacCutchan10-Jul-15 23:30 
AnswerRe: This could expose users' private data Pin
Pavel Durov11-Jul-15 3:12
professionalPavel Durov11-Jul-15 3:12 
QuestionUnable to change the permission Pin
sanara de silva23-Feb-15 4:12
Membersanara de silva23-Feb-15 4:12 
AnswerRe: Unable to change the permission Pin
Pavel Durov24-Feb-15 19:49
professionalPavel Durov24-Feb-15 19:49 
GeneralRe: Unable to change the permission Pin
Member 1251907212-May-16 0:40
MemberMember 1251907212-May-16 0:40 
QuestionUnable to change the permission using the command Pin
Bharath Varma10-Dec-14 23:44
MemberBharath Varma10-Dec-14 23:44 
AnswerRe: Unable to change the permission using the command Pin
Pavel Durov11-Dec-14 23:59
professionalPavel Durov11-Dec-14 23:59 
GeneralRe: Unable to change the permission using the command Pin
Bharath Varma14-Dec-14 23:25
MemberBharath Varma14-Dec-14 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 4 Oct 2014

Stats

72.2K views
17 bookmarked