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_clientforwardspairto 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 unavailablehere. We already use Avahi for Tether discovery. adb pair(before 34.0.5) andadb connectexit with 0 on failure.- A developer who uses adb expects
adb kill-serverand 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._tcpwith that service name.
Decision
- Shell out to the
adbbinary (distro package, version ≥ 34.0.0, parsed fromadb version). Output is parsed; exit codes are not trusted. Onlyhost:track-devices-lis spoken directly to the adb server for event-driven device state. - Private adb server by default: own key directory
(
$XDG_DATA_HOME/tether/adb, viaHOME/ANDROID_USER_HOMEoverride), 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. Configadb_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._tcpwith Avahi, matches the service name and runsadb 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 byandroid.permission.DUMP, which only shell and system hold); the app returns it inAdbLinkover the Tether session. Serial ↔ device id is stored inconfig.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, whichpsshows). - State:
EnhancedStateper device (docs/reference/dbus-api.md). When Wireless debugging is off and the app holdsWRITE_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_SETTINGSre-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-serverby 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.