[flutter_tools] ensure android log reader works in flutter drive (#68131)

This commit is contained in:
Jonah Williams 2020-10-14 14:04:33 -07:00 committed by GitHub
parent c11a64e944
commit d962c8f2a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 7 deletions

View file

@ -683,6 +683,7 @@ class AndroidDevice extends Device {
return LaunchResult.failed();
}
}
resetLogReaders();
return LaunchResult.succeeded(observatoryUri: observatoryUri);
} on Exception catch (error) {
_logger.printError('Error waiting for a debug connection: $error');
@ -742,6 +743,14 @@ class AndroidDevice extends Device {
_processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
}
/// Android device log readers are singletons. if they are closed by the
/// protocol discovery, the same kind of reader cannot be recreated.
@visibleForTesting
void resetLogReaders() {
_pastLogReader = null;
_logReader = null;
}
@override
FutureOr<DeviceLogReader> getLogReader({
AndroidApk app,

View file

@ -490,12 +490,6 @@ Future<LaunchResult> _startApp(
globals.printTrace('Starting application.');
// Forward device log messages to the terminal window running the "drive" command.
final DeviceLogReader logReader = await command.device.getLogReader(app: package);
command._deviceLogSubscription = logReader
.logLines
.listen(globals.printStatus);
final LaunchResult result = await command.device.startApp(
package,
mainPath: mainPath,
@ -517,10 +511,15 @@ Future<LaunchResult> _startApp(
);
if (!result.started) {
await command._deviceLogSubscription.cancel();
return null;
}
// Forward device log messages to the terminal window running the "drive" command.
final DeviceLogReader logReader = await command.device.getLogReader(app: package);
command._deviceLogSubscription = logReader
.logLines
.listen(globals.printStatus);
return result;
}

View file

@ -30,6 +30,20 @@ void main() {
expect(device.id, '1234');
});
testWithoutContext('Can reset log reader singletons', () async {
final AndroidDevice device = setUpAndroidDevice();
final DeviceLogReader logReader = await device.getLogReader();
final DeviceLogReader logReader2 = await device.getLogReader();
expect(logReader, logReader2);
device.resetLogReaders();
final DeviceLogReader logReader3 = await device.getLogReader();
expect(logReader, isNot(logReader3));
});
testWithoutContext('parseAdbDeviceProperties parses adb shell output', () {
final Map<String, String> properties = parseAdbDeviceProperties(kAdbShellGetprop);