Commit 60755f6d authored by Devon Carew's avatar Devon Carew

fix an issue parsing adb output (#3629)

parent 99114cd4
...@@ -55,8 +55,12 @@ class AndroidDevice extends Device { ...@@ -55,8 +55,12 @@ class AndroidDevice extends Device {
bool get isLocalEmulator { bool get isLocalEmulator {
if (_isLocalEmulator == null) { if (_isLocalEmulator == null) {
// http://developer.android.com/ndk/guides/abis.html (x86, armeabi-v7a, ...) // http://developer.android.com/ndk/guides/abis.html (x86, armeabi-v7a, ...)
try {
String value = runCheckedSync(adbCommandForDevice(['shell', 'getprop', 'ro.product.cpu.abi'])); String value = runCheckedSync(adbCommandForDevice(['shell', 'getprop', 'ro.product.cpu.abi']));
_isLocalEmulator = value.startsWith('x86'); _isLocalEmulator = value.startsWith('x86');
} catch (error) {
_isLocalEmulator = false;
}
} }
return _isLocalEmulator; return _isLocalEmulator;
...@@ -390,14 +394,21 @@ class AndroidDevice extends Device { ...@@ -390,14 +394,21 @@ class AndroidDevice extends Device {
} }
} }
List<AndroidDevice> getAdbDevices() { /// Return the list of connected ADB devices.
///
/// [mockAdbOutput] is public for testing.
List<AndroidDevice> getAdbDevices({ String mockAdbOutput }) {
List<AndroidDevice> devices = [];
List<String> output;
if (mockAdbOutput == null) {
String adbPath = getAdbPath(androidSdk); String adbPath = getAdbPath(androidSdk);
if (adbPath == null) if (adbPath == null)
return <AndroidDevice>[]; return <AndroidDevice>[];
output = runSync(<String>[adbPath, 'devices', '-l']).trim().split('\n');
List<AndroidDevice> devices = []; } else {
output = mockAdbOutput.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 deviceRegExLong = new RegExp( RegExp deviceRegExLong = new RegExp(
...@@ -445,7 +456,7 @@ List<AndroidDevice> getAdbDevices() { ...@@ -445,7 +456,7 @@ List<AndroidDevice> getAdbDevices() {
} else if (deviceState == 'offline') { } else if (deviceState == 'offline') {
printError('Device $deviceID is offline.'); printError('Device $deviceID is offline.');
} else { } else {
devices.add(new AndroidDevice(deviceID)); devices.add(new AndroidDevice(deviceID, modelID: deviceID));
} }
} else { } else {
printError( printError(
......
...@@ -15,4 +15,28 @@ void main() { ...@@ -15,4 +15,28 @@ void main() {
expect(device.id, equals(deviceId)); expect(device.id, equals(deviceId));
}); });
}); });
group('getAdbDevices', () {
testUsingContext('physical devices', () {
List<AndroidDevice> devices = getAdbDevices(mockAdbOutput: '''
List of devices attached
05a02bac device usb:336592896X product:razor model:Nexus_7 device:flo
''');
expect(devices, hasLength(1));
expect(devices.first.name, 'Nexus 7');
});
testUsingContext('emulators and short listings', () {
List<AndroidDevice> devices = getAdbDevices(mockAdbOutput: '''
List of devices attached
localhost:36790 device
0149947A0D01500C device usb:340787200X
emulator-5612 host features:shell_2
''');
expect(devices, hasLength(3));
expect(devices.first.name, 'localhost:36790');
});
});
} }
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