Sitelet https://github.com/flutter/flutter/pull/189369
Skip to content

[flutter_tools] Fix ADB device listing output parsing regression - #189369

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
bkonyi:fix-adb-device-regex
Jul 13, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
bkonyi:fix-adb-device-regex

Conversation

@bkonyi

@bkonyi bkonyi commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes a regression introduced in 629df07 where adb devices -l output containing non-key-value attributes (e.g. ABCDEFG device 20-30 product:mokey model:mokey device:mokey transport_id:1) caused regex lazy-matching to backtrack, incorrectly capturing ABCDEFG device into Group 1 (the device ID).

This change:

  • Updates _kDeviceRegex in android_device_discovery.dart to explicitly match known ADB device states (device, offline, unauthorized, no permissions, etc.) and require a column delimiter of at least two spaces or a tab ((?:\s{2,}|\t+)).
  • Adds regression unit test coverage in android_device_discovery_test.dart.

Related to #189274

Tests

  • Added regression unit test in android_device_discovery_test.dart for ADB output containing non-key-value attributes.
  • Added unit test for wireless serial names containing spaces and state keywords (my device (2)).

Fixes a regression introduced in 629df07
where `adb devices -l` output containing non-key-value attributes (e.g.
`ABCDEFG           device 20-30 product:mokey model:mokey device:mokey transport_id:1`)
caused regex lazy-matching to backtrack, incorrectly capturing `ABCDEFG           device`
into Group 1 (the device ID).

This change:
* Updates `_kDeviceRegex` in `android_device_discovery.dart` to explicitly match
  known ADB device states (`device`, `offline`, `unauthorized`, `no permissions`, etc.)
  and require a column delimiter of at least two spaces or a tab (`(?:\s{2,}|\t+)`).
* Adds regression unit test coverage in `android_device_discovery_test.dart`.

Related to flutter#189274

## Tests

* Added regression unit test in `android_device_discovery_test.dart` for ADB output containing non-key-value attributes.
* Added unit test for wireless serial names containing spaces and state keywords (`my device (2)`).
@bkonyi
bkonyi requested a review from jtmcdole July 13, 2026 15:44
@bkonyi
bkonyi requested a review from a team as a code owner July 13, 2026 15:44
@bkonyi
bkonyi requested review from gmackall and removed request for a team July 13, 2026 15:44
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 13, 2026
@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 13, 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 in AndroidDevices to prevent false positives by requiring a wider column separator and explicitly listing known ADB device states. It also adds corresponding unit tests to verify parsing behavior with extra attributes and serials containing spaces. The review feedback suggests adding the rescue state to the list of explicit ADB device states to support modern Android/ADB versions.

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>
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 13, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 13, 2026
Merged via the queue into flutter:master with commit 43ddd61 Jul 13, 2026
159 of 160 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 13, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jul 14, 2026
flutter/flutter@cf9e8af...846664b

2026-07-14 engine-flutter-autoroll@skia.org Roll Skia from dfcff99566c3 to 88954ef8f36d (1 revision) (flutter/flutter#189440)
2026-07-14 34465683+rkishan516@users.noreply.github.com refactor: remove material import from scrollable_semantics_test and selectable_region_context_menu_test (flutter/flutter#186611)
2026-07-14 engine-flutter-autoroll@skia.org Roll Skia from 3d1fc554f1a2 to dfcff99566c3 (17 revisions) (flutter/flutter#189428)
2026-07-14 engine-flutter-autoroll@skia.org Roll Dart SDK from 2c587df8f05a to 05bf153370c4 (5 revisions) (flutter/flutter#189426)
2026-07-14 nshahan@google.com [flutter_tools] Remove web hot reload flag (flutter/flutter#185994)
2026-07-14 chris@bracken.jp [iOS] Fix flaky keyboard animation test (flutter/flutter#189353)
2026-07-14 flar@google.com [Impeller] Playground expanded role (flutter/flutter#188889)
2026-07-14 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#189409)
2026-07-13 6655696+guidezpl@users.noreply.github.com Update lock-threads dependency to 6.0.2 (flutter/flutter#189053)
2026-07-13 49699333+dependabot[bot]@users.noreply.github.com Bump actions/labeler from 6.1.0 to 6.2.0 in the all-github-actions group (flutter/flutter#189396)
2026-07-13 116356835+AbdeMohlbi@users.noreply.github.com Remove  outdated todo about `analysis bug on Windows` and update condition to also perform `analysis on windows` (flutter/flutter#189283)
2026-07-13 ahmedsameha1@gmail.com Add more 0x0 size tests part 4 (flutter/flutter#185187)
2026-07-13 engine-flutter-autoroll@skia.org Roll Packages from 20928d5 to ad2eab1 (18 revisions) (flutter/flutter#189387)
2026-07-13 bkonyi@google.com [flutter_tools] Fix ADB device listing output parsing regression (flutter/flutter#189369)
2026-07-13 magder@google.com Stop running most Mac x64 builders that have Mac ARM equivalents on master (flutter/flutter#189301)
2026-07-13 magder@google.com Move a few benchmarks from x64 Intel Macs to ARM (flutter/flutter#189377)
2026-07-13 34871572+gmackall@users.noreply.github.com Add note that `hcpp` needs impeller (flutter/flutter#189382)
2026-07-13 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from vhIlDkWIy21IrlB9E... to oOETA0ISPouDt2xBo... (flutter/flutter#189349)
2026-07-13 68429735+Vonarian@users.noreply.github.com [flutter_tools] Respect mustMatchAppBuild on Windows native assets (flutter/flutter#186788)
2026-07-13 engine-flutter-autoroll@skia.org Roll Skia from 8bf65996caba to 3d1fc554f1a2 (2 revisions) (flutter/flutter#189350)
2026-07-13 engine-flutter-autoroll@skia.org Roll Dart SDK from 0fc1668c4af4 to 2c587df8f05a (9 revisions) (flutter/flutter#189351)
2026-07-13 1961493+harryterkelsen@users.noreply.github.com [web] Fall back to full CJK fonts for characters not covered by split slices (flutter/flutter#188890)
2026-07-13 magder@google.com Take Mac tool_integration_tests_* out of bringup (flutter/flutter#189368)
2026-07-13 dacoharkes@google.com [hooks] Roll record_use to 1.0 and unpin (flutter/flutter#189366)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC louisehsu@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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.
@bkonyi bkonyi added the cp: stable cherry pick this pull request to stable release candidate branch label Aug 18, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

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.

3 participants