Commit 26906240 authored by Devon Carew's avatar Devon Carew

fix an issue parsing adb devices (#3235)

parent 50461079
...@@ -473,27 +473,23 @@ List<AndroidDevice> getAdbDevices() { ...@@ -473,27 +473,23 @@ List<AndroidDevice> getAdbDevices() {
List<String> output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n'); List<String> output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n');
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper // 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
RegExp deviceRegex1 = new RegExp( RegExp deviceRegExLong = new RegExp(
r'^(\S+)\s+device\s+.*product:(\S+)\s+model:(\S+)\s+device:(\S+)$'); r'^(\S+)\s+device\s+.*product:(\S+)\s+model:(\S+)\s+device:(\S+)$');
// 0149947A0D01500C device usb:340787200X // 0149947A0D01500C device usb:340787200X
RegExp deviceRegex2 = new RegExp(r'^(\S+)\s+device\s+\S+$'); // emulator-5612 host features:shell_2
RegExp unauthorizedRegex = new RegExp(r'^(\S+)\s+unauthorized\s+\S+$'); RegExp deviceRegExShort = new RegExp(r'^(\S+)\s+(\S+)\s+\S+$');
RegExp offlineRegex = new RegExp(r'^(\S+)\s+offline\s+\S+$');
for (String line in output) {
// Skip the first line, which is always 'List of devices attached'. // Skip lines like: * daemon started successfully *
for (String line in output.skip(1)) {
// Skip lines like:
// * daemon not running. starting it now on port 5037 *
// * daemon started successfully *
if (line.startsWith('* daemon ')) if (line.startsWith('* daemon '))
continue; continue;
if (line.startsWith('List of devices')) if (line.startsWith('List of devices'))
continue; continue;
if (deviceRegex1.hasMatch(line)) { if (deviceRegExLong.hasMatch(line)) {
Match match = deviceRegex1.firstMatch(line); Match match = deviceRegExLong.firstMatch(line);
String deviceID = match[1]; String deviceID = match[1];
String productID = match[2]; String productID = match[2];
String modelID = match[3]; String modelID = match[3];
...@@ -508,21 +504,21 @@ List<AndroidDevice> getAdbDevices() { ...@@ -508,21 +504,21 @@ List<AndroidDevice> getAdbDevices() {
modelID: modelID, modelID: modelID,
deviceCodeName: deviceCodeName deviceCodeName: deviceCodeName
)); ));
} else if (deviceRegex2.hasMatch(line)) { } else if (deviceRegExShort.hasMatch(line)) {
Match match = deviceRegex2.firstMatch(line); Match match = deviceRegExShort.firstMatch(line);
String deviceID = match[1];
devices.add(new AndroidDevice(deviceID));
} else if (unauthorizedRegex.hasMatch(line)) {
Match match = unauthorizedRegex.firstMatch(line);
String deviceID = match[1];
printError(
'Device $deviceID is not authorized.\n'
'You might need to check your device for an authorization dialog.'
);
} else if (offlineRegex.hasMatch(line)) {
Match match = offlineRegex.firstMatch(line);
String deviceID = match[1]; String deviceID = match[1];
printError('Device $deviceID is offline.'); String deviceState = match[2];
if (deviceState == 'unauthorized') {
printError(
'Device $deviceID is not authorized.\n'
'You might need to check your device for an authorization dialog.'
);
} else if (deviceState == 'offline') {
printError('Device $deviceID is offline.');
} else {
devices.add(new AndroidDevice(deviceID));
}
} else { } else {
printError( printError(
'Unexpected failure parsing device information from adb output:\n' 'Unexpected failure parsing device information from adb output:\n'
...@@ -530,6 +526,7 @@ List<AndroidDevice> getAdbDevices() { ...@@ -530,6 +526,7 @@ List<AndroidDevice> getAdbDevices() {
'Please report a bug at https://github.com/flutter/flutter/issues/new'); 'Please report a bug at https://github.com/flutter/flutter/issues/new');
} }
} }
return devices; return devices;
} }
......
...@@ -8,8 +8,8 @@ import 'dart:io'; ...@@ -8,8 +8,8 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../artifacts.dart'; import '../artifacts.dart';
import '../build_configuration.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../build_configuration.dart';
import '../globals.dart'; import '../globals.dart';
import '../runner/flutter_command_runner.dart'; import '../runner/flutter_command_runner.dart';
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
import 'dart:io'; import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:mustache4dart/mustache4dart.dart' as mustache; import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as path;
import 'artifacts.dart'; import 'artifacts.dart';
import 'globals.dart'; import 'globals.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment