Skip to content

[flutter_tools] Parse single-space wireless ADB device output - #189431

Closed
Ram-Dawson wants to merge 2 commits into
flutter:masterfrom
Ram-Dawson:fix/adb-single-space-device-output
Closed

Ram-Dawson wants to merge 2 commits into
flutter:masterfrom
Ram-Dawson:fix/adb-single-space-device-output

Conversation

@Ram-Dawson

Copy link
Copy Markdown
Contributor

Description

Fixes Android device discovery when adb devices -l separates a long wireless
mDNS serial and its device state with a single space.

The existing parser accepts two spaces or a tab as the delimiter. Some ADB
output uses a single space instead, causing Flutter to report an unexpected
parsing failure and omit the wireless device.

This change adds a fallback parser for single-space delimiters when the serial
contains no spaces. The existing parser remains the preferred path so mDNS
conflict names containing spaces continue to be handled correctly.

Fixes #189430

Testing

  • Added a parser test for a single-space wireless mDNS serial.
  • Ran:
    flutter test packages/flutter_tools/test/general.shard/android/android_device_discovery_test.dart
  • Ran:
    flutter analyze packages/flutter_tools

Manual verification

Using the same wireless ADB device output:

adb-0123456789abcdef._adb-tls-connect._tcp device product:socrates model:22127RK46C device:socrates transport_id:1
  • Flutter 3.44.5 detects the device.
  • Unmodified Flutter master (3.47.0-1.0.pre-58, framework
    11faf0ac6ec69abcc7267e372a703f6d63d5b86f) reports an ADB parsing
    failure and omits the device.
  • This change detects the device as 22127RK46C (wireless).

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.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide].
  • 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.
  • 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 14, 2026 07:49
@Ram-Dawson
Ram-Dawson requested review from jesswrd and removed request for a team July 14, 2026 07:49
@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 14, 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 adds a fallback regular expression to correctly parse ADB devices with long mDNS serials separated by a single space, along with a corresponding test case. The review feedback suggests updating the comment for the new regex to use triple-slash documentation format (///) to align with the Flutter Style Guide.

Comment thread packages/flutter_tools/lib/src/android/android_device_discovery.dart Outdated
…y.dart

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@reidbaker
reidbaker requested review from mboetger and removed request for jesswrd July 14, 2026 21:23
@mboetger mboetger added the CICD Run CI/CD label Jul 14, 2026
@mboetger
mboetger requested a review from bkonyi July 14, 2026 22:18
@bkonyi

bkonyi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution @Ram-Dawson! However, a fix for this issue has already been landed: #189369.

@bkonyi bkonyi closed this Jul 14, 2026
navaronbracke pushed a commit to navaronbracke/flutter that referenced this pull request Jul 29, 2026
Fixes flutter#189972

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

## Summary

ADB formats long device-list rows as [`%-22s
%s`](https://android.googlesource.com/platform/packages/modules/adb/+/1cf2f017d312f73b3dc53bda85ef2610e35a80e9/transport.cpp#1410):
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 flutter#189369](flutter#189369) correctly
protects serials containing whitespace by requiring two spaces or a tab
before the state. [PR
flutter#189431](flutter#189431) proposed a
narrower one-space fallback for serials without whitespace and was
closed after flutter#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:

```text
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

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
@Ram-Dawson
Ram-Dawson deleted the fix/adb-single-space-device-output branch August 4, 2026 02:35
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.

[tool] Flutter fails to parse single-space wireless ADB device output

3 participants