Commit 7acc9965 authored by Dan Rubel's avatar Dan Rubel Committed by GitHub

update Android device detection to handle adb error messages (#6521)

parent ca90656f
......@@ -629,18 +629,24 @@ final RegExp _kDeviceRegex = new RegExp(r'^(\S+)\s+(\S+)(.*)');
/// [mockAdbOutput] is public for testing.
List<AndroidDevice> getAdbDevices({ String mockAdbOutput }) {
List<AndroidDevice> devices = <AndroidDevice>[];
List<String> output;
String text;
if (mockAdbOutput == null) {
String adbPath = getAdbPath(androidSdk);
if (adbPath == null)
return <AndroidDevice>[];
output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n');
text = runSync(<String>[adbPath, 'devices', '-l']);
} else {
output = mockAdbOutput.trim().split('\n');
text = mockAdbOutput;
}
for (String line in output) {
// Check for error messages from adb
if (!text.contains('List of devices')) {
printError(text);
return <AndroidDevice>[];
}
for (String line in text.trim().split('\n')) {
// Skip lines like: * daemon started successfully *
if (line.startsWith('* daemon '))
continue;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:test/test.dart';
import 'src/context.dart';
......@@ -41,11 +42,25 @@ emulator-5612 host features:shell_2
testUsingContext('android n', () {
List<AndroidDevice> devices = getAdbDevices(mockAdbOutput: '''
List of devices attached
ZX1G22JJWR device usb:3-3 product:shamu model:Nexus_6 device:shamu features:cmd,shell_v2
''');
expect(devices, hasLength(1));
expect(devices.first.name, 'Nexus 6');
});
BufferLogger logger = new BufferLogger();
testUsingContext('adb error message', () {
List<AndroidDevice> devices = getAdbDevices(mockAdbOutput: '''
It appears you do not have 'Android SDK Platform-tools' installed.
Use the 'android' tool to install them:
android update sdk --no-ui --filter 'platform-tools'
''');
expect(devices, hasLength(0));
expect(logger.errorText, contains('you do not have'));
}, overrides: <Type, dynamic>{
Logger : logger,
});
});
group('parseAdbDeviceProperties', () {
......
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