diff --git a/packages/flutter_tools/lib/src/commands/devices.dart b/packages/flutter_tools/lib/src/commands/devices.dart index 07ed49fc4d..c2b52085b6 100644 --- a/packages/flutter_tools/lib/src/commands/devices.dart +++ b/packages/flutter_tools/lib/src/commands/devices.dart @@ -27,7 +27,7 @@ class DevicesCommand extends FlutterCommand { exitCode: 1); } - final List devices = await deviceManager.getAllConnectedDevices().toList(); + final List devices = await deviceManager.getAllConnectedDevices(); if (devices.isEmpty) { globals.printStatus( diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index b3dd7d189b..0a28259143 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -100,8 +100,8 @@ class DeviceManager { /// specifiedDeviceId = 'all'. bool get hasSpecifiedAllDevices => _specifiedDeviceId == 'all'; - Stream getDevicesById(String deviceId) async* { - final List devices = await getAllConnectedDevices().toList(); + Future> getDevicesById(String deviceId) async { + final List devices = await getAllConnectedDevices(); deviceId = deviceId.toLowerCase(); bool exactlyMatchesDeviceId(Device device) => device.id.toLowerCase() == deviceId || @@ -113,18 +113,15 @@ class DeviceManager { final Device exactMatch = devices.firstWhere( exactlyMatchesDeviceId, orElse: () => null); if (exactMatch != null) { - yield exactMatch; - return; + return [exactMatch]; } // Match on a id or name starting with [deviceId]. - for (final Device device in devices.where(startsWithDeviceId)) { - yield device; - } + return devices.where(startsWithDeviceId).toList(); } /// Return the list of connected devices, filtered by any user-specified device id. - Stream getDevices() { + Future> getDevices() { return hasSpecifiedDeviceId ? getDevicesById(specifiedDeviceId) : getAllConnectedDevices(); @@ -135,12 +132,13 @@ class DeviceManager { } /// Return the list of all connected devices. - Stream getAllConnectedDevices() async* { - for (final DeviceDiscovery discoverer in _platformDiscoverers) { - for (final Device device in await discoverer.devices) { - yield device; - } - } + Future> getAllConnectedDevices() async { + final List> devices = await Future.wait>(>>[ + for (final DeviceDiscovery discoverer in _platformDiscoverers) + discoverer.devices, + ]); + + return devices.expand((List deviceList) => deviceList).toList(); } /// Whether we're capable of listing any devices given the current environment configuration. @@ -170,7 +168,7 @@ class DeviceManager { /// device connected, then filter out unsupported devices and prioritize /// ephemeral devices. Future> findTargetDevices(FlutterProject flutterProject) async { - List devices = await getDevices().toList(); + List devices = await getDevices(); // Always remove web and fuchsia devices from `--all`. This setting // currently requires devices to share a frontend_server and resident diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index d2a39a7c1b..9078488ae0 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -878,7 +878,7 @@ class DeviceValidator extends DoctorValidator { @override Future validate() async { - final List devices = await deviceManager.getAllConnectedDevices().toList(); + final List devices = await deviceManager.getAllConnectedDevices(); List messages; if (devices.isEmpty) { final List diagnostics = await deviceManager.getDeviceDiagnostics(); diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index a17cb74fca..25d752a2da 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -718,7 +718,7 @@ abstract class FlutterCommand extends Command { globals.printStatus(userMessages.flutterFoundSpecifiedDevices(devices.length, deviceManager.specifiedDeviceId)); } else { globals.printStatus(userMessages.flutterSpecifyDeviceWithAllOption); - devices = await deviceManager.getAllConnectedDevices().toList(); + devices = await deviceManager.getAllConnectedDevices(); } globals.printStatus(''); await Device.printDevices(devices); @@ -738,7 +738,7 @@ abstract class FlutterCommand extends Command { } if (deviceList.length > 1) { globals.printStatus(userMessages.flutterSpecifyDevice); - deviceList = await deviceManager.getAllConnectedDevices().toList(); + deviceList = await deviceManager.getAllConnectedDevices(); globals.printStatus(''); await Device.printDevices(deviceList); return null; @@ -804,7 +804,7 @@ mixin DeviceBasedDevelopmentArtifacts on FlutterCommand { // If there are no attached devices, use the default configuration. // Otherwise, only add development artifacts which correspond to a // connected device. - final List devices = await deviceManager.getDevices().toList(); + final List devices = await deviceManager.getDevices(); if (devices.isEmpty) { return super.requiredArtifacts; } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart index c0e4414427..77f60ad9f4 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart @@ -95,7 +95,7 @@ void main() { return Future>.value([mockDevice]); }); when(deviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.value(mockDevice); + return Future>.value([mockDevice]); }); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file('pubspec.yaml').createSync(); @@ -215,7 +215,7 @@ void main() { const List noDevices = []; when(mockDeviceManager.getDevices()).thenAnswer( - (Invocation invocation) => Stream.fromIterable(noDevices) + (Invocation invocation) => Future>.value(noDevices) ); when(mockDeviceManager.findTargetDevices(any)).thenAnswer( (Invocation invocation) => Future>.value(noDevices) @@ -245,7 +245,7 @@ void main() { // Called as part of requiredArtifacts() when(mockDeviceManager.getDevices()).thenAnswer( - (Invocation invocation) => Stream.fromIterable([]) + (Invocation invocation) => Future>.value([]) ); // No devices are attached, we just want to verify update the cache // BEFORE checking for devices @@ -308,7 +308,7 @@ void main() { )).thenReturn('/path/to/sdk'); when(mockDeviceManager.getDevices()).thenAnswer( - (Invocation invocation) => Stream.fromIterable([mockDevice]), + (Invocation invocation) => Future>.value([mockDevice]) ); when(mockDeviceManager.findTargetDevices(any)).thenAnswer( @@ -366,9 +366,7 @@ void main() { setUpAll(() { final FakeDevice fakeDevice = FakeDevice(); when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.fromIterable([ - fakeDevice, - ]); + return Future>.value([fakeDevice]); }); when(mockDeviceManager.findTargetDevices(any)).thenAnswer( (Invocation invocation) => Future>.value([fakeDevice]) @@ -454,7 +452,7 @@ void main() { testUsingContext('should only request artifacts corresponding to connected devices', () async { when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.fromIterable([ + return Future>.value([ MockDevice(TargetPlatform.android_arm), ]); }); @@ -465,7 +463,7 @@ void main() { })); when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.fromIterable([ + return Future>.value([ MockDevice(TargetPlatform.ios), ]); }); @@ -476,7 +474,7 @@ void main() { })); when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.fromIterable([ + return Future>.value([ MockDevice(TargetPlatform.ios), MockDevice(TargetPlatform.android_arm), ]); @@ -489,7 +487,7 @@ void main() { })); when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { - return Stream.fromIterable([ + return Future>.value([ MockDevice(TargetPlatform.web_javascript), ]); }); @@ -510,7 +508,7 @@ void main() { setUpAll(() { final FakeDevice fakeDevice = FakeDevice().._targetPlatform = TargetPlatform.web_javascript; when(mockDeviceManager.getDevices()).thenAnswer( - (Invocation invocation) => Stream.fromIterable([fakeDevice]) + (Invocation invocation) => Future>.value([fakeDevice]) ); when(mockDeviceManager.findTargetDevices(any)).thenAnswer( (Invocation invocation) => Future>.value([fakeDevice]) @@ -612,7 +610,7 @@ class TestRunCommand extends RunCommand { @override // ignore: must_call_super Future validateCommand() async { - devices = await deviceManager.getDevices().toList(); + devices = await deviceManager.getDevices(); } } diff --git a/packages/flutter_tools/test/general.shard/device_test.dart b/packages/flutter_tools/test/general.shard/device_test.dart index 601b9e5e70..ebbf48848c 100644 --- a/packages/flutter_tools/test/general.shard/device_test.dart +++ b/packages/flutter_tools/test/general.shard/device_test.dart @@ -18,7 +18,7 @@ void main() { testUsingContext('getDevices', () async { // Test that DeviceManager.getDevices() doesn't throw. final DeviceManager deviceManager = DeviceManager(); - final List devices = await deviceManager.getDevices().toList(); + final List devices = await deviceManager.getDevices(); expect(devices, isList); }); @@ -30,7 +30,7 @@ void main() { final DeviceManager deviceManager = TestDeviceManager(devices); Future expectDevice(String id, List expected) async { - expect(await deviceManager.getDevicesById(id).toList(), expected); + expect(await deviceManager.getDevicesById(id), expected); } await expectDevice('01abfc49119c410e', [device2]); await expectDevice('Nexus 5X', [device2]); @@ -170,9 +170,7 @@ class TestDeviceManager extends DeviceManager { bool isAlwaysSupportedOverride; @override - Stream getAllConnectedDevices() { - return Stream.fromIterable(allDevices); - } + Future> getAllConnectedDevices() async => allDevices; @override bool isDeviceSupportedForProject(Device device, FlutterProject flutterProject) { diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index f2b6cc96ba..3830765362 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -201,16 +201,15 @@ class FakeDeviceManager implements DeviceManager { } @override - Stream getAllConnectedDevices() => Stream.fromIterable(devices); + Future> getAllConnectedDevices() async => devices; @override - Stream getDevicesById(String deviceId) { - return Stream.fromIterable( - devices.where((Device device) => device.id == deviceId)); + Future> getDevicesById(String deviceId) async { + return devices.where((Device device) => device.id == deviceId).toList(); } @override - Stream getDevices() { + Future> getDevices() { return hasSpecifiedDeviceId ? getDevicesById(specifiedDeviceId) : getAllConnectedDevices();