-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Goal
Implement the _capture_u2() backend in adb_vision/screenshot.py.
uiautomator2's ATX agent captures screenshots via Android's UiDevice.takeScreenshot() API served over HTTP on port 7912. Unlike adb shell screencap, this uses the Android graphics stack directly, bypassing the Linux framebuffer — which is critical because adb shell screencap returns blank images on MEmu/VirtualBox.
Interface
async def _capture_u2(*, adb_run: AdbRunFn, serial: str, adb_exe: str) -> str:
"""Return base64-encoded PNG screenshot via uiautomator2 ATX HTTP agent."""Implementation Plan
-
Check if ATX agent is running:
GET http://localhost:7912/info(after port forward)- If not: push and start the ATX agent APKs
-
Initialize ATX agent (if needed):
- Push ATX app + test APKs to device
- APKs are at:
alas_wrapped/bin/uiautomator2/(check exact paths) - Start via:
adb shell am instrument -w -r -e ...or the simpleradb shell /data/local/tmp/atx-agent server -d
-
Forward port:
adb_run("forward", "tcp:7912", "tcp:7912", timeout=5.0) -
Take screenshot:
GET http://localhost:7912/screenshot/0?compress=true- Returns JPEG by default. Request PNG:
GET http://localhost:7912/screenshot/0?format=png - Or get JPEG and convert to PNG with Pillow
- Returns JPEG by default. Request PNG:
-
Return base64-encoded PNG
Key Reference
The ALAS codebase already has ATX initialization code. Key patterns to borrow from (but NOT import):
alas_wrapped/module/device/connection.py— ATX agent setupalas_wrapped/module/device/method/uiautomator_2.py— screenshot via u2
The standalone approach should NOT use the uiautomator2 Python library. Instead, talk to the ATX HTTP API directly — it's just REST calls.
Testing (TDD)
- Mock test: Mock
adb_runfor port forward. Mock HTTPGET /screenshot/0returning fake PNG bytes. Verify base64 result. - Agent-not-running test: Mock HTTP returning connection refused → should attempt to start agent, or raise clear error.
- Port-forward test: Verify
adb forward tcp:7912 tcp:7912is called.
Tests must pass without a device — all ADB and HTTP calls mocked.
Files to Modify
adb_vision/screenshot.py— replace the_capture_u2stub- New
adb_vision/test_u2.py— tests
Acceptance Criteria
-
_capture_u2()returns valid base64 PNG when ATX agent is running - All existing tests still pass
- New tests cover: happy path, agent not running, HTTP failure
- No ALAS imports — talk to ATX HTTP API directly
- No
uiautomator2Python library dependency