Make Android ADB async and talk to the ADB server over its smartsocket protocol - #8
Merged
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
staging-devin-ai-integration
Bot
changed the base branch from
devin/1787275698-async-adb
to
main
August 21, 2026 21:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes to the Android backend, previously split across #7 and this PR and now combined here.
1. ADB calls are async with a timeout. Every one-shot ADB invocation used
std::process::Command::output()with no timeout, so each call held a thread untiladbexited. All of them are now async and time-bounded (30s default), and the async-ness propagates throughAndroidAccessibility, the Android session/serve layers, and the CLI —AccessibilityReader::capture_screenis future-returning on all platforms as a result. Emulator discovery and screenshot writes moved totokio::fs; the long-livedscreenrecordchild and the synchronous native paths stayed as they were.2.
AdbClientno longer forksadbat all. It opens a TCP socket to the adb server (127.0.0.1:5037, honoringANDROID_ADB_SERVER_PORT) and speaks the smartsocket protocol directly, so a tap is a socket round-trip instead of a process, and a timeout cancels by dropping the socket rather than killing a child.New
transport.rsimplements the slice we need — hand-rolled rather than pulling indroidrun-adb/adbutils-rs, since it's a small, stable subset:shell v2 packets are
[id: u8][len: u32 LE][payload]with ids decoded through a#[repr(u8)] ShellPacketId; unknown ids, packets over 1 MiB, and accumulated output over 64 MiB are rejected before allocating.Two behavior changes worth knowing:
adb shellnever returned the device command's exit code; shell v2 does, soshell()/shell_raw()now error on a non-zero device command instead of silently returning its output.command(&[&str])is gone. Those were host services, not shell commands, so they're typed now:wait_for_device()(host:wait-for-any-device/host-serial:<s>:wait-for-any-device),server_version(),server_features().connected_devices()ishost:devices.The
adbbinary is still used for exactly two things:start-serverwhen nothing is listening (one retry, then an error naming both the missing server and the missing binary), and the long-livedscreenrecordchild, which is unchanged.Fallout of (1) and (2): the Android workers no longer need threads of their own.
spawn_ax_workerandspawn_input_workereach ran an OS thread hosting a current-thread runtime andblock_on-ing every command — scaffolding that only existed because ADB blocked. Both are now plaintokio::spawntasks on the ambient runtime (the input worker's startup handshake becomes aoneshotrather than async_channel), and the two emulator probe examples lost the same nested-runtime pattern.Testing
Unit tests drive a mock adb server over a real
TcpListener: request strings and the 8-byte tid read,host:devicesstate filtering, stdout/stderr split across packets with exit status, non-zero exit surfacing stderr,FAILmessages, truncated status/payload/header, EOF before the exit packet, oversized declared lengths, unknown packet ids, binaryexec:passthrough with embedded NULs, and request timeout. They bind real sockets, so they carry#[cfg_attr(miri, ignore)]— miri's isolation has no socket syscalls — while the framing/parsing tests still run under it.android-e2epasses against a real emulator in CI, which caught the one bug the mocks couldn't:connected_devices()still did.lines().skip(1)to drop theadb devicesCLI banner, buthost:devicesdoesn't send one, so the first (and in CI, only) device was discarded and everything reported "No Android devices connected". The mock had the banner baked into its payload, which hid it; it now sends raw server output.cargo fmt,clippy -D warnings,cargo test --workspace --lib --bins, andcli_smokeall pass. The smoke tests that simulate a missing adb now also pointANDROID_ADB_SERVER_PORTat a dead port, since a running local server would otherwise satisfy the client without any binary onPATH.One unrelated fix rides along: CI's clippy flags
result_large_errin generated tonic code, so the generatedprotocolmodule carries a scoped allow.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/d88fc07ea8064b38a4b4e5a7481ffebc
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/d88fc07ea8064b38a4b4e5a7481ffebc?variant=devin-insiders
Requested by: @jkelleyrtp