Basic sky_tools list command, Android implementation, and test.
This commit is contained in:
@@ -60,13 +60,60 @@ class AndroidDevice extends _Device {
|
||||
static const String className = 'AndroidDevice';
|
||||
static final String defaultDeviceID = 'default';
|
||||
|
||||
String productID;
|
||||
String modelID;
|
||||
String deviceCodeName;
|
||||
|
||||
String _adbPath;
|
||||
String get adbPath => _adbPath;
|
||||
bool _hasAdb = false;
|
||||
bool _hasValidAndroid = false;
|
||||
|
||||
factory AndroidDevice([String id = null]) {
|
||||
return new _Device(className, id);
|
||||
factory AndroidDevice(
|
||||
{String id: null,
|
||||
String productID: null,
|
||||
String modelID: null,
|
||||
String deviceCodeName: null}) {
|
||||
AndroidDevice device = new _Device(className, id);
|
||||
device.productID = productID;
|
||||
device.modelID = modelID;
|
||||
device.deviceCodeName = deviceCodeName;
|
||||
return device;
|
||||
}
|
||||
|
||||
/// mockAndroid argument is only to facilitate testing with mocks, so that
|
||||
/// we don't have to rely on the test setup having adb available to it.
|
||||
static List<AndroidDevice> getAttachedDevices([AndroidDevice mockAndroid]) {
|
||||
List<AndroidDevice> devices = [];
|
||||
String adbPath = _getAdbPath();
|
||||
if (mockAndroid != null) {
|
||||
adbPath = mockAndroid.adbPath;
|
||||
}
|
||||
List<String> output =
|
||||
runSync([adbPath, 'devices', '-l']).trim().split('\n');
|
||||
RegExp deviceInfo = new RegExp(
|
||||
r'^(\S+)\s+device\s+\S+\s+product:(\S+)\s+model:(\S+)\s+device:(\S+)$');
|
||||
// Skip first line, which is always 'List of devices attached'.
|
||||
for (String line in output.skip(1)) {
|
||||
Match match = deviceInfo.firstMatch(line);
|
||||
if (match != null) {
|
||||
String deviceID = match[1];
|
||||
String productID = match[2];
|
||||
String modelID = match[3];
|
||||
String deviceCodeName = match[4];
|
||||
|
||||
devices.add(new AndroidDevice(
|
||||
id: deviceID,
|
||||
productID: productID,
|
||||
modelID: modelID,
|
||||
deviceCodeName: deviceCodeName));
|
||||
} else {
|
||||
_logging.warning('Unexpected failure parsing device information '
|
||||
'from adb output:\n$line\n'
|
||||
'Please report a bug at http://flutter.io/');
|
||||
}
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
AndroidDevice._(id) : super._(id) {
|
||||
@@ -83,7 +130,7 @@ class AndroidDevice extends _Device {
|
||||
}
|
||||
}
|
||||
|
||||
String _getAdbPath() {
|
||||
static String _getAdbPath() {
|
||||
if (Platform.environment.containsKey('ANDROID_HOME')) {
|
||||
String androidHomeDir = Platform.environment['ANDROID_HOME'];
|
||||
String adbPath1 =
|
||||
|
||||
45
packages/flutter_tools/lib/src/list.dart
Normal file
45
packages/flutter_tools/lib/src/list.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
library sky_tools.list;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:sky_tools/src/device.dart';
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.list');
|
||||
|
||||
class ListCommand extends Command {
|
||||
final name = 'list';
|
||||
final description = 'List all connected devices.';
|
||||
AndroidDevice android;
|
||||
|
||||
ListCommand([this.android]) {
|
||||
argParser.addFlag('details',
|
||||
abbr: 'd',
|
||||
negatable: false,
|
||||
help: 'Log additional details about attached devices.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> run() async {
|
||||
bool details = argResults['details'];
|
||||
if (details) {
|
||||
print('Android Devices:');
|
||||
}
|
||||
for (AndroidDevice device in AndroidDevice.getAttachedDevices(android)) {
|
||||
if (details) {
|
||||
print('${device.id}\t'
|
||||
'${device.modelID}\t'
|
||||
'${device.productID}\t'
|
||||
'${device.deviceCodeName}');
|
||||
} else {
|
||||
print(device.id);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class TraceCommand extends Command {
|
||||
if (tracePath == null) {
|
||||
_logging.warning('No trace file saved.');
|
||||
} else {
|
||||
_logging.warning('Trace file saved to $tracePath');
|
||||
print('Trace file saved to $tracePath');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user