Stefano Siano
Stefano Siano

Reputation: 749

How can I use adb to grant permission without root?

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).

Upvotes: 47

Views: 129033

Answers (11)

Parth Shitole
Parth Shitole

Reputation: 1

Those who are wondering why all these solutions are working for others and not for you.. let me tell you just turn on disable permission monitoring and restart your device. And as soon as your device restarts just run your permission grant command. This worked for me :-)

Upvotes: 0

Elia Weiss
Elia Weiss

Reputation: 10040

In Developer Options, scroll down until you find Disable Permission Monitoring (I noticed that they change it to USB debugging (Security setting) and it might require a sim) and turn it on.

Restart your device.

Now the pm command should work

Upvotes: 79

FireEmerald
FireEmerald

Reputation: 1390

To grant app permissions you need essentially:

  1. Enable Developer Options -> USB debugging
  2. Enable Developer Options -> Disable Permission Monitoring (this is NOT next to the first option, it's all the way down in the "APPS" area)
  3. Restart your device, unlock (pin code), connect it to a pc
  4. Select File Transfer mode
  5. Check that your device is recognized by adb:
PS C:\adb-tools> ./adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
93c53934        device
  1. Force stop app to grant permissions for and then grant permissions:
PS D:\adb-tools> ./adb shell
OnePlus8Pro:/ $ am force-stop com.conena.logcat.reader
OnePlus8Pro:/ $ pm grant com.conena.logcat.reader android.permission.READ_LOGS

Additional hints:

  • In german the (2) option is called "Erlaubnisüberwachung deaktivieren", area is "APPS" (see this Video)
  • The guide was tested on a OnePlus 8 Pro, Android 12

Upvotes: 9

Joaquin
Joaquin

Reputation: 1

Go to Developer Option then Disable "Verify apps over USB"

Upvotes: -1

Sjoerd Hemminga
Sjoerd Hemminga

Reputation: 176

The answer from @elia-weiss here almost worked for me. I also had to make sure the app I was granting to was stopped. I just used force stop in app info.

Upvotes: 11

sauvvvage
sauvvvage

Reputation: 1

I fixed this by changing the usb configuration to "MIDI" while aving all usb debuging options turned on.

Upvotes: -1

Arshit Vaghasiya
Arshit Vaghasiya

Reputation: 141

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

Upvotes: 14

jkk
jkk

Reputation: 181

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"

Upvotes: 18

Harald
Harald

Reputation: 81

It worked for me with the solution Elia Weiss provided. (unfortunately I haven't enough reputation to upvote and comment)

Switch on "Developer Options" / "Disable Permission Monitoring" (at the end of the section)

This is probably different depending on Android versions and or OS variants.

In my case it's ColorOS 6.1 / Android 9 on a realme X2 global variant. (exactly: OS version RMX1993EX_11_A15)

Upvotes: 7

brand
brand

Reputation: 581

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.

Upvotes: 57

Vikasdeep Singh
Vikasdeep Singh

Reputation: 21776

You can not do that. It is straight forward security breach which of course Google will not allow you.

You can not control permissions of other apps via your app or simply by using adb commands.

Upvotes: 1

Related Questions