From 3941346723c72ad65d9c7ed6c3402e78f34cd25b Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Mon, 30 Sep 2024 10:53:08 -0700 Subject: [PATCH] when `ResidentRunner.tryInitLogReader` fails, only log warning on Android (#155800) This is a follow-up to the PR https://github.com/flutter/flutter/pull/155049 (which fixed https://github.com/flutter/flutter/issues/154903). This PR addresses the resulting issue, https://github.com/flutter/flutter/issues/155795. It does so in a hacky way for the sake of simplicity (and thus suitability for cherry-picking). I intend to clean this up on the master channel with yet another follow-up PR, https://github.com/flutter/flutter/pull/155796, which currently exists as a proof-of-concept to make sure I actually have the ability to clean this after myself here. **I intend to submit a stable hotfix patch with the changes from the original fix (https://github.com/flutter/flutter/issues/154903) and the follow-up changes from this PR.** --- .../lib/src/resident_runner.dart | 20 ++++++++++--------- .../general.shard/resident_runner_test.dart | 14 ++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index e61d993f75..af8aabbea5 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -8,6 +8,7 @@ import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:vm_service/vm_service.dart' as vm_service; +import 'android/android_device.dart'; import 'application_package.dart'; import 'artifacts.dart'; import 'asset.dart'; @@ -421,16 +422,17 @@ class FlutterDevice { /// This can fail if the device if no longer connected. Future tryInitLogReader() async { final vm_service.VM? vm = await vmService!.getVmGuarded(); - if (vm == null) { - globals.printError( - 'Unable to initiate log reader for device' - '${device?.name}, because the Flutter VM service connection ' - 'is closed.', - ); - return; - } final DeviceLogReader logReader = await device!.getLogReader(app: package); - logReader.appPid = vm.pid; + if (vm == null && logReader is AdbLogReader) { + // TODO(andrewkolos): This is a temporary, hacky fix for + // https://github.com/flutter/flutter/issues/155795 that emphasizes + // simplicity for the sake of being suitable for cherry-picking. + globals.printError( + 'Unable to initiate adb log filtering for device' + '${device?.name}. Logs from the device may be more verbose than usual.', + ); + } + logReader.appPid = vm?.pid; } Future runHot({ diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index d411681c44..d67264c16d 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -1944,6 +1944,7 @@ flutter: final TestFlutterDevice flutterDevice = TestFlutterDevice(device); flutterDevice.vmService = fakeVmServiceHost!.vmService; await flutterDevice.tryInitLogReader(); + final BufferLogger logger = globals.logger as BufferLogger; expect( logger.traceText, @@ -1952,13 +1953,12 @@ flutter: 'Service connection disposed\n', ), ); - expect( - logger.errorText, - contains( - 'Unable to initiate log reader for deviceFakeDevice, because ' - 'the Flutter VM service connection is closed.\n', - ), - ); + // We should not print a warning since the device does not have a connected + // adb log reader. + // TODO(andrewkolos): This test is a bit fragile, and is something that + // should be corrected in a follow-up PR (see + // https://github.com/flutter/flutter/issues/155795). + expect(logger.errorText, isEmpty); }, overrides: { Logger: () => BufferLogger.test(), Artifacts: () => Artifacts.test(),