From 722a493f3a105b150d8da3f473cea1e0f17989ae Mon Sep 17 00:00:00 2001 From: Marian Triebe Date: Fri, 28 May 2021 18:14:03 +0200 Subject: [PATCH] Add `coldBoot` parameter to JSON-RPC interface of daemon (#83488) --- packages/flutter_tools/doc/daemon.md | 2 ++ .../flutter_tools/lib/src/commands/daemon.dart | 5 +++-- .../commands.shard/hermetic/daemon_test.dart | 17 +++++++++++++++++ packages/flutter_tools/tool/daemon_client.dart | 4 +++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/doc/daemon.md b/packages/flutter_tools/doc/daemon.md index 638594cd05..a96494cd6f 100644 --- a/packages/flutter_tools/doc/daemon.md +++ b/packages/flutter_tools/doc/daemon.md @@ -233,6 +233,7 @@ Return a list of all available emulators. The `params` field will be a List; eac The `launch()` command allows launching an emulator/simulator by its `id`. - `emulatorId`: the id of an emulator as returned by `getEmulators`. +- `coldBoot`: an optional boolean flag which indicates if the emulator should be cold booted. Only supported for android emulators, silently ignored if emulator type is not android. #### emulator.create @@ -295,6 +296,7 @@ See the [source](https://github.com/flutter/flutter/blob/master/packages/flutter ## Changelog +- 0.6.1: Added `coldBoot` option to `emulator.lauch` command. - 0.6.0: Added `debounce` option to `app.restart` command. - 0.5.3: Added `emulatorId` field to device. - 0.5.2: Added `platformType` and `category` fields to emulator. diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 4c65fcfcc7..de85eaf080 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -32,7 +32,7 @@ import '../runner/flutter_command.dart'; import '../vmservice.dart'; import '../web/web_runner.dart'; -const String protocolVersion = '0.6.0'; +const String protocolVersion = '0.6.1'; /// A server process command. This command will start up a long-lived server. /// It reads JSON-RPC based commands from stdin, executes them, and returns @@ -1118,6 +1118,7 @@ class EmulatorDomain extends Domain { Future launch(Map args) async { final String emulatorId = _getStringArg(args, 'emulatorId', required: true); + final bool coldBoot = _getBoolArg(args, 'coldBoot') ?? false; final List matches = await emulators.getEmulatorsMatching(emulatorId); if (matches.isEmpty) { @@ -1125,7 +1126,7 @@ class EmulatorDomain extends Domain { } else if (matches.length > 1) { throw "multiple emulators match '$emulatorId'"; } else { - await matches.first.launch(); + await matches.first.launch(coldBoot: coldBoot); } } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart index 874dde33b5..63bc51486d 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart @@ -298,6 +298,23 @@ void main() { await commands.close(); }); + testUsingContext('emulator.launch coldboot parameter must be boolean', () async { + final StreamController> commands = StreamController>(); + final StreamController> responses = StreamController>(); + daemon = Daemon( + commands.stream, + responses.add, + notifyingLogger: notifyingLogger, + ); + final Map params = {'emulatorId': 'device', 'coldBoot': 1}; + commands.add({'id': 0, 'method': 'emulator.launch', 'params': params}); + final Map response = await responses.stream.firstWhere(_notEvent); + expect(response['id'], 0); + expect(response['error'], contains('coldBoot is not a bool')); + await responses.close(); + await commands.close(); + }); + testUsingContext('emulator.getEmulators should respond with list', () async { final StreamController> commands = StreamController>(); final StreamController> responses = StreamController>(); diff --git a/packages/flutter_tools/tool/daemon_client.dart b/packages/flutter_tools/tool/daemon_client.dart index c4033ae88b..8e31d7f155 100644 --- a/packages/flutter_tools/tool/daemon_client.dart +++ b/packages/flutter_tools/tool/daemon_client.dart @@ -16,7 +16,7 @@ late Process daemon; // stop: stop a running app // devices: list devices // emulators: list emulators -// launch: launch an emulator +// emulator-launch: launch an emulator, append the word coldBoot to cold boot the emulator. Future main() async { daemon = await Process.start('dart', ['bin/flutter_tools.dart', 'daemon']); @@ -72,6 +72,8 @@ Future main() async { 'method': 'emulator.launch', 'params': { 'emulatorId': words[1], + if (words.contains('coldBoot')) + 'coldBoot': true }, }); } else if (line == 'enable') {