Unverified Commit 475ee898 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Make Android log reader read any recent logs (#45743)

parent e2642fd6
...@@ -688,7 +688,7 @@ class AndroidDevice extends Device { ...@@ -688,7 +688,7 @@ class AndroidDevice extends Device {
String output; String output;
try { try {
output = runAdbCheckedSync(<String>[ output = runAdbCheckedSync(<String>[
'shell', '-x', 'logcat', '-v', 'time', '-t', '1', 'shell', '-x', 'logcat', '-v', 'time', '-t', '1'
]); ]);
} catch (error) { } catch (error) {
printError('Failed to extract the most recent timestamp from the Android log: $error.'); printError('Failed to extract the most recent timestamp from the Android log: $error.');
...@@ -1007,8 +1007,9 @@ class _AdbLogReader extends DeviceLogReader { ...@@ -1007,8 +1007,9 @@ class _AdbLogReader extends DeviceLogReader {
String get name => device.name; String get name => device.name;
void _start() { void _start() {
// Start the adb logcat process and filter logs by the "flutter" tag. final String lastTimestamp = device.lastLogcatTimestamp;
final List<String> args = <String>['shell', '-x', 'logcat', '-v', 'time', '-s', 'flutter']; // Start the adb logcat process and filter the most recent logs since `lastTimestamp`.
final List<String> args = <String>['logcat', '-v', 'time', '-T', lastTimestamp];
processUtils.start(device.adbCommandForDevice(args)).then<void>((Process process) { processUtils.start(device.adbCommandForDevice(args)).then<void>((Process process) {
_process = process; _process = process;
// We expect logcat streams to occasionally contain invalid utf-8, // We expect logcat streams to occasionally contain invalid utf-8,
......
...@@ -680,6 +680,35 @@ flutter: ...@@ -680,6 +680,35 @@ flutter:
}); });
}); });
group('logReader', () {
ProcessManager mockProcessManager;
AndroidSdk mockAndroidSdk;
setUp(() {
mockAndroidSdk = MockAndroidSdk();
mockProcessManager = MockProcessManager();
});
testUsingContext('calls adb logcat with expected flags', () async {
const String klastLocatcatTimestamp = '11-27 15:39:04.506';
when(mockAndroidSdk.adbPath).thenReturn('adb');
when(mockProcessManager.runSync(<String>['adb', '-s', '1234', 'shell', '-x', 'logcat', '-v', 'time', '-t', '1']))
.thenReturn(ProcessResult(0, 0, '$klastLocatcatTimestamp I/flutter: irrelevant', ''));
when(mockProcessManager.start(argThat(contains('logcat'))))
.thenAnswer((_) => Future<Process>.value(createMockProcess()));
final AndroidDevice device = AndroidDevice('1234');
final DeviceLogReader logReader = device.getLogReader();
logReader.logLines.listen((_) {});
verify(mockProcessManager.start(const <String>['adb', '-s', '1234', 'logcat', '-v', 'time', '-T', klastLocatcatTimestamp]))
.called(1);
}, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
ProcessManager: () => mockProcessManager,
});
});
test('Can parse adb shell dumpsys info', () { test('Can parse adb shell dumpsys info', () {
const String exampleOutput = r''' const String exampleOutput = r'''
Applications Memory Usage (in Kilobytes): Applications Memory Usage (in Kilobytes):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment