Skip to content

[flutter_tools] Parse wireless ADB serials that contain a space (mDNS conflict suffix)#187845

Closed
ishaquehassan wants to merge 2 commits into
flutter:masterfrom
ishaquehassan:fix/187092-adb-mdns-serial-space-parse
Closed

[flutter_tools] Parse wireless ADB serials that contain a space (mDNS conflict suffix)#187845
ishaquehassan wants to merge 2 commits into
flutter:masterfrom
ishaquehassan:fix/187092-adb-mdns-serial-space-parse

Conversation

@ishaquehassan

Copy link
Copy Markdown
Contributor

When adb resolves an mDNS name conflict for a wirelessly paired device it appends (2) to the instance name, producing a serial like adb-ZY22MGW35T-Z3uXXq (2)._adb-tls-connect._tcp. The device list parser in android_device_discovery.dart used RegExp(r'^(\S+)\s+(\S+)(.*)'), and \S+ stops at the first whitespace, so the serial was truncated to adb-ZY22MGW35T-Z3uXXq and the rest of the line was misread as the device state. The tool then ran adb -s with the truncated id, adb answered with device not found, and the device surfaced in flutter devices as Android null (API null) (unsupported).

This PR makes the serial capture lazy and anchors the state capture to the closed set of states adb devices -l can emit (device, offline, unauthorized, no permissions, bootloader, recovery, sideload, connecting, host), so everything before the state keyword is kept as the serial. The downstream switch on deviceState only special-cases unauthorized and offline, every other state still falls through default and is added as a device, so behavior for all previously parsed lines is unchanged. Header and daemon lines are already skipped before the regex runs, so the broader serial capture cannot pick them up.

Adds AndroidDevices preserves wireless serial containing space from mDNS name conflict to android_device_discovery_test.dart. It feeds the exact line from the issue and verifies the full serial is preserved, the model name parses, and the device is detected as wireless. The new test fails on master with the old regex and passes with this change. The full test file passes locally, 11/11.

Fixes #187092

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@ishaquehassan
ishaquehassan requested a review from a team as a code owner June 11, 2026 11:05
@ishaquehassan
ishaquehassan requested review from camsim99 and removed request for a team June 11, 2026 11:05
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Jun 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the regular expression used to parse adb devices output to correctly handle wireless serials containing spaces (such as mDNS name conflicts) and adds a unit test to verify this behavior. Feedback points out a potential edge case where a device serial containing a state keyword (e.g., "host") could cause incorrect regex matching, and suggests using a lookahead assertion to prevent this.

…arse correctly

The lazily matched serial could hand the state group a keyword that
appears as a standalone word inside the serial itself. The state now
must be followed by a key:value property list or the end of the line.
no permissions keeps its own branch because adb appends an explanation
to that state, such as (user in plugdev group); see [url], which would
fail the property lookahead.

Adds a test for a serial containing a state keyword and a regression
test for the no permissions line format.
@camsim99

Copy link
Copy Markdown
Contributor

Just FYI: #187943 seeks to address the same issue.

@ishaquehassan

Copy link
Copy Markdown
Contributor Author

Just FYI: #187943 seeks to address the same issue.

Thanks for the heads up. Looks like it takes the same approach, and since it's already with the team I'm happy to close this one in its favor. Feel free to grab any of the test cases here if they're useful, otherwise I'll close it out. Thanks!

@reidbaker
reidbaker requested review from a team, mboetger and reidbaker and removed request for camsim99 and reidbaker June 16, 2026 21:21
@jesswrd

jesswrd commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@bkonyi from android triage: this PR is similar to your PR: #187943. We will be closing this one out unless you want to keep this PR open.

@jesswrd jesswrd closed this Jun 23, 2026
@ishaquehassan
ishaquehassan deleted the fix/187092-adb-mdns-serial-space-parse branch June 24, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wireless ADB: device serial with space (mDNS conflict suffix " (2)") parsed incorrectly, device shown as "Android null (API null)"

3 participants