0

EDIT: Assume a rooted phone for this post.

I deleted a previous question I posted on this topic because none of the answers even came close to answering the question. Long story short, I need to open a database and modify an existing record. I do not want to use a "helper class" because I actually want to see and understand what is going on in a few lines of code rather than an unnecessary (for my purposes) class that contains 100 lines of code. So please don't tell me to "use the notepad tutorial." I have, and it doesn't explain what I need.

To simplify, here is what I am doing:

SQLiteDatabase myDB = this.openOrCreateDatabase("/data/data/MY_APP/databases/settings.db", MODE_PRIVATE, null);
myDB.execSQL("INSERT INTO my_table (SOME_FIELD) VALUES ('SOME_VALUE');");

This works very nicely. However it fails if I try to open/edit a database in a different path. For example I might want to edit a database that another app uses. How can I do this? Is it a simple matter of permissions? Should it work if my app requests and gets root access?

EDIT: There are tons of apps I can install on my phone that are capable of editing every single database on the system so obviously this CAN be done.

Jimmy D
  • 5,282
  • 16
  • 54
  • 70
  • 1
    "editing every single database on the system" - what are these magical apps you speak of? – Moog Oct 05 '11 at 17:23
  • @Merlin Have you really never seen a DB editor app? "SQLite Editor" is in the market. It lets you open, view, edit, ANY database on your phone. I doubt it's magic though. – Jimmy D Oct 05 '11 at 17:31
  • 1
    Unless it's rooted you can't see anything in `/data/data/some_other_app` – Moog Oct 05 '11 at 17:32
  • OK so assume it's rooted... Now what? I still can't make it work with the code I posted. – Jimmy D Oct 05 '11 at 17:34
  • The error is simply "cannot open database file." I might be requesting SU incorrectly. I will report back when I test this... – Jimmy D Oct 05 '11 at 17:47
  • Assuming its a rooted phone, does your app run with superuser access? – Pedantic Jan 17 '12 at 19:33
  • @Chris: That's my main problem, and the topic of a separate question. I can't make SU work, even after following advice from several people. – Jimmy D Jan 17 '12 at 19:38

2 Answers2

0

I don't know if you are still looking for this answer. I was looking to do the same but couldn't really find anything. I knew I needed to use root for the process, but again, couldn't find anything. I started messing around and just trying a lot of random things, and finally found a way to do it.

The short version that worked for me is you need to, as root, change the permissions of the database, access it directly (not through an sqlite helper), do whatever you wish, and then put the permissions back. I detail all of this on my blog:

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

user1883083
  • 841
  • 1
  • 8
  • 10
0

Regarding Android security, you cannot access others' app DB directly. If other applications create ContentProvider then you can access theirs DBs (if exist) through its Providers. Otherwise, there's no way out AFAIK.

Pete Houston
  • 14,931
  • 6
  • 47
  • 60
  • 1
    This is obviously not accurate otherwise apps like "SQLite Editor" wouldn't exist in the market. Clearly it's possible. – Jimmy D Oct 05 '11 at 17:33
  • xjaphx .this thing you are talking about internal DB but if the DB is in SDcard then i think i can access in other app. – Monty Jan 30 '13 at 05:53