0

My app needs to request SU access (on rooted devices) and the only examples out there say to do this:

Process p = null; 
p = Runtime.getRuntime().exec("su"); 

That's fine, but how do I associate that p process with what I want to do next? For example how do I use that process to open a database so that the attempt to open the database happens with root permissions?

Jimmy D
  • 5,282
  • 16
  • 54
  • 70

1 Answers1

0

Please see this discussion: Run secure API calls as root, android

Basically, you'd have to specify the stuff you want to execute in your call to the exec() method. Since that's hard to do, using the system app is really the best way to do things.

For the actual call, do this in your code:

Process p = null; 
p = Runtime.getRuntime().exec("su sqlite3 your_query");
Community
  • 1
  • 1
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
  • If you look here: `http://www.stealthcopter.com/blog/2010/01/android-requesting-root-access-in-your-app/` you'll see that after "p" is created you can do things like: `DataOutputStream os = new DataOutputStream(p.getOutputStream());` So how can I do the same thing with database access for example? – Jimmy D Oct 05 '11 at 19:32
  • So yes, the one thing you can do is give input and get output from the process. So if you want to get do some sort of database query, you could do something like: DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes("sqlite3 some_sql_query"); – Kurtis Nusbaum Oct 05 '11 at 19:37
  • Actually, just do this: Process p = null; p = Runtime.getRuntime().exec("su sqlite3 your_query"); and then read the output stream from that. – Kurtis Nusbaum Oct 05 '11 at 19:41