Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR-0016: adb integration: private adb server, QR pairing, Avahi discovery, reverse tunnel

  • Status: accepted
  • Date: 2026-11-15
  • Deciders: maintainer, after the M4 research round (docs/notes/m4-research-desktop.md)
  • Tags: linux, android, adb, security

Context

The enhanced tier (ADR-0007) needs the daemon to obtain and keep adb access to the phone without the user touching a terminal: pair over Wireless debugging, find the phone again when its port changes, notice when debugging is switched off (Samsung does that on reboot), and start the shell helper. Research findings that constrain the design:

  • No Rust crate implements Wireless debugging pairing (SPAKE2 over TLS); adb_client forwards pair to an adb server.
  • adb’s own mDNS is unusable: Debian 13’s adb 34.0.5 is built without it and the Google 35.0.0 binary answers mdns daemon unavailable here. We already use Avahi for Tether discovery.
  • adb pair (before 34.0.5) and adb connect exit with 0 on failure.
  • A developer who uses adb expects adb kill-server and their device list to be their own.
  • Android Studio pairs by showing a QR code WIFI:T:ADB;S:<name>;P:<password>;; that the phone scans under Wireless debugging; the phone then advertises _adb-tls-pairing._tcp with that service name.

Decision

  • Shell out to the adb binary (distro package, version ≥ 34.0.0, parsed from adb version). Output is parsed; exit codes are not trusted. Only host:track-devices-l is spoken directly to the adb server for event-driven device state.
  • Private adb server by default: own key directory ($XDG_DATA_HOME/tether/adb, via HOME/ANDROID_USER_HOME override), own server port (ANDROID_ADB_SERVER_PORT, default 5038), ADB_MDNS=0. The user’s own server and key are not touched and the phone does not show up in their tools through us. Config adb_server = "private" | "shared". A phone attached by USB is visible to whichever server owns the USB interface; in private mode our server leaves USB to the user’s (ADB_USB=0) and USB set-up goes through the shared server on request.
  • Pairing: QR flow first (the GTK app renders the payload; the daemon browses _adb-tls-pairing._tcp with Avahi, matches the service name and runs adb pair ip:port password), 6-digit code as fallback (same browse, user types the code).
  • Connecting: Avahi browse of _adb-tls-connect._tcp; adb connect ip:port; re-run whenever the service appears or its port changes.
  • Linking an adb device to a paired phone: the daemon sends a one-time token with adb shell am broadcast -n org.tether.android/.enhance.AdbLinkReceiver --es token … (receiver guarded by android.permission.DUMP, which only shell and system hold); the app returns it in AdbLink over the Tether session. Serial ↔ device id is stored in config.toml.
  • Helper transport: adb reverse localabstract:tether_<nonce> tcp:<port> to a daemon listener on 127.0.0.1 with an ephemeral port; the helper opens separate connections for control and each media stream. Every connection authenticates with a one-time token that the daemon writes to the helper’s stdin (never argv, which ps shows).
  • State: EnhancedState per device (docs/reference/dbus-api.md). When Wireless debugging is off and the app holds WRITE_SECURE_SETTINGS (one of the grants), the daemon asks the app to switch it back on (AdbWifiRequest).

Amendment 2026-11-15 (M4.1 implementation)

The private server carries Wi-Fi connections only. A USB-attached phone is reached through the user’s default adb server and key, which the daemon starts only when a phone is linked or SetUpEnhanced() is called. The stored serial is the hardware serial, because Wi-Fi transport serials change with the port. Details: docs/reference/dbus-api.md “Implementation notes and deviations (M4.1)”.

Consequences

Positive

  • One code path for USB and Wi-Fi after the device is connected.
  • No interference with the user’s development adb.
  • Pairing without typing; reconnect without user action in the common case.

Negative / risks

  • Depends on output strings of adb; covered by parser tests with captured output and a version floor.
  • A second adb server process while Tether runs.
  • Anyone local can connect to the 127.0.0.1 listener; the token gates it.
  • A desktop with adb authorisation has a full shell on the phone (ADR-0007).
  • Auto Blocker’s effect on Wireless debugging and the WRITE_SECURE_SETTINGS re-arm on One UI are unverified until tested on the A55.

Alternatives considered

  • Native adb protocol in Rust: no pairing implementation exists; large.
  • Shared server only: simplest, but adb kill-server by the user or an IDE drops mirroring, and our phone appears in their device lists.
  • Helper dials the daemon over LAN TLS: saves the tunnel hop, needs the helper to carry TLS and the pinned identity; kept as a later optimisation.
  • Unix-socket reverse target (localfilesystem:): untested with distro adb.