Repository navigation
[stable] fix(tool): parse ADB device lists by connection state - #191296
Conversation
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 please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request updates the regular expression used to parse the output of adb devices -l in android_device_discovery.dart to greedily match the device serial number. This allows the parser to handle serials that are 22 characters or longer followed by a single space, as well as serials containing whitespace. The parsed device ID is trimmed of trailing whitespace, and several unit tests are added to verify the changes across various ADB states and serial formats. There are no review comments, so no feedback is provided.
1926f75
into
flutter:flutter-3.47-candidate.0
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
#189972
Impact Description:
ADB formats long device list rows using$\ge 22$ chars) or wireless serials with mDNS conflict suffixes (such as
%-22s %s(minimum width 22 characters). For long wireless device serials ((2)), ADB outputs only a single space before the connection state. The previous parser required two or more spaces before the state, causingflutter_toolsto fail parsing these rows, report unexpected ADB parsing errors, and omit connected wireless Android devices fromflutter devicesand IDEs.Changelog Description:
[flutter/189972] Fix ADB device list parsing for long wireless mDNS serials separated from state by a single space.
Workaround:
Use wired USB debugging or reconnect wireless debugging.
Risk:
Test Coverage:
Validation Steps:
(2).flutter devices -v.packages/flutter_tools/test/general.shard/android/android_device_discovery_test.dart.