How to request root permission for a particular operation android - android

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.

Related

Espresso UI Test take screenshot - app without write external storage permission

I am writting an UI test in Espresso for an Android app. I need to take an screenshot of the screen to verify the UI, I do it through the UiDevice.takeScreenshot() method.
This method is throwing an Exception because the app has no write permissions, in order to run this UI tests, I need to specifically add the android permission in the AndroidManifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Then execute the app, go to Android settings, enable this permission; and then I can run the UI test. After that I need to go back to AndroidManifest, remove this permission (because I only need it for the UI tests).
Is there any cleaner way to achieve this without having to touch AndroidManifest and automatically grant write external storage permission for the UI tests only?
You can put the <uses-permission> element in an AndroidManifest.xml file in your androidTest/ source set, so it does not affect your production code.
To automatically grant the runtime permission during tests, you can try the new GrantPermissionRule. Or, use other techniques to grant the permission as part of your test suite. In the end, they all use:
adb shell pm grant com.package.myapp android.permission.<PERMISSION>
adb shell pm revoke com.package.myapp android.permission.<PERMISSION>
...either from Gradle or from your test code.

I am making a application which will help user to record its screen

I know this is possible in android API version 21, but I want to do it in the API version 19 or earlier. To achieve this task, I have to get root permissions. I don't know how to get root permission. How can this be achieved?
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.
Courtesy

Hide permission popup in android M/N

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\"");

Running a command as a shell user from an Android app

I am trying to execute an fopen() function on a file that is given permissions only to "shell" from a native (C++) application that is triggered from a service on my Android application. When I run the native code as a PIE from the shell, I am able to open the file for reading, but if I try from the Android application, it fails to open the file as the Android application is run in a different user space and so I am not able to open the file. My question is, is it possible to run the command as a "shell" user or a child of "shell" from the Android application. I want to be able to do this without rooting the device so su is out of question.
You can't change the user ID of your app without a rooted device. If you could, the security model wouldn't be very useful. If your app needs access to the file, you will need to grant appropriate permissions.
The other common workaround is to have a service, running as the "shell" user, whose job is to open the file and hand back a file descriptor. The tricky part is that you need a way to launch that service as the "shell" user, which brings us back to needing "su".
FWIW, the situation is the same whether you're coding in Java or C++.

Security Exception: Permission denial for DEVICE_POWER

I am trying to write a simple android app that switches off my phone screen. When I am runnning this app I get Security Exception: Permission denial app requires android.permission.DEVICE_POWER. I know that this is a protected permission but my phone is rooted. What do I specify that I can use this permission? I have already tried declaring DEVICE_ADMIN permssion along with the DEVICE_POWER permission but it still doesn't work.
Rooting potentially lets you circumvent or modify the android security model, but it doesn't necessarily mean you get special privileges for an android API which enforces it. You cannot ordinarily run an application itself as root, while code in a helper executable which you could start as root will have substantial difficulty interacting with the Android APIs.
What you are trying to do may really not be a very good idea. But if you really want to do it, you would need to either install your own build of Android so that you have a (self generated) key matching that which you used to sign the platform, which you can then use to sign your application, or else try to install your application on the system partition.
If all you want to do is turn the screen off, then why don't you use the PowerManager? According to the documentation, the goToSleep() function will force the device to go to sleep.

Categories

Resources