mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
[flutter_tools] ensure android log reader works in flutter drive (#68131)
This commit is contained in:
parent
c11a64e944
commit
d962c8f2a2
|
@ -683,6 +683,7 @@ class AndroidDevice extends Device {
|
||||||
return LaunchResult.failed();
|
return LaunchResult.failed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resetLogReaders();
|
||||||
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
||||||
} on Exception catch (error) {
|
} on Exception catch (error) {
|
||||||
_logger.printError('Error waiting for a debug connection: $error');
|
_logger.printError('Error waiting for a debug connection: $error');
|
||||||
|
@ -742,6 +743,14 @@ class AndroidDevice extends Device {
|
||||||
_processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
|
_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
|
@override
|
||||||
FutureOr<DeviceLogReader> getLogReader({
|
FutureOr<DeviceLogReader> getLogReader({
|
||||||
AndroidApk app,
|
AndroidApk app,
|
||||||
|
|
|
@ -490,12 +490,6 @@ Future<LaunchResult> _startApp(
|
||||||
|
|
||||||
globals.printTrace('Starting application.');
|
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(
|
final LaunchResult result = await command.device.startApp(
|
||||||
package,
|
package,
|
||||||
mainPath: mainPath,
|
mainPath: mainPath,
|
||||||
|
@ -517,10 +511,15 @@ Future<LaunchResult> _startApp(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.started) {
|
if (!result.started) {
|
||||||
await command._deviceLogSubscription.cancel();
|
|
||||||
return null;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,20 @@ void main() {
|
||||||
expect(device.id, '1234');
|
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', () {
|
testWithoutContext('parseAdbDeviceProperties parses adb shell output', () {
|
||||||
final Map<String, String> properties = parseAdbDeviceProperties(kAdbShellGetprop);
|
final Map<String, String> properties = parseAdbDeviceProperties(kAdbShellGetprop);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue