Mastering ADB Commands: Granting and Revoking App Permissions

Mastering ADB Commands: Granting and Revoking App Permissions

22 April 2024 Stephan Petzl Leave a comment Tech-Help


As an Android developer or a power user, you might find yourself in a situation where you need to adjust the permissions of an app on your device. This can be particularly useful during development or testing phases. The Android Debug Bridge (ADB) provides commands such as adb grant and adb revoke to manage these permissions. In this guide, we’ll explore the correct syntax and usage of these commands.

Granting Permissions

To grant a permission to an application, you need to use the following syntax:

adb shell pm grant <> <permission>

For example, to grant the READ_PROFILE permission to your app, you would execute:

adb shell pm grant android.permission.READ_PROFILE

It’s important to note that you can only grant permissions that the app has declared as optional in its manifest file.

Revoking Permissions

Similarly, to revoke a permission from an application, use the syntax:

adb shell pm revoke <> <permission>

To revoke the READ_PROFILE permission from your app, the command would be:

adb shell pm revoke android.permission.READ_PROFILE

Just like granting, you can only revoke permissions that the app has declared in its manifest.

Finding Permissions

If you need to find out which permissions an app is using, you can follow these steps:

  1. List all installed packages with their paths using adb shell pm list packages -f
  2. Copy the desired package to your computer with adb pull /path/to/package.apk
  3. Use the Android Asset Packaging Tool (AAPT) to list the permissions with aapt d permissions path/to/app.apk

This process will provide you with a list of permissions used by the app, which can be helpful in understanding what permissions to grant or revoke.

Resetting Permissions

If you’re looking to reset the permissions for all apps on your device, you can use the following command:

adb shell pm reset-permissions

Warning: This command will reset the runtime permissions for all apps on your device. It is not possible to reset permissions for a specific package only.

Automating Permission Management with Repeato

Managing permissions during automated testing can be a repetitive and time-consuming task. Our product, Repeato, can streamline this process. As a no-code test automation tool for iOS and Android, Repeato allows you to integrate permission management into your automated test suites.

With Repeato’s capability to execute ADB commands via script steps, testers can easily grant or revoke permissions within their test scenarios. This functionality, combined with Repeato’s computer vision and AI-based approach, ensures that your app behaves as expected under various permission states.

Repeato is compatible with a variety of app frameworks, including React Native, Flutter, and Unity, and it provides a fast and efficient way to edit and run tests. This makes it an excellent addition to any mobile app development toolkit, helping to ensure robust permission handling and app functionality.

Like this article? there’s more where that came from!