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.
Related
Currently I'am working on an aplication via Android Studio, that executes commands using the next sintaxis:
Process p = Runtime.getRuntime().exec(new String[] { "su", "-c", "ip link show"});
I'am working with the device IMX7D_PICO (it uses Android Things as SO). It is rooted, as is shown in the following pic:
But, when I run a command as root on Android Studio, I get the next error:
W/System.err: java.io.IOException: Cannot run program "su": error=13, Permission denied
W/System.err: at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:692)
at java.lang.Runtime.exec(Runtime.java:560)
I don't know why su works only on adb. In other hand, I know that there are others ways to obtain the data of ip link show, but the next step, it's open a socket RAW with the command that I said. So, I need to run process as su via Android Studio.
An app's process has less privileges compared to those of the shell's, resulting in
java.io.IOException: Cannot run program "su": error=13, Permission denied
For the permission to be granted you should install SuperSU app or alike and follow the app's prompts while your app is trying to su with Runtime.getRuntime().exec("su").
Once the process has gotten root you can grab the standard input of the root process and write the command(s) to it, reading its standard output. For more details see: execute shell command from android.
I don't know why su doesn't work. I 'suspect' that Android Things is using a single user that is root already, so maybe executing the command without using su would work.
On the other part of your question. Parsing the output of system commands is not the best way of getting info, in this case, you can probably get what you want using the Android class NetworkInterface https://developer.android.com/reference/java/net/NetworkInterface#getNetworkInterfaces().
You can manage raw sockets using the Android framework classes too.
Using the termux (https://termux.com) terminal-emulation program, I type the following command:
ls /sdcard
I get the following error:
ls: can't open '/sdcard': Permission denied
No, my device is not rooted, nor do I plan to root it - so I can not give any information that I'd have to root the device to obtain. However, not being rooted never in the past prevented me from having read access to the /sdcard directory - so this is new (and disturbing).
Granted - it's been a few months since previously I tried to do this - but this new limitation from Android seriously hampers the usability of termux and who-knows-what-else -- as I need to be able to have access to files that are on my SD Card. (I can still do a lot, even if not everything, even without write permissions -- but am pretty much stuck in the water if I can't get read permissions, as is presently the case.)
I've had the same issue, easly solved by typing termux-setup-storage. This will open the window to obtain storage r/w permissions and the job is done.
Be sure to run previously apt update and apt upgrade to have it available.
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.
When launching an app using adb command "am start intent.... ", I got an security exception stating that "java.lang.SecurityException: Permission Denial:", and the app doesn't get launched.
When I checked StackOverflow for solutions, I found solutions which are based on editing the manifest.xml file. I dont have any permissions to edit the file. Since am a user of that app and not a developer.
My questions are
1. Is there any way to escape this exception via adb commands. I need to escape this through commands, because its a third party app also I don't have access to manifest.xml file.
Else is there any other way to launch the app through adb command??
If you root your device you can gain root access/permissions by using su before your commands. This should prevent you from being denied due to permissions.
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