Add cold boot option to emulator launch command (#82647)
This commit is contained in:
parent
647712e92e
commit
2d283504e6
1
AUTHORS
1
AUTHORS
@ -77,3 +77,4 @@ Hidenori Matsubayashi <Hidenori.Matsubayashi@sony.com>
|
||||
Perqin Xie <perqinxie@gmail.com>
|
||||
Seongyun Kim <helloworld@cau.ac.kr>
|
||||
Ludwik Trammer <ludwik@gmail.com>
|
||||
Marian Triebe <m.triebe@live.de>
|
||||
|
@ -149,10 +149,15 @@ class AndroidEmulator extends Emulator {
|
||||
String _prop(String name) => _properties != null ? _properties[name] : null;
|
||||
|
||||
@override
|
||||
Future<void> launch({@visibleForTesting Duration startupDuration}) async {
|
||||
final Process process = await _processUtils.start(
|
||||
<String>[_androidSdk.emulatorPath, '-avd', id],
|
||||
);
|
||||
Future<void> launch({@visibleForTesting Duration startupDuration, bool coldBoot = false}) async {
|
||||
final List<String> command = <String>[
|
||||
_androidSdk.emulatorPath,
|
||||
'-avd',
|
||||
id,
|
||||
if (coldBoot)
|
||||
'-no-snapshot-load'
|
||||
];
|
||||
final Process process = await _processUtils.start(command);
|
||||
|
||||
// Record output from the emulator process.
|
||||
final List<String> stdoutList = <String>[];
|
||||
|
@ -15,6 +15,9 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
EmulatorsCommand() {
|
||||
argParser.addOption('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',
|
||||
help: 'Creates a new Android emulator based on a Pixel device.',
|
||||
negatable: false);
|
||||
@ -43,7 +46,8 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
}
|
||||
|
||||
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')) {
|
||||
await _createEmulator(name: stringArg('name'));
|
||||
} else {
|
||||
@ -57,7 +61,7 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
|
||||
Future<void> _launchEmulator(String id) async {
|
||||
Future<void> _launchEmulator(String id, {bool coldBoot}) async {
|
||||
final List<Emulator> emulators =
|
||||
await emulatorManager.getEmulatorsMatching(id);
|
||||
|
||||
@ -69,7 +73,7 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
"More than one emulator matches '$id':",
|
||||
);
|
||||
} else {
|
||||
await emulators.first.launch();
|
||||
await emulators.first.launch(coldBoot: coldBoot);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ abstract class Emulator {
|
||||
&& other.id == id;
|
||||
}
|
||||
|
||||
Future<void> launch();
|
||||
Future<void> launch({bool coldBoot});
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
@ -40,7 +40,7 @@ class IOSEmulator extends Emulator {
|
||||
PlatformType get platformType => PlatformType.ios;
|
||||
|
||||
@override
|
||||
Future<void> launch() async {
|
||||
Future<void> launch({bool coldBoot = false}) async {
|
||||
Future<bool> launchSimulator(List<String> additionalArgs) async {
|
||||
final List<String> args = <String>[
|
||||
'open',
|
||||
|
@ -144,6 +144,22 @@ void main() {
|
||||
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 {
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final AndroidEmulator emulator = AndroidEmulator(emulatorID,
|
||||
|
@ -367,7 +367,7 @@ class FakeEmulator extends Emulator {
|
||||
PlatformType get platformType => PlatformType.android;
|
||||
|
||||
@override
|
||||
Future<void> launch() {
|
||||
Future<void> launch({bool coldBoot = false}) {
|
||||
throw UnimplementedError('Not implemented in Mock');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user