[flutter_tools] Do not use the logcat -T flag on Android versions before Lollipop (#49327)

This commit is contained in:
Jason Simmons
2020-01-23 20:18:01 -08:00
committed by Flutter GitHub Bot
parent d9f071fd0a
commit 3f97315720
2 changed files with 52 additions and 22 deletions

View File

@@ -10,7 +10,7 @@ import '../android/android_builder.dart';
import '../android/android_sdk.dart';
import '../android/android_workflow.dart';
import '../application_package.dart';
import '../base/common.dart' show throwToolExit;
import '../base/common.dart' show throwToolExit, unawaited;
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
@@ -1014,29 +1014,36 @@ class _AdbLogReader extends DeviceLogReader {
@override
String get name => device.name;
void _start() {
Future<void> _start() async {
final String lastTimestamp = device.lastLogcatTimestamp;
// Start the adb logcat process and filter the most recent logs since `lastTimestamp`.
final List<String> args = <String>[
'logcat',
'-v',
'time',
'-T',
lastTimestamp ?? '', // Empty `-T` means the timestamp of the logcat command invocation.
];
processUtils.start(device.adbCommandForDevice(args)).then<void>((Process process) {
_process = process;
// We expect logcat streams to occasionally contain invalid utf-8,
// see: https://github.com/flutter/flutter/pull/8864.
const Utf8Decoder decoder = Utf8Decoder(reportErrors: false);
_process.stdout.transform<String>(decoder).transform<String>(const LineSplitter()).listen(_onLine);
_process.stderr.transform<String>(decoder).transform<String>(const LineSplitter()).listen(_onLine);
_process.exitCode.whenComplete(() {
if (_linesController.hasListener) {
_linesController.close();
}
});
});
// logcat -T is not supported on Android releases before Lollipop.
const int kLollipopVersionCode = 21;
final int apiVersion = int.tryParse(await device._apiVersion);
if (apiVersion != null && apiVersion >= kLollipopVersionCode) {
args.addAll(<String>[
'-T',
lastTimestamp ?? '', // Empty `-T` means the timestamp of the logcat command invocation.
]);
}
_process = await processUtils.start(device.adbCommandForDevice(args));
// We expect logcat streams to occasionally contain invalid utf-8,
// see: https://github.com/flutter/flutter/pull/8864.
const Utf8Decoder decoder = Utf8Decoder(reportErrors: false);
_process.stdout.transform<String>(decoder).transform<String>(const LineSplitter()).listen(_onLine);
_process.stderr.transform<String>(decoder).transform<String>(const LineSplitter()).listen(_onLine);
unawaited(_process.exitCode.whenComplete(() {
if (_linesController.hasListener) {
_linesController.close();
}
}));
}
// 'W/ActivityManager(pid): '