Unverified Commit 2d283504 authored by Marian Triebe's avatar Marian Triebe Committed by GitHub

Add cold boot option to emulator launch command (#82647)

parent 647712e9
...@@ -77,3 +77,4 @@ Hidenori Matsubayashi <Hidenori.Matsubayashi@sony.com> ...@@ -77,3 +77,4 @@ Hidenori Matsubayashi <Hidenori.Matsubayashi@sony.com>
Perqin Xie <perqinxie@gmail.com> Perqin Xie <perqinxie@gmail.com>
Seongyun Kim <helloworld@cau.ac.kr> Seongyun Kim <helloworld@cau.ac.kr>
Ludwik Trammer <ludwik@gmail.com> Ludwik Trammer <ludwik@gmail.com>
Marian Triebe <m.triebe@live.de>
...@@ -149,10 +149,15 @@ class AndroidEmulator extends Emulator { ...@@ -149,10 +149,15 @@ class AndroidEmulator extends Emulator {
String _prop(String name) => _properties != null ? _properties[name] : null; String _prop(String name) => _properties != null ? _properties[name] : null;
@override @override
Future<void> launch({@visibleForTesting Duration startupDuration}) async { Future<void> launch({@visibleForTesting Duration startupDuration, bool coldBoot = false}) async {
final Process process = await _processUtils.start( final List<String> command = <String>[
<String>[_androidSdk.emulatorPath, '-avd', id], _androidSdk.emulatorPath,
); '-avd',
id,
if (coldBoot)
'-no-snapshot-load'
];
final Process process = await _processUtils.start(command);
// Record output from the emulator process. // Record output from the emulator process.
final List<String> stdoutList = <String>[]; final List<String> stdoutList = <String>[];
......
...@@ -15,6 +15,9 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -15,6 +15,9 @@ class EmulatorsCommand extends FlutterCommand {
EmulatorsCommand() { EmulatorsCommand() {
argParser.addOption('launch', argParser.addOption('launch',
help: 'The full or partial ID of the emulator to launch.'); help: 'The full or partial ID of the emulator to launch.');
argParser.addFlag('cold',
help: 'Used with the "--launch" flag to cold boot the emulator instance (Android only).',
negatable: false);
argParser.addFlag('create', argParser.addFlag('create',
help: 'Creates a new Android emulator based on a Pixel device.', help: 'Creates a new Android emulator based on a Pixel device.',
negatable: false); negatable: false);
...@@ -43,7 +46,8 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -43,7 +46,8 @@ class EmulatorsCommand extends FlutterCommand {
} }
if (argResults.wasParsed('launch')) { if (argResults.wasParsed('launch')) {
await _launchEmulator(stringArg('launch')); final bool coldBoot = argResults.wasParsed('cold');
await _launchEmulator(stringArg('launch'), coldBoot: coldBoot);
} else if (argResults.wasParsed('create')) { } else if (argResults.wasParsed('create')) {
await _createEmulator(name: stringArg('name')); await _createEmulator(name: stringArg('name'));
} else { } else {
...@@ -57,7 +61,7 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -57,7 +61,7 @@ class EmulatorsCommand extends FlutterCommand {
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
Future<void> _launchEmulator(String id) async { Future<void> _launchEmulator(String id, {bool coldBoot}) async {
final List<Emulator> emulators = final List<Emulator> emulators =
await emulatorManager.getEmulatorsMatching(id); await emulatorManager.getEmulatorsMatching(id);
...@@ -69,7 +73,7 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -69,7 +73,7 @@ class EmulatorsCommand extends FlutterCommand {
"More than one emulator matches '$id':", "More than one emulator matches '$id':",
); );
} else { } else {
await emulators.first.launch(); await emulators.first.launch(coldBoot: coldBoot);
} }
} }
......
...@@ -268,7 +268,7 @@ abstract class Emulator { ...@@ -268,7 +268,7 @@ abstract class Emulator {
&& other.id == id; && other.id == id;
} }
Future<void> launch(); Future<void> launch({bool coldBoot});
@override @override
String toString() => name; String toString() => name;
......
...@@ -40,7 +40,7 @@ class IOSEmulator extends Emulator { ...@@ -40,7 +40,7 @@ class IOSEmulator extends Emulator {
PlatformType get platformType => PlatformType.ios; PlatformType get platformType => PlatformType.ios;
@override @override
Future<void> launch() async { Future<void> launch({bool coldBoot = false}) async {
Future<bool> launchSimulator(List<String> additionalArgs) async { Future<bool> launchSimulator(List<String> additionalArgs) async {
final List<String> args = <String>[ final List<String> args = <String>[
'open', 'open',
......
...@@ -144,6 +144,22 @@ void main() { ...@@ -144,6 +144,22 @@ void main() {
await emulator.launch(startupDuration: Duration.zero); await emulator.launch(startupDuration: Duration.zero);
}); });
testWithoutContext('succeeds with coldboot launch', () async {
final List<String> kEmulatorLauchColdBootCommand = <String>[
...kEmulatorLaunchCommand,
'-no-snapshot-load'
];
final AndroidEmulator emulator = AndroidEmulator(emulatorID,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: kEmulatorLauchColdBootCommand),
]),
androidSdk: mockSdk,
logger: BufferLogger.test(),
);
await emulator.launch(startupDuration: Duration.zero, coldBoot: true);
});
testWithoutContext('prints error on failure', () async { testWithoutContext('prints error on failure', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final AndroidEmulator emulator = AndroidEmulator(emulatorID, final AndroidEmulator emulator = AndroidEmulator(emulatorID,
......
...@@ -367,7 +367,7 @@ class FakeEmulator extends Emulator { ...@@ -367,7 +367,7 @@ class FakeEmulator extends Emulator {
PlatformType get platformType => PlatformType.android; PlatformType get platformType => PlatformType.android;
@override @override
Future<void> launch() { Future<void> launch({bool coldBoot = false}) {
throw UnimplementedError('Not implemented in Mock'); throw UnimplementedError('Not implemented in Mock');
} }
} }
......
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