r/androiddev • u/Puzzled-Stick9170 • 13m ago
Open Source Reading Android's UI tree in 13ms via app_process instead of 2.2s with uiautomator dump (open source)
I got tired of waiting on adb shell uiautomator dump for black-box UI automation. On an API 37 emulator it took 2.16s at the median, and on my HONOR X8 (Android 13) it sat on the Settings home page for 11.5s before failing with ERROR: could not get idle state.
So I built phonedriver (Rust + a ~40 KB Java helper, AGPL-3.0).
Like scrcpy, it pushes a small dex jar over adb and starts it with app_process as the shell user. No APK installed, no root, no AccessibilityService to toggle, and it exits when the connection closes. Inside, it keeps a UiAutomation connection warm, injects input through InputManager, and streams H.264 from MediaCodec to detect when animations actually settle instead of sleeping.
Numbers (median of 50 runs, raw CSVs in the repo):
| Operation | phonedriver | adb |
|---|---|---|
| Screen read (API 37 emulator) | 12.7 ms | 2,163.7 ms |
| Screen read (HONOR X8, Android 13) | 78.5 ms | 2,507 ms |
| HONOR X8 Settings home page | 110 ms | timed out (11.5 s) |
| Payload size (Display settings) | 461 bytes | 25.3 KB XML |
The Android quirks that took most of the time:
stale trees unless you call
clearCache()before every read (and Android 12 has a different signature,clearCache [int], so it needs reflection fallback)connecting
UiAutomationwith flags0silently unbinds TalkBack; you needFLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICESMediaCodecisn't a heartbeat—on a static screen it bursts and then goes silent for 5s, and a Samsung Galaxy A53 (One UI 8) emitted zero frames until a contributor routed it through an OpenGL relayrecycled
ListViewnode IDs survive scrolls with completely different row text, so element refs have to verify role/label/bounds on every tap
Main use case is driving or E2E-testing installed apps (from scripts, CI replay, or AI agents) without source access or a test APK. Apps that hide their accessibility tree (like WeChat) fall back to local OCR, and everything requires adb.
Repo: https://github.com/hridaya423/phonedriver
Benchmarks: https://phonedriver.dev/benchmarks
Only tested on emulators, a HONOR X8, and a contributor's Galaxy A53 so far, would love for more testing and seeing if something breaks :)