How to grant/revoke permissions with adb in Android

This article will introduce how to grant/revoke a package permissions with adb.

1. "adb shell pm grant --user 0 PACKAGE PERMISSION"

The following command grants ACCESS_FINE_LOCATION permission to the Youtube app installed on User 0.

If the --user option is omitted, the default value User 0 is used.

$ adb shell pm grant --user 0 com.google.android.youtube android.permission.ACCESS_FINE_LOCATION

And, you can check the status of the permission in the runtime permissions: from the package information by the following command.

granted=true means that the permission has been granted to the app.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    codePath=/product/app/YouTube
    ....
    install permissions:
      com.google.android.c2dm.permission.RECEIVE: granted=true
      android.permission.USE_CREDENTIALS: granted=true
    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=0 instant=false virtual=false
      gids=[3003]
      runtime permissions:
        android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.ACCESS_COARSE_LOCATION: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]

2. "adb shell pm revoke --user 0 PACKAGE PERMISSION"

The following command revokes the ACCESS_FINE_LOCATION permission from the Youtube app installed on User 0.

If the --user option is omitted, the default value User 0 is used.

$ adb shell pm revoke --user 0 com.google.android.youtube android.permission.ACCESS_FINE_LOCATION

You can check the status of the permission in the runtime permissions: of the package information.

granted=false means that it had revoked the app the permission.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    codePath=/product/app/YouTube
    ....
    install permissions:
      com.google.android.c2dm.permission.RECEIVE: granted=true
      android.permission.USE_CREDENTIALS: granted=true
    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=0 instant=false virtual=false
      gids=[3003]
      runtime permissions:
        android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.ACCESS_COARSE_LOCATION: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]

3. "adb shell pm reset-permissions"

This command will reset all runtime permissions of an app to their initial settings. System-granted permissions will be changed to granted, and all other permissions will be reset to revoked.

$ adb shell pm reset-permissions

Related Posts

codechachaCopyright ©2019 codechacha