Fix daemon device discovery crash when Xcode isn't installed (#60546)

This commit is contained in:
Jenn Magder
2020-06-29 14:54:19 -07:00
committed by GitHub
parent 09cca73aee
commit d5225a560d
2 changed files with 17 additions and 1 deletions

View File

@@ -64,6 +64,9 @@ class IOSDevices extends PollingDeviceDiscovery {
'Control of iOS devices or simulators only supported on macOS.'
);
}
if (!_xcdevice.isInstalled) {
return;
}
deviceNotifier ??= ItemListNotifier<Device>();
@@ -72,7 +75,7 @@ class IOSDevices extends PollingDeviceDiscovery {
// cancel any outstanding subscriptions.
await _observedDeviceEventsSubscription?.cancel();
_observedDeviceEventsSubscription = _xcdevice.observedDeviceEvents().listen(
_observedDeviceEventsSubscription = _xcdevice.observedDeviceEvents()?.listen(
_onDeviceEvent,
onError: (dynamic error, StackTrace stack) {
_logger.printTrace('Process exception running xcdevice observe:\n$error\n$stack');

View File

@@ -370,6 +370,19 @@ void main() {
);
});
testWithoutContext('start polling without Xcode', () async {
final IOSDevices iosDevices = IOSDevices(
platform: macPlatform,
xcdevice: mockXcdevice,
iosWorkflow: mockIosWorkflow,
logger: logger,
);
when(mockXcdevice.isInstalled).thenReturn(false);
await iosDevices.startPolling();
verifyNever(mockXcdevice.getAvailableIOSDevices());
});
testWithoutContext('start polling', () async {
final IOSDevices iosDevices = IOSDevices(
platform: macPlatform,