Skip to content

fix: recognize wireless-debugging devices adb connects to over mDNS - #43

Merged
Jeomon merged 1 commit into
CursorTouch:masterfrom
aftabkh4n:fix/mdns-wireless-device-detection
Nov 6, 2026
Merged

Jeomon merged 1 commit into
CursorTouch:masterfrom
aftabkh4n:fix/mdns-wireless-device-detection

Conversation

@aftabkh4n

Copy link
Copy Markdown
Contributor

Problem

When a phone is paired for wireless debugging, adb connects to it automatically over mDNS. adb then names the device after its mDNS service instead of host:port:

adb-fc29a614-i3szUK._adb-tls-connect._tcp device product:PongEEA model:A065 device:Pong transport_id:74

(This line is from Genymobile/scrcpy#6248. scrcpy hit the same two problems.)

1. USB vs Wi-Fi selection. pick_device decides by whether the serial contains a colon. As a result:

  • With only a wireless phone attached, --connection wifi reports "No ready device over wifi".
  • --connection usb picks the wireless phone, even when a phone plugged in by cable is also attached but listed after it.

2. Serials with a space. When an mDNS name repeats, adb appends (2), e.g. adb-AEORQMSAOWNQ-N7Ger8 (2)._adb-tls-connect._tcp (also from that scrcpy issue). list_devices splits the line on whitespace. That cuts the serial to adb-AEORQMSAOWNQ-N7Ger8 and reads (2)._adb-tls-connect._tcp as the state. A ready phone is therefore listed as unknown, under a serial adb doesn't recognize.

Change

  • mobile/service.py: add _is_network(). A device counts as a network device when its serial contains : or adb-tls-connect. This is the rule scrcpy adopted in sc_adb_device_get_type(). pick_device uses it for both wifi and usb. auto is unchanged.
  • adb/core.py: list_devices now finds the one-word state with a regex built from DeviceState, instead of assuming the state is the second field. The serial is everything before the state. Lines that don't match keep the old split, e.g. no permissions (...), whose state isn't one word, so that case still reads as UNKNOWN.

Testing

  • uv run pytest: 583 passed, 21 skipped. ruff check and ruff format --check are clean.
  • New tests:
    • TestListDevices: an mDNS serial, a serial with a space next to a USB phone, and no permissions (...) staying UNKNOWN.
    • TestPickDevice: wifi takes an mDNS device, and usb skips it.
  • Three of the new tests fail on master and pass with this change. The other two cover behavior that already worked and must stay that way.
Case Before After
adb-… (2)._adb-tls-connect._tcp device … serial cut short, state unknown full serial, state device
only an mDNS phone, --connection wifi none found the phone
only an mDNS phone, --connection usb the wireless phone none
mDNS phone listed before a USB phone, --connection usb the wireless phone the USB phone

I don't have a wireless-debugging setup here. The adb devices -l lines come from real reports in the scrcpy issue above.

A phone paired for wireless debugging is connected by adb itself over
mDNS, and adb names it after its service rather than host:port:
"adb-RF8M12345-AbC9Zz._adb-tls-connect._tcp". Two things went wrong:

- pick_device told Wi-Fi from USB by a colon in the serial, so with
  --connection wifi such a phone was not found, and --connection usb
  took it as a USB device, even ahead of a phone plugged in by cable.
  It now also counts a serial naming "adb-tls-connect" as a network
  device, the rule scrcpy adopted for the same problem
  (Genymobile/scrcpy#6248).
- adb appends " (2)" when an mDNS name repeats, so the serial can
  contain a space. list_devices split the line on whitespace, which cut
  the serial short and read "(2)..." as the state, so a ready phone was
  listed as "unknown" under a serial adb does not know. It now finds
  the one-word state instead of assuming it is the second field, and
  keeps the old split for states that are not one word, such as
  "no permissions (...)".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014TonJ1geSd97oAtSBZofUK
@Jeomon
Jeomon merged commit 2e0a01c into CursorTouch:master Nov 6, 2026
@Jeomon

Jeomon commented Nov 6, 2026

Copy link
Copy Markdown
Member

Thanks

Jeomon pushed a commit that referenced this pull request Nov 22, 2026
A phone paired for wireless debugging is connected by adb itself over
mDNS and listed under its service name, e.g.
"adb-RF8M12345-AbC9Zz._adb-tls-connect._tcp". #43 taught pick_device
that such a serial is a network device, but the explicit Wi-Fi path did
not know it: with --connection wifi --device <that serial>,
ANDROID_MCP_CONNECTION=wifi + ANDROID_MCP_DEVICE, or --wifi <serial>,
normalize_wifi_address appended ":5555" and connect_wifi ran
`adb connect adb-…_tcp:5555`, which fails to resolve the name as a
host. Even past that, the ":5555" serial no longer matched the device
adb lists, so the attached, ready phone could never be selected.

normalize_wifi_address now leaves an mDNS serial as it is, and
connect_wifi selects it without `adb connect`, since adb already holds
the connection. Host and host:port addresses are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014TonJ1geSd97oAtSBZofUK
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