Register memory info command on vmservice for Android devices (#45568)
diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 46b65a5..3a539b8 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart
@@ -423,6 +423,14 @@ /// Stop an app package on the current device. Future<bool> stopApp(covariant ApplicationPackage app); + /// Query the current application memory usage.. + /// + /// If the device does not support this callback, an empty map + /// is returned. + Future<MemoryInfo> queryMemoryInfo() { + return Future<MemoryInfo>.value(const MemoryInfo.empty()); + } + Future<void> takeScreenshot(File outputFile) => Future<void>.error('unimplemented'); @override @@ -487,6 +495,25 @@ void dispose() {} } +/// Information about an application's memory usage. +abstract class MemoryInfo { + /// Const constructor to allow subclasses to be const. + const MemoryInfo(); + + /// Create a [MemoryInfo] object with no information. + const factory MemoryInfo.empty() = _NoMemoryInfo; + + /// Convert the object to a JSON representation suitable for serialization. + Map<String, Object> toJson(); +} + +class _NoMemoryInfo implements MemoryInfo { + const _NoMemoryInfo(); + + @override + Map<String, Object> toJson() => <String, Object>{}; +} + class DebuggingOptions { DebuggingOptions.enabled( this.buildInfo, {