3

I am working on a rooted device. I have connected with the adb shell from my pc and I can verify that the other database exists and I can query its tables.

However in the my java code when I try to open the database I get error

android.database.sqlite.SQLiteException: unable to open database file

I am trying to open the database like this:

SQLiteDatabase.openDatabase(PATH, null, SQLiteDatabase.OPEN_READONLY); 

The path is something like /data/data/com.xxx.xxx/databases/xx.db

Am I supposed to read the databases of other applications like this or there is another way?

UPDATE: I also tried making the system app as adviced in this thread Push my apk to /system/app

I think it works because the app cannot be uninstalled after that from the applications manager like the ordinary apps so I think it is a system app. But still I cannot access the database though I am sure the paths and permissions are ok.

2
  • Can you give more details about your environment, e.g. OS, etc. The languages you are using and the type of Database you are looking to access? Commented Jun 28, 2012 at 12:06
  • @Deepend this is obviously Android and Java. Check the tags. Commented Jun 28, 2012 at 12:08

3 Answers 3

9

Android OS by default does not allow applications to access each others private folders. To be able to read files that are in another applications folder either:

1) you need to have both applications installed using same user id. Add this to both manifests:

android:sharedUserId="com.xx.xx" 

2) If other app is a 3rd party app then your only choice is to install your app as system application. To do that you need a rooted phone and you need to mount the system folder. And then you need to put your application into /system/app/ folder and reboot the phone. It should be installed automatically during the boot.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the response @Caner what I did was to download an app from the store named Root Browser and copied the .apk to the /system/app then I rebooted, the app was installed indeed but the result is the same. I double checked to see if the db path is the same. I am using a rooted HTC Desire HD with Cyanogenmod. Also through the Root Browser app I gave all permissions to the apk in the /system/app folder.
open the shell and do su and then try chown root.root /system/app/your.apk
unfortunately this didn't help either, the Root Browser app shows correctly that the owner of the apk is root but this doesn't change anything. Interesting thing is that once I copy the .apk to the /system/app folder the app automatically is installed without restart needed(though I tried restarting the device too). Here are the few lines of the stacktrace which are interesting: sqlite returned: error code = 14, msg = cannot open file at line 27205 of [42537b6056] sqlite3_open_v2("/data/data/com.facebook.katana/databases/fb.db", &handle, 1, NULL) failed
i dont know then :( maybe this could help: stackoverflow.com/questions/8021578/… you can try to copy the database to some folder you can access
finally this is what I ended doing and it works String[] hin = { "su", "-c","cp /data/data/com.xxx.xxx/databases/xx.db /sdcard/xx.db" }; Runtime.getRuntime().exec(hin); From there I could access the .db. Now I have another question but I will create a new thread for it. Thanks!
1

I would assume that the permissions on the database files are set such that your application has no acess. Even if your device is rooted it doesn't mean that your application is running as root.

2 Comments

Thanks @David Wasser but if I use chown on the .apk doesn't this make the app run as root? If it is running as root is it still possible that I have no access to the database?
Good question. I don't play much with rooted phones so I guess I can't help you here. Sorry. You should be able to see if your app is running as root by using adb shell and a ps command which should show you the userid that each process runs as.
1

This is because the app needs root, and needs to change the permissions of the database you are trying to access so that you can actually access it. What you will need to do is, as root, change the permissions of the database so that everyone can access it, do what you would like on the database, close the database and change the permissions back.

This does circumvent security of android, so proceed at your own risk. You can find a code sample at:

http://rratmansky.wordpress.com/?p=259&preview=true

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.