Handle adb error cases more gracefully

We now print a sensible message if we can't find `dart` or `adb`. Also, we
print a sensible message if the device isn't authorized.

Fixes #380
Fixes #358
This commit is contained in:
Adam Barth
2015-11-17 23:23:30 -08:00
parent b065036a0a
commit 3027497f85
2 changed files with 23 additions and 0 deletions

View File

@@ -505,6 +505,14 @@ class AndroidDevice extends Device {
static List<AndroidDevice> getAttachedDevices([AndroidDevice mockAndroid]) {
List<AndroidDevice> devices = [];
String adbPath = (mockAndroid != null) ? mockAndroid.adbPath : _getAdbPath();
try {
runCheckedSync([adbPath, 'version']);
} catch (e) {
_logging.severe('Unable to find adb. Is "adb" in your path?');
return devices;
}
List<String> output = runSync([adbPath, 'devices', '-l']).trim().split('\n');
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
@@ -514,6 +522,8 @@ class AndroidDevice extends Device {
// 0149947A0D01500C device usb:340787200X
RegExp deviceRegex2 = new RegExp(r'^(\S+)\s+device\s+\S+$');
RegExp unauthorizedRegex = new RegExp(r'^(\S+)\s+unauthorized$');
// Skip first line, which is always 'List of devices attached'.
for (String line in output.skip(1)) {
// Skip lines like:
@@ -539,6 +549,13 @@ class AndroidDevice extends Device {
Match match = deviceRegex2.firstMatch(line);
String deviceID = match[1];
devices.add(new AndroidDevice(id: deviceID));
} else if (unauthorizedRegex.hasMatch(line)) {
Match match = unauthorizedRegex.firstMatch(line);
String deviceID = match[1];
_logging.warning(
'Device $deviceID is not authorized.\n'
'You might need to check your device for an authorization dialog.'
);
} else {
_logging.warning(
'Unexpected failure parsing device information from adb output:\n'