forked from firka/flutter
This reverts commit 84a7a611b0.
This commit is contained in:
@@ -142,7 +142,7 @@ class AndroidEmulator extends Emulator {
|
||||
Category get category => Category.mobile;
|
||||
|
||||
@override
|
||||
String get platformDisplay => PlatformType.android.toString();
|
||||
PlatformType get platformType => PlatformType.android;
|
||||
|
||||
String _prop(String name) => _properties != null ? _properties[name] : null;
|
||||
|
||||
|
||||
@@ -933,7 +933,7 @@ Map<String, dynamic> _emulatorToMap(Emulator emulator) {
|
||||
'id': emulator.id,
|
||||
'name': emulator.name,
|
||||
'category': emulator.category?.toString(),
|
||||
'platformType': emulator.platformDisplay,
|
||||
'platformType': emulator.platformType?.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
final String description = 'List, launch and create emulators.';
|
||||
|
||||
@override
|
||||
final List<String> aliases = <String>['emulator', 'simulators', 'simulator'];
|
||||
final List<String> aliases = <String>['emulator'];
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
|
||||
@@ -614,6 +614,10 @@ abstract class Device {
|
||||
/// Check if the device is supported by Flutter.
|
||||
bool isSupported();
|
||||
|
||||
// String meant to be displayed to the user indicating if the device is
|
||||
// supported by Flutter, and, if not, why.
|
||||
String supportMessage() => isSupported() ? 'Supported' : 'Unsupported';
|
||||
|
||||
/// The device's platform.
|
||||
Future<TargetPlatform> get targetPlatform;
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ abstract class Emulator {
|
||||
String get name;
|
||||
String get manufacturer;
|
||||
Category get category;
|
||||
String get platformDisplay;
|
||||
PlatformType get platformType;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
@@ -283,7 +283,7 @@ abstract class Emulator {
|
||||
emulator.id ?? '',
|
||||
emulator.name ?? '',
|
||||
emulator.manufacturer ?? '',
|
||||
emulator.platformDisplay ?? '',
|
||||
emulator.platformType?.toString() ?? '',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -16,26 +16,17 @@ class IOSEmulators extends EmulatorDiscovery {
|
||||
bool get canListAnything => globals.iosWorkflow.canListEmulators;
|
||||
|
||||
@override
|
||||
Future<List<Emulator>> get emulators async {
|
||||
final List<IOSSimulator> simulators = await globals.iosSimulatorUtils.getAvailableDevices();
|
||||
return simulators.map<Emulator>((IOSSimulator device) {
|
||||
return IOSEmulator(device);
|
||||
}).toList();
|
||||
}
|
||||
Future<List<Emulator>> get emulators async => getEmulators();
|
||||
|
||||
@override
|
||||
bool get canLaunchAnything => canListAnything;
|
||||
}
|
||||
|
||||
class IOSEmulator extends Emulator {
|
||||
IOSEmulator(IOSSimulator simulator)
|
||||
: _simulator = simulator,
|
||||
super(simulator.id, true);
|
||||
|
||||
final IOSSimulator _simulator;
|
||||
const IOSEmulator(String id) : super(id, true);
|
||||
|
||||
@override
|
||||
String get name => _simulator.name;
|
||||
String get name => 'iOS Simulator';
|
||||
|
||||
@override
|
||||
String get manufacturer => 'Apple';
|
||||
@@ -44,20 +35,43 @@ class IOSEmulator extends Emulator {
|
||||
Category get category => Category.mobile;
|
||||
|
||||
@override
|
||||
String get platformDisplay =>
|
||||
// com.apple.CoreSimulator.SimRuntime.iOS-10-3 => iOS-10-3
|
||||
_simulator.simulatorCategory?.split('.')?.last ?? 'ios';
|
||||
PlatformType get platformType => PlatformType.ios;
|
||||
|
||||
@override
|
||||
Future<void> launch() async {
|
||||
final RunResult launchResult = await globals.processUtils.run(<String>[
|
||||
'open',
|
||||
'-a',
|
||||
globals.xcode.getSimulatorPath(),
|
||||
]);
|
||||
if (launchResult.exitCode != 0) {
|
||||
globals.printError('$launchResult');
|
||||
Future<bool> launchSimulator(List<String> additionalArgs) async {
|
||||
final List<String> args = <String>[
|
||||
'open',
|
||||
...additionalArgs,
|
||||
'-a',
|
||||
globals.xcode.getSimulatorPath(),
|
||||
];
|
||||
|
||||
final RunResult launchResult = await globals.processUtils.run(args);
|
||||
if (launchResult.exitCode != 0) {
|
||||
globals.printError('$launchResult');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return _simulator.boot();
|
||||
|
||||
// First run with `-n` to force a device to boot if there isn't already one
|
||||
if (!await launchSimulator(<String>['-n'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run again to force it to Foreground (using -n doesn't force existing
|
||||
// devices to the foreground)
|
||||
await launchSimulator(<String>[]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the list of iOS Simulators (there can only be zero or one).
|
||||
List<IOSEmulator> getEmulators() {
|
||||
final String simulatorPath = globals.xcode.getSimulatorPath();
|
||||
if (simulatorPath == null) {
|
||||
return <IOSEmulator>[];
|
||||
}
|
||||
|
||||
return <IOSEmulator>[const IOSEmulator(iosSimulatorId)];
|
||||
}
|
||||
|
||||
@@ -66,9 +66,7 @@ class IOSSimulatorUtils {
|
||||
return <IOSSimulator>[];
|
||||
}
|
||||
|
||||
final List<SimDevice> connected = (await _simControl.getAvailableDevices())
|
||||
.where((SimDevice device) => device.isBooted)
|
||||
.toList();
|
||||
final List<SimDevice> connected = await _simControl.getConnectedDevices();
|
||||
return connected.map<IOSSimulator>((SimDevice device) {
|
||||
return IOSSimulator(
|
||||
device.udid,
|
||||
@@ -79,26 +77,6 @@ class IOSSimulatorUtils {
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
Future<List<IOSSimulator>> getAvailableDevices() async {
|
||||
if (!_xcode.isInstalledAndMeetsVersionCheck) {
|
||||
return <IOSSimulator>[];
|
||||
}
|
||||
|
||||
final List<SimDevice> available = await _simControl.getAvailableDevices();
|
||||
return available
|
||||
.map<IOSSimulator>((SimDevice device) {
|
||||
return IOSSimulator(
|
||||
device.udid,
|
||||
name: device.name,
|
||||
simControl: _simControl,
|
||||
simulatorCategory: device.category,
|
||||
xcode: _xcode,
|
||||
);
|
||||
})
|
||||
.where((IOSSimulator simulator) => simulator.isSupported())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper around the `simctl` command line tool.
|
||||
@@ -111,23 +89,6 @@ class SimControl {
|
||||
_xcode = xcode,
|
||||
_processUtils = ProcessUtils(processManager: processManager, logger: logger);
|
||||
|
||||
/// Create a [SimControl] for testing.
|
||||
///
|
||||
/// Defaults to a buffer logger.
|
||||
@visibleForTesting
|
||||
factory SimControl.test({
|
||||
@required ProcessManager processManager,
|
||||
Logger logger,
|
||||
Xcode xcode,
|
||||
}) {
|
||||
logger ??= BufferLogger.test();
|
||||
return SimControl(
|
||||
logger: logger,
|
||||
xcode: xcode,
|
||||
processManager: processManager,
|
||||
);
|
||||
}
|
||||
|
||||
final Logger _logger;
|
||||
final ProcessUtils _processUtils;
|
||||
final Xcode _xcode;
|
||||
@@ -199,10 +160,10 @@ class SimControl {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/// Returns all the available simulator devices.
|
||||
Future<List<SimDevice>> getAvailableDevices() async {
|
||||
/// Returns all the connected simulator devices.
|
||||
Future<List<SimDevice>> getConnectedDevices() async {
|
||||
final List<SimDevice> simDevices = await getDevices();
|
||||
return simDevices.where((SimDevice device) => device.isAvailable).toList();
|
||||
return simDevices.where((SimDevice device) => device.isBooted).toList();
|
||||
}
|
||||
|
||||
Future<bool> isInstalled(String deviceId, String appId) {
|
||||
@@ -273,17 +234,6 @@ class SimControl {
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<RunResult> boot(String deviceId) {
|
||||
return _processUtils.run(
|
||||
<String>[
|
||||
..._xcode.xcrunCommand(),
|
||||
'simctl',
|
||||
'boot',
|
||||
deviceId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> takeScreenshot(String deviceId, String outputPath) async {
|
||||
try {
|
||||
await _processUtils.run(
|
||||
@@ -346,11 +296,7 @@ class SimDevice {
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
String get state => data['state']?.toString();
|
||||
|
||||
bool get isAvailable =>
|
||||
data['isAvailable'] == true ||
|
||||
data['availability']?.toString() == '(available)';
|
||||
|
||||
String get availability => data['availability']?.toString();
|
||||
String get name => data['name']?.toString();
|
||||
String get udid => data['udid']?.toString();
|
||||
|
||||
@@ -448,6 +394,7 @@ class IOSSimulator extends Device {
|
||||
@override
|
||||
bool isSupported() {
|
||||
if (!globals.platform.isMacOS) {
|
||||
_supportMessage = 'iOS devices require a Mac host machine.';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -455,25 +402,21 @@ class IOSSimulator extends Device {
|
||||
// We do not yet support WatchOS or tvOS devices.
|
||||
final RegExp blocklist = RegExp(r'Apple (TV|Watch)', caseSensitive: false);
|
||||
if (blocklist.hasMatch(name)) {
|
||||
_supportMessage = 'Flutter does not support Apple TV or Apple Watch.';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> boot() async {
|
||||
final RunResult result = await _simControl.boot(id);
|
||||
String _supportMessage;
|
||||
|
||||
if (result.exitCode == 0) {
|
||||
return true;
|
||||
}
|
||||
// 149 exit code means the device is already booted. Ignore this error.
|
||||
if (result.exitCode == 149) {
|
||||
globals.printTrace('Simulator "$id" already booted.');
|
||||
return true;
|
||||
@override
|
||||
String supportMessage() {
|
||||
if (isSupported()) {
|
||||
return 'Supported';
|
||||
}
|
||||
|
||||
globals.logger.printError('$result');
|
||||
return false;
|
||||
return _supportMessage ?? 'Unknown';
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user