I want to use shell command for my app as root permission. I put in my manifest:
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
I want to know if there is a way to allow Super User permission programmatically without using any input device. As you know a window like this is appearing :
I want to avoid that step and programmatically select Remember choice forever.
Short answer! You can not do programatically !
Just exec the command su and within that Process you have root priviliges:
Process p = Runtime.getRuntime().exec("su");
See this blog post for full example.
Source
Related
I know from https://developer.android.com/guide/topics/connectivity/telecom/selfManaged, that you can set the default dialer by having the necessary items in your manifest and permissions listed. One of those being the Dial intent.
What i'm trying to do is build a library that does all of these content provider calls and provide a nice reactive way of doing things to my application. While building the library I would like to add some integration tests around these device calls.
There's the GrantPermissionsRule that helps with setting permissions already defined in your manifest but how does one deal with becoming the default dialer or SMS application? I'd accept even an adb command that you could run using a Runtime execute command.
I also tried testing on an emulator and I noticed that you can give your app WRITE_SECURE_SETTINGS but not MANAGE_USERS which is the other necessary permission you need if you were to use reflection to access the https://android.googlesource.com/platform/frameworks/base/+/master/telecomm/java/android/telecom/DefaultDialerManager.java
Any help is much appreciated!
you can try adb command:
adb shell settings put secure dialer_default_application com.google.android.dialer
replacing com.google.android.dialer with your package.
I have an app that requires root access. I'm using the following code to request the permission:
Process p = Runtime.getRuntime().exec("su");
What this does is: when the user has granted the root access to the app, it displays the root sign (#) in the statusbar ( which is normal ). The symbol remains in the statusbar even after the app goes to the background or even after that activity is finished. I want the symbol to appear when the permission is granted, and releasing the granted root access after performing the operation, so it removes the symbol from the statusbar.
HideItPro does it so I know it's possible, but I couldn't find a way pf doing it. Can anyone help me how to do this ?
PS: I'm using RootTools sdk for root operations.
Android's permission system is different than traditional Linux. On normal, commercial devices there is no access to "root" and there is no su command. You have to have a rooted ROM for that functionality.
Is there any way in Android M/N to hide the permission popup .
I completely understands that Android M onwards it has a new security modal and it mandates run time permissions check for dangerous permissions. But I did not find anything related to hide/suppress the popup.
After reading the material on developer documentation(link below) I found that only normal permission can be pre granted by System without asking from user. But for others e.g. Camera, Network, Media files etc. we MUST get permission from user which I'm trying to avoid for better user experience.
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
All I'm trying to understand that is there any way to create an app with higher privilege or make modification in AOSP or anything we can do to suppress the permission popup in Android M or N?
Any help would be appreciated. Thanks!
Only with root permissions.
Runtime.getRuntime().exec("su -c \"pm grant com.example.app android.permission.ACCESS_FINE_LOCATION\"");
in a monkeyrunner script while launching an activity, is there a way to mimic yourself having a certain permission that the starting activity requires?
I am using "device.startActivity(component='com.package/.MyActivity)" but the activity MyActivity requires a permission, and hence device.startActivity fails. Is there a way to give this permission to the script?
When I had this problem, I solved it by creating a very small application(with the correct permissions in the manifest) that I pushed to the phone. All the application did was re-send intents sent to it, but to a different destination. My application also had a gui for triggering events manually, but that's optional.
You can add permissions in AndroidManifest.xml file.
I don't know what monkeyRunner script is, and do we talk about the same permissions here, but in Android, all permissions you want to give to the app, you go to Manifest file.
Running an activity through monkeyrunner is not exactly different than running it manually. So, when it asks for permission, you can verify it right after installation by sending an extra command like:
device.press('KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP)
or
device.press('KEYCODE_BUTTON_SELECT', MonkeyDevice.DOWN_AND_UP)
You can also get your application have system privilages by pushing it into a special folder with these commands:
>adb remount
>adb push your\local\apk\path.apk system/priv-app
>adb shell stop
>adb shell start
Hope it works for you...
I'm learning Android programming, and I want to make an application which has to run as root. The logical thing would be to add a root permission in the Android Manifest.
I saw this link in the documentation, and especially noted the FACTORY_TEST permission:
public static final String FACTORY_TEST
Since: API Level 1
Run as a manufacturer test
application, running as the root user.
Only available when the device is
running in manufacturer test mode.
Constant Value:
"android.permission.FACTORY_TEST"
Is that the best way?
If it's not possible using the SDK, how can I make a "root" application work?
What you need to do is something like:
Process root = Runtime.getRuntime().exec("su");
That causes SuperUser to show, which lets you either Allow or Block it from root access. This approach might not work if the user is not rooted. Here is a way you can test it.
First lets us get the basics right. Android run Linux kernel underneath. Now if you have to run your process on it with super user privileges(run it as root) the only way is to execute your process is via command line because it is the only way you can directly interact with the kernel. Also you need to use su before running any command. Also as Chris has mentioned in his comment on the 1st answer
Process process = Runtime.getRuntime().exec("su");
will accomplish nearly nothing. It will just ask for super use privilege using dialog. What you can do is instead of just executing su you can execute your process with su as following
Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", yourCommand});
The -c Option
Among the most commonly used of su's few options is -c, which tells su to execute the command that directly follows it on the same line. Such command is executed as the new user, and then the terminal window or console from which su was run immediately returns to the account of the former user after the command has completed execution or after any program that it has launched has been closed.(More details)
Alternate Option
Alternative to above method one another way that might work is to use command line to copy you app to /system/app/ directory. Then your application will run automatically with root privileges(same as System apps)
The SDK does not offer a way to run an app as root.