Commit 3027497f authored by Adam Barth's avatar Adam Barth

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
parent b065036a
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
export FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}"))
FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
......@@ -20,6 +22,8 @@ if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"`
echo -n $REVISION > "$STAMP_PATH"
fi
set +e
$DART "$SNAPSHOT_PATH" "$@"
# The VM exits with code 253 if the snapshot version is out-of-date.
......@@ -29,5 +33,7 @@ if [ $EXIT_CODE != 253 ]; then
exit $EXIT_CODE
fi
set -e
$DART --snapshot="$SNAPSHOT_PATH" --package-root="$FLUTTER_TOOLS_DIR/packages" "$SCRIPT_PATH"
$DART "$SNAPSHOT_PATH" "$@"
......@@ -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'
......
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