Merge pull request #2512 from devoncarew/lastLogcatTimestamp
fix a npe in lastLogcatTimestamp
This commit is contained in:
commit
df94a0ea1c
@ -289,7 +289,6 @@ class AndroidDevice extends Device {
|
|||||||
DeviceLogReader get logReader {
|
DeviceLogReader get logReader {
|
||||||
if (_logReader == null)
|
if (_logReader == null)
|
||||||
_logReader = new _AdbLogReader(this);
|
_logReader = new _AdbLogReader(this);
|
||||||
|
|
||||||
return _logReader;
|
return _logReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,8 +302,8 @@ class AndroidDevice extends Device {
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the most recent timestamp in the Android log. The format can be
|
/// Return the most recent timestamp in the Android log or `null` if there is
|
||||||
// passed to logcat's -T option.
|
/// no available timestamp. The format can be passed to logcat's -T option.
|
||||||
String get lastLogcatTimestamp {
|
String get lastLogcatTimestamp {
|
||||||
String output = runCheckedSync(adbCommandForDevice(<String>[
|
String output = runCheckedSync(adbCommandForDevice(<String>[
|
||||||
'-s', id, 'logcat', '-v', 'time', '-t', '1'
|
'-s', id, 'logcat', '-v', 'time', '-t', '1'
|
||||||
@ -312,7 +311,7 @@ class AndroidDevice extends Device {
|
|||||||
|
|
||||||
RegExp timeRegExp = new RegExp(r'^\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}', multiLine: true);
|
RegExp timeRegExp = new RegExp(r'^\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}', multiLine: true);
|
||||||
Match timeMatch = timeRegExp.firstMatch(output);
|
Match timeMatch = timeRegExp.firstMatch(output);
|
||||||
return timeMatch[0];
|
return timeMatch?.group(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> stopTracing(AndroidApk apk, { String outPath }) async {
|
Future<String> stopTracing(AndroidApk apk, { String outPath }) async {
|
||||||
@ -333,9 +332,10 @@ class AndroidDevice extends Device {
|
|||||||
String tracePath = null;
|
String tracePath = null;
|
||||||
bool isComplete = false;
|
bool isComplete = false;
|
||||||
while (!isComplete) {
|
while (!isComplete) {
|
||||||
String logs = runCheckedSync(adbCommandForDevice(<String>[
|
List<String> args = <String>['-s', id, 'logcat', '-d'];
|
||||||
'-s', id, 'logcat', '-d', '-T', beforeStop
|
if (beforeStop != null)
|
||||||
]));
|
args.addAll(<String>['-T', beforeStop]);
|
||||||
|
String logs = runCheckedSync(adbCommandForDevice(args));
|
||||||
Match fileMatch = traceRegExp.firstMatch(logs);
|
Match fileMatch = traceRegExp.firstMatch(logs);
|
||||||
if (fileMatch != null && fileMatch[1] != null) {
|
if (fileMatch != null && fileMatch[1] != null) {
|
||||||
tracePath = fileMatch[1];
|
tracePath = fileMatch[1];
|
||||||
@ -481,31 +481,29 @@ class _AdbLogReader extends DeviceLogReader {
|
|||||||
|
|
||||||
bool get isReading => _process != null;
|
bool get isReading => _process != null;
|
||||||
|
|
||||||
Future get finished =>
|
Future get finished => _process != null ? _process.exitCode : new Future.value(0);
|
||||||
_process != null ? _process.exitCode : new Future.value(0);
|
|
||||||
|
|
||||||
Future start() async {
|
Future start() async {
|
||||||
if (_process != null) {
|
if (_process != null)
|
||||||
throw new StateError(
|
throw new StateError('_AdbLogReader must be stopped before it can be started.');
|
||||||
'_AdbLogReader must be stopped before it can be started.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the adb logcat process.
|
// Start the adb logcat process.
|
||||||
_process = await runCommand(device.adbCommandForDevice(
|
List<String> args = <String>[
|
||||||
<String>[
|
|
||||||
'-s',
|
'-s',
|
||||||
device.id,
|
device.id,
|
||||||
'logcat',
|
'logcat',
|
||||||
'-v',
|
'-v',
|
||||||
'tag', // Only log the tag and the message
|
'tag', // Only log the tag and the message
|
||||||
'-T',
|
|
||||||
device.lastLogcatTimestamp,
|
|
||||||
'-s',
|
'-s',
|
||||||
'flutter:V',
|
'flutter:V',
|
||||||
'ActivityManager:W',
|
'ActivityManager:W',
|
||||||
'System.err:W',
|
'System.err:W',
|
||||||
'*:F',
|
'*:F'
|
||||||
]));
|
];
|
||||||
|
String lastTimestamp = device.lastLogcatTimestamp;
|
||||||
|
if (lastTimestamp != null)
|
||||||
|
args.addAll(<String>['-T', lastTimestamp]);
|
||||||
|
_process = await runCommand(device.adbCommandForDevice(args));
|
||||||
_stdoutSubscription =
|
_stdoutSubscription =
|
||||||
_process.stdout.transform(UTF8.decoder)
|
_process.stdout.transform(UTF8.decoder)
|
||||||
.transform(const LineSplitter()).listen(_onLine);
|
.transform(const LineSplitter()).listen(_onLine);
|
||||||
@ -516,10 +514,9 @@ class _AdbLogReader extends DeviceLogReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future stop() async {
|
Future stop() async {
|
||||||
if (_process == null) {
|
if (_process == null)
|
||||||
throw new StateError(
|
throw new StateError('_AdbLogReader must be started before it can be stopped.');
|
||||||
'_AdbLogReader must be started before it can be stopped.');
|
|
||||||
}
|
|
||||||
_stdoutSubscription?.cancel();
|
_stdoutSubscription?.cancel();
|
||||||
_stdoutSubscription = null;
|
_stdoutSubscription = null;
|
||||||
_stderrSubscription?.cancel();
|
_stderrSubscription?.cancel();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user