I read lots of websites about how to root an android device and give the app root privileges.
Now I have installed superuser app. When I enter su in a console to the device then superuser comes to ask for rights. This looks fine.
But when I do Runtime.getRuntime().exec("su"); in my app nothing happens.
Error code is 1, message is permission denied. No superuser message appears. This looks like my app can't call su. Funny: when I let my app call Runtime.getRuntime().exec("su -v"); I get a result! (namely the su version).
Call to su only fails.
What am I missing?
Btw. I added permission android.permission.ACCESS_SUPERUSER to the manifest as stated somewhere.
There are so many threads about root privileges, but none of them explains what can go wrong.
Is this CyanogenMod? Look in the settings: you can choose whether to allow apps to request root, and whether to allow adb to do so. You might have got it set to "ADB only". If so, change it to "ADB and apps".
Your su -V tells you that you're successfully executing an external program; but su itself is refusing to let you become root.
Related
I have an application where I create a process and call the dumpsys telephony.registry command to get information about the mobile network status.
String[] cmds={"dumpsys telephony.registry"};
Process p = Runtime.getRuntime().exec(cmds [0]+"\n");
and then after that I parse the result of the command. For "ls" or other commands it works fine. For dupmsys I get Permission Denial: can't dump telephony.registry from pid-953, uid=10090. I get the same error results for dumpsys power or other dumpsys commands.
I have set DUMP permissions android.permission.DUMP in the android Manifest like suggested here
I think that I am doing this right since Android offers this feature here
I have also done the step described here to force eclipse to allow me to give my application DUMP permission in the manifest.
When I execute the dumpsys command I always get the same result
Permission Denial: can't dump telephony.registry from pid-953, uid=10090
Am I doing something wrong? Why does android OS still deny me access to the dump service ?
PS I have set min API 8 and I am testing the application on device running (ICS)
API 15
Why does android OS still deny me access to the dump service ?
Because that permission is flagged as android:protectionLevel="signature|system|development" (or signatureOrSystem using the old syntax) on Android 2.3+, and therefore cannot be held by ordinary Android SDK applications.
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line:
adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB.
Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost:<portnum> and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
NOTE: You don't need the DUMP permission for that to work.
The android dev team decided to stop granting these permissions to third-party apps. Only system apps can now get them.
more details:https://code.google.com/p/acra/issues/detail?id=100
It reports private values of core Android services that you would never be able to typically obtain. Official document says "Not for use by third-party applications".
Add permission on your manifest "android.permission.DUMP". I have not tried it yet but it shows on adb shell that it is missing that permission
I want to execute the "su" comand from an app..I have rooted the emulator and installed Superuser.apk(superuser 2.3.6.1)
Process pr= Runtime.getRuntime().exec("su");
process.waitFor();
Log.d("Ex.Value",Integer.toString(process.exitValue()));
But I'm getting 255 as the exit value which seems to be some error in executing "su".
I have included RootTools library (http://code.google.com/p/roottools/). When checked with the methods RootTools.isRootAvailable(), RootTools.isAccessGiven()...Its found that the emulator has SU, but my application is not granted Root permissions. Will it be the real issue?? ..If so Can you plz tell how to grant my app the Root permission?
When you execute 'su', you should have root access within that process. The app should then automatically ask for root permission to the user via a dialog box. This dialog box is provided by android but is only present in devices that have been rooted.
This blog post has an example that might help you:
http://www.stealthcopter.com/blog/2010/01/android-requesting-root-access-in-your-app/
The comments at the end are very informative as well.
I recently upgraded on a Stock Android 4.1 on my transformer tf101. In my app, i need root access my USB camera plugged in to the device. Till now, i have done this by the following code:
Runtime.getRuntime().exec("su");
DataOutputStream oOutSream = new DataOutputStream( process.getOutputStream());
oOutSream.writeBytes( "chmod -R 777 /dev/bus/usb/* \n" );
oOutSream.flush();
oOutSream.writeBytes("exit\n");
oOutSream.flush();
I know, chmod 777 is NOT a good idea, but i haven't found any other solution so far. Well, after upgrading to 4.1 this is NOT working anymore. SuperSU prompts a Messagebox informing me that the app has requested root access, but it wont work. the strange thing is.. when i open up the adb shell from the pc, and enter those commands, it works flawlessly.
If i granted su access by the pc, my app works correctly, although random toasts show up informing me "root acces granted" or "root acces denied". Could it be a bug in SuperSU?
Thanks for the help!
A better idea is to look at what permissions the usb devices have you want access.
For example using ls on your phone:
$ ls -l /dev/bus/usb/001/
crw-rw---- system usb 189, 1 2012-09-15 19:18 002
crw-rw---- system usb 189, 0 2012-09-15 19:18 001
I might be wrong here but I think in every android version the usb group has rw permissions for all usb devices. What you want to do is, launching your application with usb as group id.
You could do this, for example, by using su to elevate your process to root and then setting your group id using setgid. After that you can write to your usb devices without that chmod fiddeling which is really really not good.
Edit: Also, don't forget to drop the root permissions using setuid(whateverAppUID) after you're done setting the group id!
I have a rooted tablet that gives adb root as soon as it connects.
When I type adb shell
I get
root#android:/#
I can do su
and it's not showing me any permissions errors
But when I try to execute a file on an sdcard that has already been given all permissions.
I get Permission Denied
Why is this happening?
The sdcard is mounted with a noexec flag, which means you cannot execute things stored there.
This is doubly important when running as root or even the semi privileged shell, since the lack of file permissions or ownership there means any userid with the write external storage permission could trojanize the program you might want to run.
As an aside the default shell has a limited vocabulary of errors and in many versions will also say permission denied as a substitute for command not found. Your current working directory is not in the search path, so if you want to run something from there, you typically need to do:
./filename
I'm using a dev phone (Nexus One). I connected to it through "adb shell" but I couldn't get the root permission. When I run "su" in the shell, I got
$ su
su: permission denied
Actually I cannot access "/sbin" at all.
When I used the "root" option in "adb", I got errors too:
./adb root -s xxx shell
adbd cannot run as root in production builds
I got this error no matter I used a downloaded SDK or I compiled an SDK from the source. I'm not sure about what "production builds" actually means. Does it mean that I need to compile Android and put it on the phone? I thought a dev phone already has the root permission unlocked.
Thanks for your help.
You should unlock your phone - root it. Nexus One comes with this option, but you have to enable it. You can read this article or google for more.