Skip to content

Stream over USB without developer mode (Android Open Accessory) - #7

Merged
FacuM merged 10 commits into
mainfrom
feat/aoa
Oct 26, 2026
Merged

FacuM merged 10 commits into
mainfrom
feat/aoa

Conversation

@FacuM

@FacuM FacuM commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Depends on #3 (Wi-Fi transport). This PR is stacked on wifi-transport; review the diff against that branch.

Summary

  • The host switches connected Android tablets to USB accessory mode (AOA) through libusb and streams over the accessory bulk endpoints. Only the MTP/ADB interface of the tablet is touched.
  • USB auto mode tries AOA first and falls back to adb.
  • Android opens the accessory and streams through the same session code as the other transports.
  • The tray and CLI show a hint when USB access fails. Diagnostics report libusb, UsbDk and the USB candidates.

Changes

  • Host: AOA switch and acceptor in ezd-link and ezd-host-service, blocking reader and writer halves for link I/O, and a USB transport option in the service config.
  • Android: accessory streaming in MainActivity and NativeBridge, with the Rust side in ezd-android.
  • Packaging:
    • udev uaccess rule for the accessory and switch devices.
    • libusb added to the PKGBUILD, the Debian package, the AppImage build and CI.
    • optional UsbDk component in the Windows installer.
  • Robustness:
    • the host waits for the bus to settle and retries failed switches;
    • tablets stuck in an old session are reset;
    • the accessory file descriptor is released as soon as the session stops, so replugging works;
    • the client ends the session after 5 seconds of host silence, because accessory links never report a dead host.

Scope notes

  • Windows support is the optional UsbDk path. It is not verified on hardware yet.
  • The ezd-fake-client and protocol crates are unchanged apart from what the transport needs.

Verification

  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings, also with --no-default-features for ezd-host-service, ezd-tray and ezd-host, and for the Android crate on arm64.
  • cargo test --workspace: 682 passed, 2 ignored.
  • Android: assembleFullDebug, assemblePlayDebug, lintFullDebug, testFullDebugUnitTest.
  • On hardware (Linux with KDE, Samsung Galaxy Tab S, USB debugging off):
    • connects over AOA;
    • unplug and replug reconnects, twice, and the second time without any prompt;
    • when the host is killed, the tablet leaves the frozen frame in about 7 seconds and reconnects when the host returns;
    • ADB-only mode (--aoa off --adb) still streams.

Not yet verified:

  • Windows with and without UsbDk (checklist in docs/windows-testing.md).
  • A device without the app being declined and reset on real hardware. This is covered by unit tests only.

FacuM added 9 commits October 25, 2026 17:42
USB bulk endpoints and the Android accessory file descriptor only offer blocking I/O. Each half runs on its own thread, bridged to the async side through an in-memory pipe, so the mux works over them unchanged.
The host polls libusb for devices with an MTP or adb interface, switches one to Android accessory mode and runs the session over its bulk endpoints, so USB works without developer mode. A device whose app never answers is reset and left alone until it is unplugged for a while. Silent accessories stay open between polls so no bytes are lost. On Windows this needs UsbDk; without it the host says so and keeps using adb.
The app opens the accessory the host switched it into, hands the descriptor to the native session and prefers it over the adb loopback and Wi-Fi while it stays attached.
udev rule giving the seat user access to MTP, adb and accessory devices, libusb in the Linux packages and CI, an optional UsbDk download in the Windows installer, and docs.
A tablet still in a session with an earlier host process answers with
stats instead of a handshake: reset it so it renegotiates. A device that
just showed up is left to settle before switching, and a failed switch is
retried a few times before the device is given up on.
The gadget driver lets one opener at a time have /dev/usb_accessory, and a
blocked read kept it open after the session ended, even across a replug
and while Android froze the app, so the next accessory handshake failed.
Share one descriptor between the link threads, point it at /dev/null when
the session stops or ends, and interrupt a read in progress.
A USB accessory link never reports a host process that died: the tablet
kept showing the last frame. The host answers every ping, so after 5 s
without anything from it the client ends the session and reconnects.
@FacuM
FacuM changed the base branch from wifi-transport to main October 26, 2026 01:33
@FacuM
FacuM merged commit fe86316 into main Oct 26, 2026
10 checks passed
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.

1 participant