Skip to content

fix(adb): redial the port that actually worked, not always 5555 - #7

Open
X-Ryl669 wants to merge 1 commit into
zoir-dev:mainfrom
X-Ryl669:fix/adb-redial-remember-port
Open

fix(adb): redial the port that actually worked, not always 5555#7
X-Ryl669 wants to merge 1 commit into
zoir-dev:mainfrom
X-Ryl669:fix/adb-redial-remember-port

Conversation

@X-Ryl669

Copy link
Copy Markdown

When using Universal control feature, the current status is to enable adb USB debugging (then WIFI debugging). However, leaving USB debugging enabled usually stops DRM and banking app from running.

Here's the attempt from Claude to fix it:

redial hardcoded 5555, which is where adb tcpip always lands — but Android 11+ Wireless debugging picks a RANDOM port and keeps it while the toggle stays on. That matters beyond tidiness: Wireless debugging is the only way to run adb with USB debugging off, and plenty of banking/DRM apps refuse to start while Settings.Global.adb_enabled is

  1. So the configuration a user needs in order to keep those apps working is exactly the one where redial could never reconnect: after a Wi-Fi roam, a suspend or an adb kill-server, scan_transports finds nothing, the redial knocks on a port nobody is listening on, and Universal Control arms with no cursor ever reaching the phone — silent on both screens.

scan_transports now notes the port of whatever network transport is attached (rsplit(':'), so the bracketed IPv6 form works too) and persists it to ~/.cache/vortex/last_adb_port, mirroring how lan.rs caches the peer IP — the phone keeps that port across our own restarts, so memory alone would forget it exactly when it is needed.

Redial then tries the remembered port first and 5555 second, so:

  • a Wireless-debugging port is reconnected without a cable;
  • a stale entry (phone re-paired, or moved back to adb tcpip) still recovers on the same pass rather than needing a manual reconnect;
  • and a success on either port becomes the next first guess, so the cache self-corrects. The 5555 fallback is skipped when it IS the remembered port — each miss costs about a second of adb connect blocking.

Verified end-to-end by planting a bogus port and dropping the transport: tried :39999, fell back to :5555, reconnected, and rewrote the cache. redial_port_order is split out as the pure half so the ordering is covered by a unit test without a global or the filesystem in the way.

`redial` hardcoded 5555, which is where `adb tcpip` always lands — but
Android 11+ *Wireless debugging* picks a RANDOM port and keeps it while
the toggle stays on. That matters beyond tidiness: Wireless debugging is
the only way to run adb with **USB debugging off**, and plenty of
banking/DRM apps refuse to start while `Settings.Global.adb_enabled` is
1. So the configuration a user needs in order to keep those apps working
is exactly the one where redial could never reconnect: after a Wi-Fi
roam, a suspend or an `adb kill-server`, `scan_transports` finds nothing,
the redial knocks on a port nobody is listening on, and Universal Control
arms with no cursor ever reaching the phone — silent on both screens.

`scan_transports` now notes the port of whatever network transport is
attached (`rsplit(':')`, so the bracketed IPv6 form works too) and
persists it to ~/.cache/vortex/last_adb_port, mirroring how lan.rs caches
the peer IP — the phone keeps that port across our own restarts, so
memory alone would forget it exactly when it is needed.

Redial then tries the remembered port first and 5555 second, so:
  - a Wireless-debugging port is reconnected without a cable;
  - a stale entry (phone re-paired, or moved back to `adb tcpip`) still
    recovers on the same pass rather than needing a manual reconnect;
  - and a success on either port becomes the next first guess, so the
    cache self-corrects.
The 5555 fallback is skipped when it IS the remembered port — each miss
costs about a second of `adb connect` blocking.

Verified end-to-end by planting a bogus port and dropping the transport:
tried :39999, fell back to :5555, reconnected, and rewrote the cache.
`redial_port_order` is split out as the pure half so the ordering is
covered by a unit test without a global or the filesystem in the way.
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.

2 participants