Granting powerful permissions like SYSTEM_ALERT_WINDOW (draw‑over‑other‑apps) or WRITE_SECURE_SETTINGS gives an app capabilities that are normally reserved for system components. Misuse can lead to privacy leaks, unwanted overlays, or even device instability. This tutorial explains exactly why you might need these permissions, how to grant them safely via ADB, and how to verify or revoke them later.
Make sure you have the following prerequisites:
WRITE_SECURE_SETTINGS to untrusted apps. This permission can change system‑wide settings, disable security features, and potentially brick the device if misused.Android classifies permissions into several groups. The two most common “high‑risk” permissions that people request via ADB are:
Both permissions are runtime permissions, meaning the user normally has to approve them in the UI. ADB can bypass the UI for debugging or testing purposes, but the same security considerations apply.
adb devices. You should see a line like 0123456789ABCDEF device. If the status is unauthorized, check the phone for a dialog asking to Allow USB debugging and tap Allow.adb tcpip 5555, disconnect the cable, find the phone’s IP in Settings > About phone > Status, then run adb connect IP_ADDRESS:5555. Verify with adb devices again.The package name is the unique identifier used by Android (e.g., com.example.myapp). You can obtain it in several ways:
id=.adb shell pm list packages | grep -i myapp.Use the pm grant command. The syntax is:
adb shell pm grant <package_name> <permission_name>
Examples:
SYSTEM_ALERT_WINDOW to com.example.overlay:
adb shell pm grant com.example.overlay android.permission.SYSTEM_ALERT_WINDOW
WRITE_SECURE_SETTINGS to com.example.tuner:
adb shell pm grant com.example.tuner android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant --user 0 variant or temporarily install the app as a system app via adb push (outside the scope of this tutorial).Why this works: The pm (package manager) tool runs with the same privileges as the shell user, which Android treats as a privileged debugging user when USB debugging is enabled. It can directly modify the app’s granted permissions database.
Run the following command to dump the app’s permission state:
adb shell dumpsys package <package_name> | grep granted
Look for a line containing the permission you granted. For example:
android.permission.SYSTEM_ALERT_WINDOW: granted=true
You can also check the UI:
Launch the app and perform the action that required the permission. For a floating widget, you should now see the overlay appear on top of other apps. For a tuner that changes secure settings, navigate to the relevant system screen and confirm the change took effect.
If you later decide the app no longer needs the elevated rights, revoke them with pm revoke:
adb shell pm revoke <package_name> <permission_name>
Example:
adb shell pm revoke com.example.overlay android.permission.SYSTEM_ALERT_WINDOW
After revoking, the UI toggle will turn off and the app will lose the ability to draw overlays.
Android’s hidden appops tool can enable or disable specific operations that are not exposed as normal permissions. It’s useful when pm grant is blocked (e.g., on newer Android versions).
adb shell appops get <package_name>
For drawing overlays, the operation code is SYSTEM_ALERT_WINDOW (same name as the permission). Use:
adb shell appops set <package_name> SYSTEM_ALERT_WINDOW allow
adb shell appops get <package_name> SYSTEM_ALERT_WINDOW
It should report allow.
Note: appops is undocumented and may change without notice. It also requires the same debugging privileges as pm.
adb devices: Ensure USB debugging is enabled, the cable is data‑capable, and the phone’s screen is unlocked. On some OEM skins you must also enable “USB debugging (Security settings)” under Developer options.--user 0 to the command:
adb shell pm grant --user 0 com.example.tuner android.permission.WRITE_SECURE_SETTINGS
If it still fails, the permission cannot be granted without root on that build.
Settings.canDrawOverlays()) which may cache the result. Force‑stop and restart the app, or reboot the device.
adb backup -apk -shared -all -f backup.ab (optional, for full device backup).pm grant command you run, so you can easily revoke later.pm command operates on the primary user (user 0) by default. To target a work profile, use the --user flag with the profile’s user ID (obtainable via adb shell pm list users).Imagine you are testing a new “floating notes” app that lets you write quick notes that appear on top of any screen. The Play Store version does not request the overlay permission automatically because the developer wants the user to enable it manually. You want to automate the test on multiple devices.
adb install notes.apk.adb shell pm list packages | grep notes → com.example.floatingnotes.adb shell pm grant com.example.floatingnotes android.permission.SYSTEM_ALERT_WINDOW
adb shell dumpsys package com.example.floatingnotes | grep SYSTEM_ALERT_WINDOW.adb shell monkey -p com.example.floatingnotes -c android.intent.category.LAUNCHER 1
adb shell pm revoke com.example.floatingnotes android.permission.SYSTEM_ALERT_WINDOW
This workflow can be scripted in a CI pipeline to test overlay behavior across many device models without manual interaction.
Using ADB’s pm grant (or appops set) you can safely give an app high‑risk permissions for debugging, testing, or controlled personal use. The process is straightforward:
adb shell pm grant <package> <permission>.dumpsys package or the Settings UI.Always keep security in mind: only grant what you truly need, document every change, and revert the permission once testing is complete. With these safeguards, ADB becomes a powerful ally for developers and power users alike.









