Use Xcode instruments to list devices (#10801)

Eliminates the dependency on idevice_id from libimobiledevice. Instead,
uses Xcode built-in functionality.
This commit is contained in:
Chris Bracken
2017-06-16 16:02:28 -07:00
committed by GitHub
parent 5344ffc790
commit 37bb5f1300
3 changed files with 47 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ class IOSDevices extends PollingDeviceDiscovery {
}
class IOSDevice extends Device {
IOSDevice(String id, { this.name }) : super(id) {
IOSDevice(String id, { this.name, String sdkVersion }) : _sdkVersion = sdkVersion, super(id) {
_installerPath = _checkForCommand('ideviceinstaller');
_iproxyPath = _checkForCommand('iproxy');
_pusherPath = _checkForCommand(
@@ -55,6 +55,8 @@ class IOSDevice extends Device {
String _iproxyPath;
String _pusherPath;
final String _sdkVersion;
@override
bool get supportsHotMode => true;
@@ -71,14 +73,30 @@ class IOSDevice extends Device {
@override
bool get supportsStartPaused => false;
// Physical device line format to be matched:
// My iPhone (10.3.2) [75b90e947c5f429fa67f3e9169fda0d89f0492f1]
//
// Other formats in output (desktop, simulator) to be ignored:
// my-mac-pro [2C10513E-4dA5-405C-8EF5-C44353DB3ADD]
// iPhone 6s (9.3) [F6CEE7CF-81EB-4448-81B4-1755288C7C11] (Simulator)
static final RegExp _deviceRegex = new RegExp(r'^(.*) +\((.*)\) +\[(.*)\]$');
static List<IOSDevice> getAttachedDevices() {
if (!iMobileDevice.isInstalled)
if (!xcode.isInstalled)
return <IOSDevice>[];
final List<IOSDevice> devices = <IOSDevice>[];
for (String id in iMobileDevice.getAttachedDeviceIDs()) {
final String name = iMobileDevice.getInfoForDevice(id, 'DeviceName');
devices.add(new IOSDevice(id, name: name));
final Iterable<String> deviceLines = xcode.getAvailableDevices()
.split('\n')
.map((String line) => line.trim());
for (String line in deviceLines) {
final Match match = _deviceRegex.firstMatch(line);
if (match != null) {
final String deviceName = match.group(1);
final String sdkVersion = match.group(2);
final String deviceID = match.group(3);
devices.add(new IOSDevice(deviceID, name: deviceName, sdkVersion: sdkVersion));
}
}
return devices;
}
@@ -311,11 +329,7 @@ class IOSDevice extends Device {
Future<TargetPlatform> get targetPlatform async => TargetPlatform.ios;
@override
Future<String> get sdkNameAndVersion async => 'iOS $_sdkVersion ($_buildVersion)';
String get _sdkVersion => iMobileDevice.getInfoForDevice(id, 'ProductVersion');
String get _buildVersion => iMobileDevice.getInfoForDevice(id, 'BuildVersion');
Future<String> get sdkNameAndVersion async => 'iOS $_sdkVersion';
@override
DeviceLogReader getLogReader({ApplicationPackage app}) {

View File

@@ -70,14 +70,6 @@ class IMobileDevice {
return await exitsHappyAsync(<String>['idevicename']);
}
List<String> getAttachedDeviceIDs() {
return runSync(<String>['idevice_id', '-l'])
.trim()
.split('\n')
.where((String line) => line.isNotEmpty)
.toList();
}
/// Returns the value associated with the specified `ideviceinfo` key for a device.
///
/// If either the specified key or device does not exist, returns the empty string.
@@ -165,6 +157,8 @@ class Xcode {
return _xcodeVersionCheckValid(_xcodeMajorVersion, _xcodeMinorVersion);
}
String getAvailableDevices() => runSync(<String>['/usr/bin/instruments', '-s', 'devices']);
}
bool _xcodeVersionCheckValid(int major, int minor) {