Ok, i know there is plenty of info about rooting various devices out there, however there i seem to locate anywhere that has an guide to actually rooting an Android system.
I understand to gain root access you must have a version of su that is compatible with your Kenel. I build an -eng build of AOSP and this includes a version of su into the system ( /system/xbin/su) with the following permissions.
Code:
-rwsr-sr-x root root 60112 2011-12-06 11:56 su
Its my understanding that each app in the Android system is essentially a individual user of the Linux system so i thought that all i would have to is grant the correct permissions for su so that any user can execute it.
Code:
chmod 755 su
-rwxr-xr-x root root 60112 2011-12-06 11:56 su
This does not seem to be the case, i have done this though when i try to su (from Terminal Emulator) i get this
Code:
$su
su: UID 10027 not allowed to su
$
Can anyone let me know what i am missing to allow root access for my applications?
Ok, so it is the version of su that is bad.
If you want to root any device get the correct version of su from here and include into your builds.
I am currently trying to write a root app.
I know that I can execute shell commands in a root shell like this.
However, I also want to execute some commands that way:
Code:
su -c[command]
But I can't get it to work if I use commands with parameters like ls -l or mkdir <path>. Executing something like su -c reboot works fine.
According to this it should work.
If I execute these commands using an adb shell or the Terminal Emulator app, they work fine.
This is my code:
Code:
package de.nikwen.sutest;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su");
runtime.exec("su -c 'mkdir /data/data/abcdef'");
runtime.exec("su -c \"print asdf\"");
//However, this works:
// runtime.exec("su -c 'reboot'");
} catch (IOException e) {
e.printStackTrace();
}
}
}
I get this logcat:
Code:
04-02 21:03:14.509: D/su(3620): su invoked.
04-02 21:03:14.519: E/su(3624): Unknown id: /data/data/abcdef'
04-02 21:03:14.519: E/su(3624):
04-02 21:03:14.529: D/su(3623): su invoked.
04-02 21:03:14.539: D/su(3625): su invoked.
04-02 21:03:14.559: E/su(3626): Unknown id: asdf"
04-02 21:03:14.559: E/su(3626):
04-02 21:03:14.639: D/su(3629): 10079 de.nikwen.sutest executing 0 /system/bin/sh using shell /system/bin/sh : sh
Does anybody have an idea to solve my problems?
Could anybody please test this code on his device? I would really appreciate this as it could be ROM related. (http://forum.xda-developers.com/showthread.php?t=2180669)
Well, as far I know if you already used su you don't need to use it in the other commands, like this:
Code:
runtime.exec("su");
runtime.exec("mkdir /data/data/abcdef");
Anyway, to run commands as root easily, I recommend you RootTools
RoberGalarga said:
Well, as far I know if you already used su you don't need to use it in the other commands, like this:
Code:
runtime.exec("su");
runtime.exec("mkdir /data/data/abcdef");
Anyway, to run commands as root easily, I recommend you RootTools
Click to expand...
Click to collapse
First of all: Big thanks for your answer. :good:
Well, it doesn't work if I do not use
Code:
runtime.exec("su");
And not using the su command again works, but only if you write the commands into the OutputStream of the process which is returned.
You have to call it at least once after installation to make the SU app ask the user for permission. Then the other lines should work on its own.
The advantage of using su -c [command] is that the user isn't shown all these annoying Toasts like "App x has been granted Su permissions", just the first time when it requests su rights after each launch of the app. My app has to call these functions very often and all these Toasts are VERY annoying. If you look at apps like file managers, there is also just one Toast at launch time and then they execute all commands without any Toast.
According to this you should execute everything like this:
Usage: su -c 'command'
su -c 'command1; command2; .... ; commandN'
Click to expand...
Click to collapse
My question is just if this works on other devices or ROMs. I will really appreciate if you try it.
And if it doesn't, then my question will be why it doesn't.
EDIT: And I don't want to use any libraries, even though it would be much easier.
The strange thing is that the last quotation mark is seen as a part of the argument.
EDIT: Inserting a space before the quotation mark doesn't work:
Code:
04-03 00:02:59.129: E/su(13793): Unknown id: /data/data/abcdef
04-03 00:02:59.129: E/su(13793):
04-03 00:02:59.139: D/su(13790): su invoked.
04-03 00:02:59.139: D/su(13792): su invoked.
04-03 00:02:59.159: D/su(13794): su invoked.
04-03 00:02:59.169: E/su(13795): Unknown id: asdf
04-03 00:02:59.169: E/su(13795):
04-03 00:02:59.189: D/su(13796): db allowed
04-03 00:02:59.219: D/su(13798): 10079 de.nikwen.sutest executing 0 /system/bin/sh using shell /system/bin/sh : sh
EDIT2: Deleting the last quotation mark also didn't help:
Code:
04-03 00:05:18.409: D/su(14117): su invoked.
04-03 00:05:18.439: D/su(14120): 10079 de.nikwen.sutest executing 0 /system/bin/sh using shell /system/bin/sh : sh
04-03 00:05:18.439: D/su(14118): db allowed
04-03 00:05:18.459: E/su(14123): Unknown id: /data/data/abcdef
04-03 00:05:18.459: E/su(14123):
04-03 00:05:18.469: D/su(14122): su invoked.
04-03 00:05:18.489: D/su(14124): su invoked.
04-03 00:05:18.489: E/su(14125): Unknown id: asdf
04-03 00:05:18.489: E/su(14125):
Ok, in Terminal Emulator this works fine (2.3.7, CM-bassed):
su -c "ls /sys"
So it's kinda weird =/
RoberGalarga said:
Ok, in Terminal Emulator this works fine (2.3.7, CM-bassed):
su -c "ls /sys"
So it's kinda weird =/
Click to expand...
Click to collapse
Yes, it is.
Did you try the source code?
If you want, I can compile it for you.
Flashed this and it doesn't work, too.
Here is the compiled apk.
Could somebody please test this?
Tested, don't seems to work (it should create the folder /data/data/abcdef right?)
RoberGalarga said:
Tested, don't seems to work (it should create the folder /data/data/abcdef right?)
Click to expand...
Click to collapse
Yes, it should.
Thank you very much for your answer as you have been the only one giving me answers. :good:
EDIT: The link in your signature is broken.
However, I don't understand why this works here:
Code:
Runtime.getRuntime().exec("/system/bin/su -c 'setprop ctl.stop zygote'");
Something else I found:
Usage:
su --> becomes root (starts /bin/sh as root)
su -c '' --> run a command or many commands separated by ; as root.
Click to expand...
Click to collapse
(http://de.appszoom.com/android_applications/tools/superuser-su_feoig.html)
I have solved the problem now:
Code:
package de.nikwen.sutest;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su");
runtime.exec(new String[] {"su", "-c", "mkdir /data/data/abcdef"});
runtime.exec(new String[] {"su", "-c", "print asdf"});
//do this to execute two ore more commands at once
runtime.exec(new String[] {"su", "-c", "mkdir /data/data/aaab; mkdir /data/data/aaac"});
} catch (IOException e) {
e.printStackTrace();
}
}
}
I know that I shouldn't run this on the main thread but in a service or at least in a different thread. This is for testing purposes only.
I missunderstood this blog entry.
But now everything works fine.
However, I still don't know why my first code example doesn't work. If anybody has an idea, please still answer my question as it hasn't been answered completely yet.
Again: Big thanks to RoberGalarga! :good:
The thing is that I'm fed up of some stock adware apps on my Micromax phone and want to disable them for good. So, as per this Android SE answer, I used adb shell to disable the app, but I'm getting the following error:
Code:
[email protected]:/ $ pm hide com.micromax.trendingapps
Error: java.lang.SecurityException: Neither user 2000 nor current process has android.permission.MANAGE_USERS.
1|[email protected]:/ $
The error message indicates that I need android.permission.MANAGE_USERS to achieve that. So I even tried granting that permission to the shell app, but no use!
Code:
[email protected]:/ $ pm grant com.android.shell android.permission.MANAGE_USERS
Operation not allowed: java.lang.SecurityException: Package com.android.shell has not requested permission android.permission.MANAGE_USERS
1|[email protected]:/ $
Is there any other way to get myself that permission?
Finally, the smart-phone is Micromax Q4260 running Marshmallow, if that matters. This could probably be solved by rooting, but I don't have any intention of doing it as it could be risky on this little known model.
I tried run ssserver on Nexus4 with Android 4.2.2 but can't. The result is "Permission denied". File permissions appear to be normal:
[email protected]:/data/local/tmp $ ls -al ssserver
-rwxrwxrwx shell shell 810284 2019-04-17 09:33 ssserver
I tried the following but it didn't work:
- reboot device
- disable selinux
= create test.sh in same directory and set execute permission run but get same prompt "Permission denied"
The problem seems to be only under Android 5.0 will happen. I tried create Android 4.2.2 emulator and execute ssserver it's ok!
Why can't I run ssserver on Android device?
I want to grant INJECT_EVENTS permission to a SSH app that I downloaded in order to emulate touch using SSH.
I plugged into my computer and typed the following, but got the error below
Code:
adb -d shell pm grant net.xnano.android.sshserver android.permission.INJECT_EVENTS
Security exception: Package net.xnano.android.sshserver has not requested permission android.permission.INJECT_EVENTS
Click to expand...
Click to collapse
My Pixel 3a(Android 10) does not have the setting to Disable permission monitoring, as other internet sources said to try.
Are there any other ways I could grant permissions to an app that I did not make without rooting?
@spencer_3
Only the permissions that are defined in the APK's manifest file can be granted/revoked .