If you’ve ever used ADB (Android Debug Bridge), you’re probably familiar with the basics: adb install, adb shell input tap, or adb shell input swipe. These commands are great for simple automation.
But what if you could send Play/Pause to a music app running in the background? What if you could simulate a Camera shutter press, a Media Next command, or even a Power button long-press—all without touching the screen?
Enter ADB Extended Keys.
These are not just keyboard strokes. They are Android key event codes that map directly to hardware buttons and system functions. When combined with adb shell input keyevent, they unlock a new level of app control, automation, and testing.
Let’s dive deep into what extended keys are, how to use them, and the most powerful codes you need to know. adb app control extended key
appops Command – The Real Extended Controlappops is the unsung hero of ADB app control. It manages low-level app operations. This is where the "extended key" truly shines.
Syntax: adb shell appops set <package> <op> <mode>
Example Extended Keys with appops:
RUN_IN_BACKGROUND – Control whether an app can run background services.WAKE_LOCK – Prevent apps from keeping the device awake.GET_USAGE_STATS – Grant/revoke usage access without navigating settings.Real-world command:
adb shell appops set com.facebook.katana RUN_IN_BACKGROUND ignore
This command (using the extended key RUN_IN_BACKGROUND and mode ignore) forces Facebook to stop background processes without uninstalling or disabling the app.
This report details the technical implementation and usage of Android Debug Bridge (ADB) commands to simulate input events, specifically focusing on "Extended Keys." These are media or application-specific buttons (such as Play/Pause, Skip, Volume, or Camera buttons) often found on external peripherals (headsets, Bluetooth devices) or specialized hardware. Understanding how to simulate these inputs is critical for QA testing, automation scripting, and developing Android applications that respond to hardware media controls.
# Open settings adb shell am start -a android.settings.SETTINGSRisks and Caveats: The Double-Edged Sword
With great power comes great responsibility. Misusing the ADB App Control Extended Key can lead to:
- Boot loops: Disabling
com.android.systemuiorcom.android.phonewill soft-brick your device.- Data loss: Using
pm clearwith extended flags can wipe app data irreversibly.- Voided warranty: While ADB doesn’t require root, disabling certain system apps may violate your device’s terms of service (though rare).
- Update failures: Some OTA (over-the-air) updates check that all required packages are enabled. Disabling critical ones may block updates.
Golden rule: Always list packages first:
adb shell pm list packages -d(disabled) andadb shell pm list packages -s(suspended). Useadb shell dumpsys package <package>to verify state before and after applying extended keys. Beyond Basic Tap and Swipe: Mastering ADB AppForce-stop to apply immediately
am force-stop $PACKAGE "
echo "Extended key applied to $PACKAGE"
To revert:
adb shell "
cmd app set-app-suspended --user 0 $PACKAGE false &&
pm grant $PACKAGE android.permission.CAMERA
"