Skip to content

Commit 194c88b

Browse files
committed
Merge pull request flutter#2702 from yjbanov/better-device-name
[ios] improve test device naming
2 parents 4453301 + 225686b commit 194c88b

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

packages/flutter_tools/lib/src/ios/simulators.dart

+35-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'mac.dart';
2222
const String _xcrunPath = '/usr/bin/xcrun';
2323

2424
/// Test device created by Flutter when no other device is available.
25-
const String _kFlutterTestDevice = 'flutter.test.device';
25+
const String _kFlutterTestDeviceSuffix = '(Flutter)';
2626

2727
class IOSSimulators extends PollingDeviceDiscovery {
2828
IOSSimulators() : super('IOSSimulators');
@@ -97,7 +97,7 @@ class SimControl {
9797
}
9898

9999
SimDevice _createTestDevice() {
100-
String deviceType = _findSuitableDeviceType();
100+
SimDeviceType deviceType = _findSuitableDeviceType();
101101
if (deviceType == null) {
102102
return null;
103103
}
@@ -109,18 +109,19 @@ class SimControl {
109109

110110
// Delete any old test devices
111111
getDevices()
112-
.where((SimDevice d) => d.name == _kFlutterTestDevice)
112+
.where((SimDevice d) => d.name.endsWith(_kFlutterTestDeviceSuffix))
113113
.forEach(_deleteDevice);
114114

115115
// Create new device
116-
List<String> args = [_xcrunPath, 'simctl', 'create', _kFlutterTestDevice, deviceType, runtime];
116+
String deviceName = '${deviceType.name} $_kFlutterTestDeviceSuffix';
117+
List<String> args = [_xcrunPath, 'simctl', 'create', deviceName, deviceType.identifier, runtime];
117118
printTrace(args.join(' '));
118119
runCheckedSync(args);
119120

120-
return getDevices().firstWhere((SimDevice d) => d.name == _kFlutterTestDevice);
121+
return getDevices().firstWhere((SimDevice d) => d.name == deviceName);
121122
}
122123

123-
String _findSuitableDeviceType() {
124+
SimDeviceType _findSuitableDeviceType() {
124125
List<Map<String, dynamic>> allTypes = _list(SimControlListSection.devicetypes);
125126
List<Map<String, dynamic>> usableTypes = allTypes
126127
.where((Map<String, dynamic> info) => info['name'].startsWith('iPhone'))
@@ -136,7 +137,10 @@ class SimControl {
136137
);
137138
}
138139

139-
return usableTypes.first['identifier'];
140+
return new SimDeviceType(
141+
usableTypes.first['name'],
142+
usableTypes.first['identifier']
143+
);
140144
}
141145

142146
String _findSuitableRuntime() {
@@ -300,6 +304,30 @@ class SimControlListSection {
300304
static const SimControlListSection pairs = const SimControlListSection._('pairs');
301305
}
302306

307+
/// A simulated device type.
308+
///
309+
/// Simulated device types can be listed using the command
310+
/// `xcrun simctl list devicetypes`.
311+
class SimDeviceType {
312+
SimDeviceType(this.name, this.identifier);
313+
314+
/// The name of the device type.
315+
///
316+
/// Examples:
317+
///
318+
/// "iPhone 6s"
319+
/// "iPhone 6 Plus"
320+
final String name;
321+
322+
/// The identifier of the device type.
323+
///
324+
/// Examples:
325+
///
326+
/// "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"
327+
/// "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"
328+
final String identifier;
329+
}
330+
303331
class SimDevice {
304332
SimDevice(this.category, this.data);
305333

0 commit comments

Comments
 (0)