last day (14 days later) » 

5:26 PM
-1
A: Android running su within app

user1506104There is an android manifest permission you can use to gain root access <uses-permission android:name="android.permission.FACTORY_TEST" /> Your app will run as a manufacturer test application, running as the root user. Thus making the 'su' command accessible to your app. However, I doubt that...

 
Added that permission to the manifest but still no joy. Still runs as the user I mentioned in the question. I'll have to try figure out how to re-root the device and see if I can get it to work that way.
 
what is the output after you run exec("su")? can you show the content of variable 'output'?
 
Nothing. After running exec("su") there is no returned value at all.
 
No SecurityException or IOException either? I believe you put your code in a try-catch block.
 
No errors at all. Was just catching Exception but after your comment tried to catch SecurityException and IOException, but nothing. No error.
 
5:26 PM
in your command prompt, what do you see when you execute this command: adb shell su
 
Goes straight to root@BH84:/ # So the root command prompt
 
try to replace exec("su") with exec("su;id")
maybe the Runtime.getRuntime() creates a new session on each call. that is why your "su" is not carried over to your exec("id")
 
5:43 PM
I think you are right - get the following error now - IOException java.io.IOException: Error running exec(). Command: [su;id] Working Directory: null Environment: null
Actually - I'm not sure why I get that error now.
 
by the way, since your are using FACTORY_TEST, your are already in root. so no need to exec("su"). just do exec("id")
 
Seems if I just run exec("id") it spits out what I had in the original question : uid=10079(u0_a79) gid=10079(u0_a79) groups=50079(all_a79) context=u:r:untrusted_app:s0n
 
i see so you still need the su command
 
But su;id threw an error - no working directory - I'll google that and see if it helps.
Just an aside. The main reason I'm needing root access is to run a command to turn Airplane mode off. Root is now required for that command.
 
i think su;id is not the correct way
you should put su and id in a string array
then call exec(stringArray)
instead of exec(string)
 
5:56 PM
Seems I get no output when passing in the string array
 
sorry. try with someone else. :)
 
Thanks very much for the help. Much appreciated.
 

last day (14 days later) »