Skip to content

Commit 3337391

Browse files
committed
fix(flutter_tools): parse adb device IDs with space and parenthesis suffixes (resolve flutter#180982)
1 parent 3e4e8b3 commit 3337391

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/android/android_device_discovery.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
111111
}
112112

113113
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
114-
static final _kDeviceRegex = RegExp(r'^(\S+)\s+(\S+)(.*)');
114+
static final _kDeviceRegex = RegExp(r'^(\S+(?:\s+\(\d+\))?)\s+(\S+)(.*)');
115115

116116
/// Parse the given `adb devices` output in [text], and fill out the given list
117117
/// of devices and possible device issue diagnostics. Either argument can be null,

‎packages/flutter_tools/test/general.shard/android/android_device_discovery_test.dart‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,38 @@ List of devices attached
193193
expect(devices.first.connectionInterface, DeviceConnectionInterface.wireless);
194194
});
195195

196+
testWithoutContext(
197+
'AndroidDevices can parse output for wireless devices with suffix (2)',
198+
() async {
199+
final androidDevices = AndroidDevices(
200+
userMessages: UserMessages(),
201+
androidWorkflow: androidWorkflow,
202+
androidSdk: FakeAndroidSdk(),
203+
logger: BufferLogger.test(),
204+
processManager: FakeProcessManager.list(<FakeCommand>[
205+
const FakeCommand(
206+
command: <String>['adb', 'devices', '-l'],
207+
stdout: '''
208+
List of devices attached
209+
adb-1234567._adb-tls-connect._tcp. (2) device product:razor model:Nexus_7 device:flo
210+
211+
''',
212+
),
213+
]),
214+
platform: FakePlatform(),
215+
fileSystem: MemoryFileSystem.test(),
216+
);
217+
218+
final List<Device> devices = await androidDevices.pollingGetDevices();
219+
220+
expect(devices, hasLength(1));
221+
expect(devices.first.id, 'adb-1234567._adb-tls-connect._tcp. (2)');
222+
expect(devices.first.name, 'Nexus 7');
223+
expect(devices.first.category, Category.mobile);
224+
expect(devices.first.connectionInterface, DeviceConnectionInterface.wireless);
225+
},
226+
);
227+
196228
testWithoutContext('AndroidDevices can parse output for emulators and short listings', () async {
197229
final androidDevices = AndroidDevices(
198230
userMessages: UserMessages(),

0 commit comments

Comments
 (0)