22

While migrating one of my apps to use the Android 6.0 permissions system, I found it very hard to debug permissions using the emulator.

Findings:

  • Disabling a permission in the app info screen doesn't re-show the grant permission dialog when using the requestPermissions() method.
  • Reinstalling the app seems to be the only way to make the app show the grant permission dialog again.

What is the proper method to debug permission using the Android emulator?

Rolf ツ
  • 8,197
  • 5
  • 44
  • 72
  • anyone interested using a shell script can refer https://gist.github.com/nitiwari-dev/90df91e3eb21864ca711b271e071b77b – nitesh Feb 16 '17 at 08:33

1 Answers1

38

It’s actually very easy to debug Android 6.0 permissions. You can reset the permissions to the "install state" for the current foreground app all apps using the following ADB shell command:

adb shell pm reset-permissions

Note: Currently you can't reset the runtime permissions for a specific package, the package manger (pm) tool help section states:

revert all runtime permissions to their default state.

You can easily execute the reset-permissions command using the terminal interface in Android Studio. Note that ADB commands only works if the ADB directory is added to the PATH system environment variable (see: add ADB to path variable).

You can also reset/revoke a specific permissions using:

adb shell pm revoke com.your.package android.permission.WRITE_EXTERNAL_STORAGE

A downside of this command is that it will restart your app, but this doesn't reset the runtime permissions for all apps. To grant a permission replace revoke with grant.

Community
  • 1
  • 1
Rolf ツ
  • 8,197
  • 5
  • 44
  • 72
  • 1
    That's hardly a "downside" - it's the way things are designed to work! If permissions are changed for an app, normally done via the settings UI, then the app is restarted (so that it gets a chance to check for the changed permissions) – zmarties Dec 29 '15 at 14:33
  • True! But it is a downside in contrast with the other command mentioned. Because that command doesn't restart the app. – Rolf ツ Dec 29 '15 at 14:35
  • 2
    The fact that reset-permissions does not kill the app is raised as a bug - https://code.google.com/p/android/issues/detail?id=195087 – zmarties Dec 29 '15 at 14:42
  • 1
    The bug report isn't about the ADB command though, so we can't be sure if it is expected behavior (for the command) or not. – Rolf ツ Dec 29 '15 at 14:44
  • 3
    How to reset permissions for a specific app? – nicael Aug 04 '16 at 09:05
  • When I add the package name after reset-permission, it resets them for all running apps – Steven Elliott Sep 15 '16 at 13:24
  • @StevenElliott you are right, I somehow thought it was designed like this, it seems it's not. – Rolf ツ Sep 15 '16 at 13:59