How to debug/reset Android 6.0 permissions?
T

1

31

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?

Thusly answered 29/12, 2015 at 14:15 Comment(2)
anyone interested using a shell script can refer gist.github.com/nitiwari-dev/90df91e3eb21864ca711b271e071b77bJackinthepulpit
As of API 33 you can programmatically revoke permissions: #31535588. Useful function to add to an internal debug/warmup screen/activity.Birkett
T
49

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.

Thusly answered 29/12, 2015 at 14:16 Comment(7)
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)Pacificia
True! But it is a downside in contrast with the other command mentioned. Because that command doesn't restart the app.Doggoned
The fact that reset-permissions does not kill the app is raised as a bug - code.google.com/p/android/issues/detail?id=195087Pacificia
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.Doggoned
How to reset permissions for a specific app?Darling
When I add the package name after reset-permission, it resets them for all running appsSlickenside
@StevenElliott you are right, I somehow thought it was designed like this, it seems it's not.Doggoned

© 2022 - 2024 — McMap. All rights reserved.