tags:

views:

29

answers:

2

Hey everyone, i'm planing an app where i need to edit a system file. I can only edit that file with root rights. I have a rooted dev phone with Superuser.apk installed. Other apps that require root do request root access on first start. i want to do the same but i can't find any hints on how to request superuser rights for my app :( I found something about an intent android.intent.action.superuser but when i try to launch an activity for that intent action i get an ActivityNotFoundException.

Any ideas?

Greets, Goddchen

A: 

Maybe because you should choose "android.intent.action.superuser" instead? I assume this could be the problem. Found the source of this on: http://forum.xda-developers.com/showpost.php?p=2954887&postcount=7

mreichelt
sorry for the typo, of course i meant android.intent.action.superuser. and thats exactly the example i'm referencing to.
Goddchen
I guess you have to install a different Superuser app then - maybe the one that is explained at the start of the thread: http://forum.xda-developers.com/showthread.php?p=2954887
mreichelt
i just found out that Runtime.getRuntime().exec("su"); calls up the superuser right dialog. but how can i read and write a file this way?
Goddchen
+1  A: 

The intent does not actually get you superuser rights, it just interacts with the superuser app's permission granting mechanism.

The real key is to understand that android's underlying linux does not support escalation of a user's privileges. Instead, it supports (/has been modified to support) a mechanism for a user to request to run _some_other_process_ as the superuser.

What this means is that the actual root-rights task will have to be done by a different executable, probably a native 'command line' one which you will launch under delegation by the su command or whatever your particular modified android build supports. It will be easiest if you can figure out how to do the task using one of the built-in toolbox command line programs - for example, write the file somewhere else and then mv (and maybe chown) it to where you want. Also bear in mind that /system is typically mounted read-only, and you would have to remount it rw before you can write there.

Put a lot of thought into anything you try to do as the superuser... it's easy to make a mess or leave problems behind. If you are deploying the app to others, also think about security holes you will be creating.

Chris Stratton
thanks for the hint. i'm currently trying to read a file with that "cat" command. "su -c 'cat <myfile>'" works fine from within adb shell. unfortunately the same command doesnt return anything when run from within my app (Runtime.getRuntime().exec("su -c 'cat <myfile>'");).
Goddchen
You need to think a bit about what you should expect it to do - it's not going to 'return anything' useful. If you hook the stdout of however you launch it you might get something (see source of terminal app). Test an unprivileged case without the su for simplicity, or use something that is file-to-file instead of depending on stdout or stdin.
Chris Stratton
it is now working: i had to exec("su sh") to open a shell. then create a dataoutputstream and write commands to that shell.
Goddchen