Automatically kill running ADB server before opening USB devices - #5
Averroeskw wants to merge 2 commits into
Conversation
A running ADB server captures connected USB devices, preventing this client from accessing them. Add ADBServer::kill_if_running(), which asks a listening server (if any) to quit over the ADB smart protocol without spawning a new server instance, and call it before opening a USB device. Fixes PenumbraOS#1 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
I'm going back and forth on whether or not this is a good idea. I guess this would need to be a thing exclusively because this is a special version of the ADB server that can do our auth, but at the same time it seems weird to patch the client to shut down other servers. |
…default, --kill-server to opt in Addresses review feedback: patching the client to shut down other servers unprompted is surprising. Now a running server produces 'a running ADB server is holding USB devices. Stop it with `adb kill-server` or re-run with --kill-server.' and the kill only happens with the explicit flag. Adds side-effect-free ADBServer::is_running() for the probe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Fair point — killing another server unprompted is surprising behavior. Reworked: by default a running server now just produces an actionable error ( One request: please hold off merging either PR for now — my Pin's interposer is still inbound, and I'd like to verify everything end-to-end on the actual device before this lands. |
|
Closing for now — pulling this back until I've verified the full stack end-to-end on the physical device (interposer inbound). Will reopen once it's hardware-verified. The branch lives on in my fork history if anyone needs the diff in the meantime. |
|
Neither of these changes require an Ai Pin or an interposer; you just need an Android device (and you could even use the emulator if you so desire). |
Fixes #1
Problem
A running stock ADB server captures connected USB devices, so
adb_remote_auth usb …fails to claim the interface until the user manually runsadb kill-server.Change
adb_client: addsADBServer::kill_if_running(). It probes the server address (default127.0.0.1:5037) with a plain TCP connect and, only if something is listening, issueshost:killover the ADB smart protocol. Unlike the existingADBServer::kill(), it never goes throughconnect(), which would spawnadb start-serverfirst — so noadbbinary is required and nothing is started just to be killed. If no server is listening it logs at debug level and returnsOk(()).adb_cli: theusbsubcommand now callsADBServer::default().kill_if_running()before opening the USB device. Failures are logged as a warning and do not abort the command (the device open path will surface any real problem).The
localsubcommand is untouched — it needs the server and still starts it.Verification
Tested on macOS (no Ai Pin needed for this one):
adb start-server, confirmed listening on:5037):adb_cli usb shell lslogskilling currently running ADB server..., the server process is gone afterwards, and the command proceeds to USB autodetection.no ADB server listening on 127.0.0.1:5037at debug level and proceeds directly, no error and no server spawned.cargo build --releaseandcargo clippy --releaseare clean (no new warnings vsmain).🤖 Generated with Claude Code