Commit 0b49d81c authored by Dan Rubel's avatar Dan Rubel Committed by GitHub

flutter devices/doctor report Android (and iOS) version (#6545)

* refactor device descriptions method - easier to add columns
* show device SDK version
parent 04e14f8b
...@@ -115,6 +115,13 @@ class AndroidDevice extends Device { ...@@ -115,6 +115,13 @@ class AndroidDevice extends Device {
return _platform; return _platform;
} }
@override
String get sdkNameAndVersion => 'Android $_sdkVersion (API $_apiVersion)';
String get _sdkVersion => _getProperty('ro.build.version.release');
String get _apiVersion => _getProperty('ro.build.version.sdk');
_AdbLogReader _logReader; _AdbLogReader _logReader;
_AndroidDevicePortForwarder _portForwarder; _AndroidDevicePortForwarder _portForwarder;
......
...@@ -163,6 +163,8 @@ abstract class Device { ...@@ -163,6 +163,8 @@ abstract class Device {
TargetPlatform get platform; TargetPlatform get platform;
String get sdkNameAndVersion;
/// Get the log reader for this device. /// Get the log reader for this device.
DeviceLogReader get logReader; DeviceLogReader get logReader;
...@@ -239,24 +241,36 @@ abstract class Device { ...@@ -239,24 +241,36 @@ abstract class Device {
String toString() => name; String toString() => name;
static Iterable<String> descriptions(List<Device> devices) { static Iterable<String> descriptions(List<Device> devices) {
int nameWidth = 0; if (devices.isEmpty)
int idWidth = 0; return <String>[];
// Extract device information
List<List<String>> table = <List<String>>[];
for (Device device in devices) { for (Device device in devices) {
nameWidth = math.max(nameWidth, device.name.length);
idWidth = math.max(idWidth, device.id.length);
}
return devices.map((Device device) {
String supportIndicator = device.isSupported() ? '' : ' (unsupported)'; String supportIndicator = device.isSupported() ? '' : ' (unsupported)';
if (device.isLocalEmulator) { if (device.isLocalEmulator) {
String type = device.platform == TargetPlatform.ios ? 'simulator' : 'emulator'; String type = device.platform == TargetPlatform.ios ? 'simulator' : 'emulator';
supportIndicator += ' ($type)'; supportIndicator += ' ($type)';
} }
return '${device.name.padRight(nameWidth)} • ' table.add(<String>[
'${device.id.padRight(idWidth)} • ' device.name,
'${getNameForTargetPlatform(device.platform)}$supportIndicator'; device.id,
}); '${getNameForTargetPlatform(device.platform)}',
'${device.sdkNameAndVersion}$supportIndicator',
]);
}
// Calculate column widths
List<int> indices = new List<int>.generate(table[0].length - 1, (int i) => i);
List<int> widths = indices.map((int i) => 0).toList();
for (List<String> row in table) {
widths = indices.map((int i) => math.max(widths[i], row[i].length)).toList();
}
// Join columns into lines of text
return table.map((List<String> row) =>
indices.map((int i) => row[i].padRight(widths[i])).join(' • ') +
' • ${row.last}');
} }
static void printDevices(List<Device> devices) { static void printDevices(List<Device> devices) {
......
...@@ -89,7 +89,7 @@ class IOSDevice extends Device { ...@@ -89,7 +89,7 @@ class IOSDevice extends Device {
List<IOSDevice> devices = <IOSDevice>[]; List<IOSDevice> devices = <IOSDevice>[];
for (String id in _getAttachedDeviceIDs(mockIOS)) { for (String id in _getAttachedDeviceIDs(mockIOS)) {
String name = _getDeviceName(id, mockIOS); String name = IOSDevice._getDeviceInfo(id, 'DeviceName', mockIOS);
devices.add(new IOSDevice(id, name: name)); devices.add(new IOSDevice(id, name: name));
} }
return devices; return devices;
...@@ -105,11 +105,11 @@ class IOSDevice extends Device { ...@@ -105,11 +105,11 @@ class IOSDevice extends Device {
} }
} }
static String _getDeviceName(String deviceID, [IOSDevice mockIOS]) { static String _getDeviceInfo(String deviceID, String infoKey, [IOSDevice mockIOS]) {
String informerPath = (mockIOS != null) String informerPath = (mockIOS != null)
? mockIOS.informerPath ? mockIOS.informerPath
: _checkForCommand('ideviceinfo'); : _checkForCommand('ideviceinfo');
return runSync(<String>[informerPath, '-k', 'DeviceName', '-u', deviceID]).trim(); return runSync(<String>[informerPath, '-k', infoKey, '-u', deviceID]).trim();
} }
static final Map<String, String> _commandMap = <String, String>{}; static final Map<String, String> _commandMap = <String, String>{};
...@@ -369,6 +369,13 @@ class IOSDevice extends Device { ...@@ -369,6 +369,13 @@ class IOSDevice extends Device {
@override @override
TargetPlatform get platform => TargetPlatform.ios; TargetPlatform get platform => TargetPlatform.ios;
@override
String get sdkNameAndVersion => 'iOS $_sdkVersion ($_buildVersion)';
String get _sdkVersion => _getDeviceInfo(id, 'ProductVersion');
String get _buildVersion => _getDeviceInfo(id, 'BuildVersion');
@override @override
DeviceLogReader get logReader { DeviceLogReader get logReader {
if (_logReader == null) if (_logReader == null)
......
...@@ -46,7 +46,7 @@ class IOSSimulatorUtils { ...@@ -46,7 +46,7 @@ class IOSSimulatorUtils {
return <IOSSimulator>[]; return <IOSSimulator>[];
return SimControl.instance.getConnectedDevices().map((SimDevice device) { return SimControl.instance.getConnectedDevices().map((SimDevice device) {
return new IOSSimulator(device.udid, name: device.name); return new IOSSimulator(device.udid, name: device.name, category: device.category);
}).toList(); }).toList();
} }
} }
...@@ -302,11 +302,13 @@ class SimDevice { ...@@ -302,11 +302,13 @@ class SimDevice {
} }
class IOSSimulator extends Device { class IOSSimulator extends Device {
IOSSimulator(String id, { this.name }) : super(id); IOSSimulator(String id, { this.name, this.category }) : super(id);
@override @override
final String name; final String name;
final String category;
@override @override
bool get isLocalEmulator => true; bool get isLocalEmulator => true;
...@@ -557,6 +559,9 @@ class IOSSimulator extends Device { ...@@ -557,6 +559,9 @@ class IOSSimulator extends Device {
@override @override
TargetPlatform get platform => TargetPlatform.ios; TargetPlatform get platform => TargetPlatform.ios;
@override
String get sdkNameAndVersion => category;
@override @override
DeviceLogReader get logReader { DeviceLogReader get logReader {
if (_logReader == null) if (_logReader == null)
......
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