Background
I'm trying to create an app that can grant and revoke permissions of other apps.
To do this I'm using adb commands:
pm grant packageName permissionName
This works great if I call it through a shell with root permissions.
Problem
The problem is that when I call this command without root permissions, I receive
Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS
This is to be expected (it would be a big problem otherwise).
Question
Is it possible to allow my app to manage other apps permissions through Android settings?
I'm looking for something like granting USAGE_STATS permission to an app going to Settings -> Security -> "App with usage access", but for GRANT_RUNTIME_PERMISSIONS (and REVOKE_RUNTIME_PERMISSIONS).
Sure. You can set up and utilize an ADB shell without your Android based device being rooted. You are simply restricted from running ADB as root and making system-level changes. You can push files to your device, pull files from your device, sideload app packages and updates, etc., and many more non-root functions.
The general steps to enable it is Settings>About Phone and tab the Build Number seven times to unlock Developer Options. Now go to Developer Options in System Settings and activate the root option (ADB only or Apps and ADB). After this, adb will restart and you will be able to use root from the cmd line.
I was trying to install BBS to my Redmi Note 4, MIUI 10.1 (not sure if details are relevant). Got same error. Then I found a menu item three rows below main 'USB debugging' menu in developer options. It was called
USB debugging (Security settings)
Allow granting permissions and simulating input via USB debugging
Attempt to enable this option prompted three warning windows with information about terrible things that can happen if you proceed. After last confirmation (not sure if the phone was connected or I connected it after) I ran
adb -d shell pm grant packageName android.permission.BATTERY_STATS
but now it succeeded.
In Developer Options
, scroll (all the way) down until u find Disable Permission Monitoring
and turn it on.
Now the pm
command should work
I noticed that they change it to: USB debugging (Security setting'
and location moved up
and it require a sim
For those who are using MIUI:
I'm using MIUI 12.0.5 Stable. And in this version - to run any granting permission commands, we must first enable "USB Debugging" and "USB Debugging (Security settings)" from the developer options, and only after then we will be able to execute permission commands via adb like this one:
adb shell pm grant com.ivianuu.immersivemodemanager android.permission.WRITE_SECURE_SETTINGS
Xiaomi users may need to enable an setting in the Developer Options. It's called "USB debugging (Security settings)" with the subheading "Allow granting permissions and simulating input via USB debugging"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With