Automating USB Debug Enabling on Non-Root Android Devices Using AccessibilityService

This article demonstrates how to automatically enable USB debugging on a non‑root Android phone after reboot by installing a high‑permission app that uses an AccessibilityService to detect the debug state, launch the developer options, and simulate user interactions to toggle the setting.

Baidu Intelligent Testing
Baidu Intelligent Testing
Baidu Intelligent Testing
Automating USB Debug Enabling on Non-Root Android Devices Using AccessibilityService

During remote Android automated testing, a device may reboot and the Developer Options, including USB debugging, become disabled, requiring manual re‑enablement via ADB.

This article explores automating that process on a non‑root phone by pre‑installing a privileged app that runs at boot and uses Android's AccessibilityService to monitor and enable USB debugging.

Experiment plan

1. Ensure the app is pre‑installed and can start on boot via a BroadcastReceiver listening for RECEIVE_BOOT_COMPLETED. 2. The app checks the current USB debugging status. 3. If disabled, the app launches the Developer Options screen and, using AccessibilityService, traverses the UI hierarchy to toggle the master switch and the USB debugging switch, confirming any dialogs.

The AccessibilityService is declared in AndroidManifest.xml with the appropriate intent‑filter and BIND_ACCESSIBILITY_SERVICE permission. It overrides onAccessibilityEvent to filter TYPE_WINDOW_STATE_CHANGED events, obtains the UI node tree, and performs click actions on the required elements.

To reduce variability across manufacturers, the service directly opens the Developer Options settings page, then performs the minimal steps: enable the global switch, confirm the dialog, enable USB debugging, and confirm again.

Testing on a Nexus 5 shows that after a reboot the app starts within two minutes, detects the disabled state, and successfully enables USB debugging, as demonstrated by the final GIF.

The article also discusses broader uses and potential abuses of AccessibilityService, urging responsible use.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Mobile DevelopmentAndroidAccessibilityServiceNon-rootUSB debugging
Baidu Intelligent Testing
Written by

Baidu Intelligent Testing

Welcome to follow.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.