[ios] improve test device naming
The new name format is "DEVICE_TYPE_NAME (Flutter)". For example:
iPhone 6 (Flutter)
iPhone 6s Plus (Flutter)
The names are taken from `xcrun simctl list --json devicetypes`.
Fixes #2682
diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart
index 9623642..fe02d31 100644
--- a/packages/flutter_tools/lib/src/ios/simulators.dart
+++ b/packages/flutter_tools/lib/src/ios/simulators.dart
@@ -22,7 +22,7 @@
const String _xcrunPath = '/usr/bin/xcrun';
/// Test device created by Flutter when no other device is available.
-const String _kFlutterTestDevice = 'flutter.test.device';
+const String _kFlutterTestDeviceSuffix = '(Flutter)';
class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators');
@@ -97,7 +97,7 @@
}
SimDevice _createTestDevice() {
- String deviceType = _findSuitableDeviceType();
+ SimDeviceType deviceType = _findSuitableDeviceType();
if (deviceType == null) {
return null;
}
@@ -109,18 +109,19 @@
// Delete any old test devices
getDevices()
- .where((SimDevice d) => d.name == _kFlutterTestDevice)
+ .where((SimDevice d) => d.name.endsWith(_kFlutterTestDeviceSuffix))
.forEach(_deleteDevice);
// Create new device
- List<String> args = [_xcrunPath, 'simctl', 'create', _kFlutterTestDevice, deviceType, runtime];
+ String deviceName = '${deviceType.name} $_kFlutterTestDeviceSuffix';
+ List<String> args = [_xcrunPath, 'simctl', 'create', deviceName, deviceType.identifier, runtime];
printTrace(args.join(' '));
runCheckedSync(args);
- return getDevices().firstWhere((SimDevice d) => d.name == _kFlutterTestDevice);
+ return getDevices().firstWhere((SimDevice d) => d.name == deviceName);
}
- String _findSuitableDeviceType() {
+ SimDeviceType _findSuitableDeviceType() {
List<Map<String, dynamic>> allTypes = _list(SimControlListSection.devicetypes);
List<Map<String, dynamic>> usableTypes = allTypes
.where((Map<String, dynamic> info) => info['name'].startsWith('iPhone'))
@@ -136,7 +137,10 @@
);
}
- return usableTypes.first['identifier'];
+ return new SimDeviceType(
+ usableTypes.first['name'],
+ usableTypes.first['identifier']
+ );
}
String _findSuitableRuntime() {
@@ -300,6 +304,30 @@
static const SimControlListSection pairs = const SimControlListSection._('pairs');
}
+/// A simulated device type.
+///
+/// Simulated device types can be listed using the command
+/// `xcrun simctl list devicetypes`.
+class SimDeviceType {
+ SimDeviceType(this.name, this.identifier);
+
+ /// The name of the device type.
+ ///
+ /// Examples:
+ ///
+ /// "iPhone 6s"
+ /// "iPhone 6 Plus"
+ final String name;
+
+ /// The identifier of the device type.
+ ///
+ /// Examples:
+ ///
+ /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"
+ /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"
+ final String identifier;
+}
+
class SimDevice {
SimDevice(this.category, this.data);