From 34b9ce859af85b181ac2d355993283b3e7a11938 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 20 Jan 2017 08:51:57 -0800 Subject: [PATCH] proxy service extension calls through the daemon protocol (#7554) * proxy service extension calls through the daemon protocol * add test for app.callServiceExtension --- .../lib/src/commands/daemon.dart | 22 +++++++++++++++ packages/flutter_tools/test/daemon_test.dart | 27 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 8c12a38913..d32a067899 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -22,6 +22,7 @@ import '../ios/simulators.dart'; import '../resident_runner.dart'; import '../run.dart'; import '../runner/flutter_command.dart'; +import '../vmservice.dart'; const String protocolVersion = '0.2.0'; @@ -280,6 +281,7 @@ class AppDomain extends Domain { AppDomain(Daemon daemon) : super(daemon, 'app') { registerHandler('start', start); registerHandler('restart', restart); + registerHandler('callServiceExtension', callServiceExtension); registerHandler('stop', stop); registerHandler('discover', discover); } @@ -435,6 +437,26 @@ class AppDomain extends Domain { }); } + Future callServiceExtension(Map args) async { + String appId = _getStringArg(args, 'appId', required: true); + String methodName = _getStringArg(args, 'methodName'); + Map params = args['params'] ?? {}; + + AppInstance app = _getApp(appId); + if (app == null) + throw "app '$appId' not found"; + + Isolate isolate = app.runner.currentView.uiIsolate; + Map result = await isolate.invokeFlutterExtensionRpcRaw(methodName, params: params); + if (result == null) + return new OperationResult(1, 'method not available: $methodName'); + + if (result.containsKey('error')) + return new OperationResult(1, result['error']); + else + return OperationResult.ok; + } + Future stop(Map args) async { String appId = _getStringArg(args, 'appId', required: true); diff --git a/packages/flutter_tools/test/daemon_test.dart b/packages/flutter_tools/test/daemon_test.dart index a9a6fb272c..ad3ca42f02 100644 --- a/packages/flutter_tools/test/daemon_test.dart +++ b/packages/flutter_tools/test/daemon_test.dart @@ -167,6 +167,33 @@ void main() { commands.close(); }); + _testUsingContext('daemon.callServiceExtension', () async { + DaemonCommand command = new DaemonCommand(); + applyMocksToCommand(command); + + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); + daemon = new Daemon( + commands.stream, + (Map result) => responses.add(result), + daemonCommand: command, + notifyingLogger: notifyingLogger + ); + + commands.add({ + 'id': 0, + 'method': 'app.callServiceExtension', + 'params': { + 'methodName': 'ext.flutter.debugPaint' + } + }); + Map response = await responses.stream.where(_notEvent).first; + expect(response['id'], 0); + expect(response['error'], contains('appId is required')); + responses.close(); + commands.close(); + }); + _testUsingContext('daemon.stop', () async { DaemonCommand command = new DaemonCommand(); applyMocksToCommand(command);