diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index e38b6fe689e..cf0b4d479bd 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -255,7 +255,12 @@ class VMService implements vm_service.VmService { final Map versionJson = version.toJson(); versionJson['frameworkRevisionShort'] = version.frameworkRevisionShort; versionJson['engineRevisionShort'] = version.engineRevisionShort; - return versionJson; + return { + 'result': { + 'type': 'Success', + ...versionJson, + } + }; }); _delegateService.registerService('flutterVersion', 'Flutter Tools'); @@ -306,8 +311,21 @@ class VMService implements vm_service.VmService { } if (device != null) { _delegateService.registerServiceCallback('flutterMemoryInfo', (Map params) async { - final MemoryInfo result = await device.queryMemoryInfo(); - return result.toJson(); + try { + final MemoryInfo result = await device.queryMemoryInfo(); + return { + 'result': { + 'type': 'Success', + ...result.toJson(), + } + }; + } on Exception catch (e, st) { + throw vm_service.RPCError( + 'Error during memory info query $e\n$st', + RPCErrorCodes.kServerError, + '', + ); + } }); _delegateService.registerService('flutterMemoryInfo', 'Flutter Tools'); } @@ -354,6 +372,7 @@ class VMService implements vm_service.VmService { final io.WebSocket channel = await _openChannel(wsUri.toString(), compression: compression); final StreamController primary = StreamController(); final StreamController secondary = StreamController(); + // Create an instance of the package:vm_service API in addition to the flutter // tool's to allow gradual migration. final Completer streamClosedCompleter = Completer(); @@ -371,7 +390,6 @@ class VMService implements vm_service.VmService { primary.addError(error, stackTrace); secondary.addError(error, stackTrace); }); - final vm_service.VmService delegateService = vm_service.VmService( primary.stream, channel.add, diff --git a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart new file mode 100644 index 00000000000..8e7fb92369f --- /dev/null +++ b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart @@ -0,0 +1,43 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:file/file.dart'; +import 'package:flutter_tools/src/base/file_system.dart'; +import 'package:vm_service/vm_service.dart'; +import 'package:vm_service/vm_service_io.dart'; + +import '../src/common.dart'; +import 'test_data/basic_project.dart'; +import 'test_driver.dart'; +import 'test_utils.dart'; + +void main() { + Directory tempDir; + FlutterRunTestDriver flutter; + + test('Flutter Tool VMService methods can be called', () async { + tempDir = createResolvedTempDirectorySync('vmservice_integration_test.'); + + final BasicProject _project = BasicProject(); + await _project.setUpIn(tempDir); + + flutter = FlutterRunTestDriver(tempDir); + await flutter.run(withDebugger: true); + final int port = flutter.vmServicePort; + final VmService vmService = await vmServiceConnectUri('ws://localhost:$port/ws'); + + final Response versionResponse = await vmService.callMethod('s0.flutterVersion'); + expect(versionResponse.type, 'Success'); + expect(versionResponse.json, containsPair('frameworkRevisionShort', isNotNull)); + expect(versionResponse.json, containsPair('engineRevisionShort', isNotNull)); + + final Response memoryInfoResponse = await vmService.callMethod('s0.flutterMemoryInfo'); + expect(memoryInfoResponse.type, 'Success'); + }); + + tearDown(() { + tryToDelete(tempDir); + flutter?.stop(); + }); +}