Skip to content

Automatically kill running ADB server before opening USB devices - #5

Closed
Averroeskw wants to merge 2 commits into
PenumbraOS:mainfrom
Averroeskw:fix/auto-kill-adb-server
Closed

Averroeskw wants to merge 2 commits into
PenumbraOS:mainfrom
Averroeskw:fix/auto-kill-adb-server

Conversation

@Averroeskw

Copy link
Copy Markdown

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 runs adb kill-server.

Change

  • adb_client: adds ADBServer::kill_if_running(). It probes the server address (default 127.0.0.1:5037) with a plain TCP connect and, only if something is listening, issues host:kill over the ADB smart protocol. Unlike the existing ADBServer::kill(), it never goes through connect(), which would spawn adb start-server first — so no adb binary is required and nothing is started just to be killed. If no server is listening it logs at debug level and returns Ok(()).
  • adb_cli: the usb subcommand now calls ADBServer::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 local subcommand is untouched — it needs the server and still starts it.

Verification

Tested on macOS (no Ai Pin needed for this one):

  • With a running server (adb start-server, confirmed listening on :5037): adb_cli usb shell ls logs killing currently running ADB server..., the server process is gone afterwards, and the command proceeds to USB autodetection.
  • With no server running: logs no ADB server listening on 127.0.0.1:5037 at debug level and proceeds directly, no error and no server spawned.
  • cargo build --release and cargo clippy --release are clean (no new warnings vs main).

🤖 Generated with Claude Code

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>
@agg23

agg23 commented Jul 2, 2026

Copy link
Copy Markdown
Member

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>
@Averroeskw

Copy link
Copy Markdown
Author

Fair point — killing another server unprompted is surprising behavior. Reworked: by default a running server now just produces an actionable error (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 an explicit --kill-server flag. The probe (ADBServer::is_running()) is side-effect-free and nothing is ever started or stopped without asking.

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.

@Averroeskw

Copy link
Copy Markdown
Author

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.

@Averroeskw Averroeskw closed this Jul 3, 2026
@agg23

agg23 commented Jul 3, 2026

Copy link
Copy Markdown
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically kill real ADB server when running command

2 participants