Skip to content

fix(tool): parse ADB device lists by connection state - #189973

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
Ram-Dawson:fix/adb-device-list-state-boundary
Jul 29, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
Ram-Dawson:fix/adb-device-list-state-boundary

Conversation

@Ram-Dawson

Copy link
Copy Markdown
Contributor

Fixes #189972

Related to #189430 and #189369. This supersedes the narrower parser approach from closed PR #189431.

Summary

ADB formats long device-list rows as %-22s %s: the serial field has a minimum width, so a long wireless serial can be separated from its connection state by a single space. mDNS conflict suffixes can also introduce whitespace inside the serial.

PR #189369 correctly protects serials containing whitespace by requiring two spaces or a tab before the state. PR #189431 proposed a narrower one-space fallback for serials without whitespace and was closed after #189369 landed. The combined case has both an mDNS conflict suffix and a valid single-space state delimiter, so neither earlier rule accepts it.

This change parses the explicit known ADB connection-state field instead of inferring a boundary from whitespace width. The serial capture is greedy so state-like words and mDNS conflict suffixes remain part of the serial, and right-side padding from ADB's minimum-width field is removed.

Tests

Added regression coverage for:

  • ordinary single-space wireless mDNS serials;
  • mDNS conflict serials containing (2) with device and offline states;
  • every state currently recognized by Flutter Tools;
  • serials that contain state-like words; and
  • existing padded and tab-separated output forms.

Ran:

flutter test packages/flutter_tools/test/general.shard/android/android_device_discovery_test.dart
flutter analyze packages/flutter_tools

The device-discovery test file passed with 16 tests, and analysis reported no issues.

Real-device validation

After deleting bin/cache/flutter_tools.snapshot, unmodified upstream/master at 0ed149e63db1f68d2042063baf0a99d969ccd84b omitted the wireless Android device and reported an unexpected ADB parsing failure. With this patch, flutter devices -v listed the device with the complete mDNS conflict serial and successfully used that serial for adb -s ... shell getprop.

Scope

This PR changes only Flutter Tools parsing and its Android device-discovery tests. It does not change ADB, mDNS pairing, wireless transport behavior, or device-state handling after a row has been parsed.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@Ram-Dawson
Ram-Dawson requested a review from a team as a code owner July 24, 2026 07:44
@Ram-Dawson
Ram-Dawson requested review from mboetger and removed request for a team July 24, 2026 07:44
@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 Jul 24, 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 ADB device parsing regular expression in android_device_discovery.dart to use greedy matching for the device serial, followed by trimming trailing whitespace from the parsed device ID. This change allows correct parsing of long serials and serials containing whitespace (such as mDNS conflict suffixes). Extensive unit tests are added to cover these scenarios and various ADB states. Feedback was provided to update the regex documentation comments to use triple-slash (///) documentation comments in accordance with the Flutter Style Guide.

@bkonyi bkonyi 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.

Thanks for the follow up fix, and sorry for not getting back to you sooner! LGTM!

@mboetger mboetger added the CICD Run CI/CD label Jul 27, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 29, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 29, 2026
Merged via the queue into flutter:master with commit 9c98b26 Jul 29, 2026
24 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 29, 2026
@Ram-Dawson
Ram-Dawson deleted the fix/adb-device-list-state-boundary branch August 4, 2026 02:28
@bkonyi bkonyi added the cp: stable cherry pick this pull request to stable release candidate branch label Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: stable cherry pick this pull request to stable release candidate branch 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.

[tool] Flutter fails to parse mDNS conflict serials with a single-space state delimiter

3 participants