|
| 1 | +# Android Snapshot Helper |
| 2 | + |
| 3 | +Small instrumentation APK used to capture Android accessibility snapshots without relying on |
| 4 | +`uiautomator dump`'s fixed idle wait behavior. The helper enables Android's interactive-window |
| 5 | +retrieval flag and serializes every accessible window root returned by `UiAutomation.getWindows()` |
| 6 | +so keyboards and system overlays can appear in the same snapshot. If interactive window roots are |
| 7 | +unavailable, it falls back to the active-window root. |
| 8 | + |
| 9 | +The helper is intentionally provider-neutral. Local `adb`, cloud ADB tunnels, and remote device |
| 10 | +providers can all install and run the same APK as long as they can execute ADB-style operations. |
| 11 | +Released helper APKs use the committed `debug.keystore`; do not rotate it casually, because Android |
| 12 | +requires a stable signing certificate for `adb install -r` upgrades. |
| 13 | + |
| 14 | +## Build |
| 15 | + |
| 16 | +```sh |
| 17 | +sh ./scripts/build-android-snapshot-helper.sh 0.13.3 .tmp/android-snapshot-helper |
| 18 | +``` |
| 19 | + |
| 20 | +The build uses Android SDK command-line tools directly. It expects `ANDROID_HOME` or |
| 21 | +`ANDROID_SDK_ROOT` to point at an SDK with `platforms/android-36` and matching build tools. |
| 22 | +`pnpm prepack` builds the npm-bundled helper into `android-snapshot-helper/dist`; npm users get |
| 23 | +that APK in the package and the first helper-backed `snapshot` installs it automatically when |
| 24 | +missing or outdated. |
| 25 | + |
| 26 | +## Run |
| 27 | + |
| 28 | +```sh |
| 29 | +adb install -r -t .tmp/android-snapshot-helper/agent-device-android-snapshot-helper-0.13.3.apk |
| 30 | +adb shell am instrument -w \ |
| 31 | + -e waitForIdleTimeoutMs 500 \ |
| 32 | + -e timeoutMs 8000 \ |
| 33 | + -e maxDepth 128 \ |
| 34 | + -e maxNodes 5000 \ |
| 35 | + com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation |
| 36 | +``` |
| 37 | + |
| 38 | +`maxDepth` also caps recursive traversal depth inside the helper. |
| 39 | +The `-t` install flag is required because the helper is a debuggable instrumentation/test APK. |
| 40 | +Devices or providers that block test-package installs must allow this package before helper capture |
| 41 | +can run. |
| 42 | + |
| 43 | +## Output Contract |
| 44 | + |
| 45 | +The APK emits instrumentation status records using |
| 46 | +`agentDeviceProtocol=android-snapshot-helper-v1`. |
| 47 | + |
| 48 | +Each XML chunk is sent with: |
| 49 | + |
| 50 | +- `outputFormat=uiautomator-xml` |
| 51 | +- `chunkIndex` |
| 52 | +- `chunkCount` |
| 53 | +- `payloadBase64` |
| 54 | + |
| 55 | +The final instrumentation result includes: |
| 56 | + |
| 57 | +- `ok=true` |
| 58 | +- `helperApiVersion=1` |
| 59 | +- `waitForIdleTimeoutMs` |
| 60 | +- `timeoutMs` |
| 61 | +- `maxDepth` |
| 62 | +- `maxNodes` |
| 63 | +- `rootPresent` |
| 64 | +- `captureMode` (`interactive-windows` or `active-window`) |
| 65 | +- `windowCount` |
| 66 | +- `nodeCount` |
| 67 | +- `truncated` |
| 68 | +- `elapsedMs` |
| 69 | + |
| 70 | +Failures return `ok=false`, `errorType`, and `message` in the final result. |
| 71 | + |
| 72 | +The release manifest is a stable provider contract for the current helper protocol. Providers should |
| 73 | +resolve the APK from `apkUrl`, verify `sha256`, install using `installArgs`, and run |
| 74 | +`instrumentationRunner`. `installArgs` must start with `install`; extra arguments are limited to the |
| 75 | +allowlisted adb install flags `-r`, `-t`, `-d`, and `-g`, and the consumer appends the APK path. |
0 commit comments