Change DeviceManager.getAllConnectedDevices() return value from Stream to List (#51015)
This commit is contained in:
parent
6815e72086
commit
85b54d4c0c
@ -27,7 +27,7 @@ class DevicesCommand extends FlutterCommand {
|
||||
exitCode: 1);
|
||||
}
|
||||
|
||||
final List<Device> devices = await deviceManager.getAllConnectedDevices().toList();
|
||||
final List<Device> devices = await deviceManager.getAllConnectedDevices();
|
||||
|
||||
if (devices.isEmpty) {
|
||||
globals.printStatus(
|
||||
|
@ -100,8 +100,8 @@ class DeviceManager {
|
||||
/// specifiedDeviceId = 'all'.
|
||||
bool get hasSpecifiedAllDevices => _specifiedDeviceId == 'all';
|
||||
|
||||
Stream<Device> getDevicesById(String deviceId) async* {
|
||||
final List<Device> devices = await getAllConnectedDevices().toList();
|
||||
Future<List<Device>> getDevicesById(String deviceId) async {
|
||||
final List<Device> 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 <Device>[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<Device> getDevices() {
|
||||
Future<List<Device>> getDevices() {
|
||||
return hasSpecifiedDeviceId
|
||||
? getDevicesById(specifiedDeviceId)
|
||||
: getAllConnectedDevices();
|
||||
@ -135,12 +132,13 @@ class DeviceManager {
|
||||
}
|
||||
|
||||
/// Return the list of all connected devices.
|
||||
Stream<Device> getAllConnectedDevices() async* {
|
||||
for (final DeviceDiscovery discoverer in _platformDiscoverers) {
|
||||
for (final Device device in await discoverer.devices) {
|
||||
yield device;
|
||||
}
|
||||
}
|
||||
Future<List<Device>> getAllConnectedDevices() async {
|
||||
final List<List<Device>> devices = await Future.wait<List<Device>>(<Future<List<Device>>>[
|
||||
for (final DeviceDiscovery discoverer in _platformDiscoverers)
|
||||
discoverer.devices,
|
||||
]);
|
||||
|
||||
return devices.expand<Device>((List<Device> 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<List<Device>> findTargetDevices(FlutterProject flutterProject) async {
|
||||
List<Device> devices = await getDevices().toList();
|
||||
List<Device> devices = await getDevices();
|
||||
|
||||
// Always remove web and fuchsia devices from `--all`. This setting
|
||||
// currently requires devices to share a frontend_server and resident
|
||||
|
@ -878,7 +878,7 @@ class DeviceValidator extends DoctorValidator {
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
final List<Device> devices = await deviceManager.getAllConnectedDevices().toList();
|
||||
final List<Device> devices = await deviceManager.getAllConnectedDevices();
|
||||
List<ValidationMessage> messages;
|
||||
if (devices.isEmpty) {
|
||||
final List<String> diagnostics = await deviceManager.getDeviceDiagnostics();
|
||||
|
@ -718,7 +718,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
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<void> {
|
||||
}
|
||||
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<Device> devices = await deviceManager.getDevices().toList();
|
||||
final List<Device> devices = await deviceManager.getDevices();
|
||||
if (devices.isEmpty) {
|
||||
return super.requiredArtifacts;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ void main() {
|
||||
return Future<List<Device>>.value(<Device>[mockDevice]);
|
||||
});
|
||||
when(deviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
||||
return Stream<Device>.value(mockDevice);
|
||||
return Future<List<Device>>.value(<Device>[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<Device> noDevices = <Device>[];
|
||||
when(mockDeviceManager.getDevices()).thenAnswer(
|
||||
(Invocation invocation) => Stream<Device>.fromIterable(noDevices)
|
||||
(Invocation invocation) => Future<List<Device>>.value(noDevices)
|
||||
);
|
||||
when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
|
||||
(Invocation invocation) => Future<List<Device>>.value(noDevices)
|
||||
@ -245,7 +245,7 @@ void main() {
|
||||
|
||||
// Called as part of requiredArtifacts()
|
||||
when(mockDeviceManager.getDevices()).thenAnswer(
|
||||
(Invocation invocation) => Stream<Device>.fromIterable(<Device>[])
|
||||
(Invocation invocation) => Future<List<Device>>.value(<Device>[])
|
||||
);
|
||||
// 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<Device>.fromIterable(<Device>[mockDevice]),
|
||||
(Invocation invocation) => Future<List<Device>>.value(<Device>[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<Device>.fromIterable(<Device>[
|
||||
fakeDevice,
|
||||
]);
|
||||
return Future<List<Device>>.value(<Device>[fakeDevice]);
|
||||
});
|
||||
when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
|
||||
(Invocation invocation) => Future<List<Device>>.value(<Device>[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<Device>.fromIterable(<Device>[
|
||||
return Future<List<Device>>.value(<Device>[
|
||||
MockDevice(TargetPlatform.android_arm),
|
||||
]);
|
||||
});
|
||||
@ -465,7 +463,7 @@ void main() {
|
||||
}));
|
||||
|
||||
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
||||
return Stream<Device>.fromIterable(<Device>[
|
||||
return Future<List<Device>>.value(<Device>[
|
||||
MockDevice(TargetPlatform.ios),
|
||||
]);
|
||||
});
|
||||
@ -476,7 +474,7 @@ void main() {
|
||||
}));
|
||||
|
||||
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
||||
return Stream<Device>.fromIterable(<Device>[
|
||||
return Future<List<Device>>.value(<Device>[
|
||||
MockDevice(TargetPlatform.ios),
|
||||
MockDevice(TargetPlatform.android_arm),
|
||||
]);
|
||||
@ -489,7 +487,7 @@ void main() {
|
||||
}));
|
||||
|
||||
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
||||
return Stream<Device>.fromIterable(<Device>[
|
||||
return Future<List<Device>>.value(<Device>[
|
||||
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<Device>.fromIterable(<Device>[fakeDevice])
|
||||
(Invocation invocation) => Future<List<Device>>.value(<Device>[fakeDevice])
|
||||
);
|
||||
when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
|
||||
(Invocation invocation) => Future<List<Device>>.value(<Device>[fakeDevice])
|
||||
@ -612,7 +610,7 @@ class TestRunCommand extends RunCommand {
|
||||
@override
|
||||
// ignore: must_call_super
|
||||
Future<void> validateCommand() async {
|
||||
devices = await deviceManager.getDevices().toList();
|
||||
devices = await deviceManager.getDevices();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ void main() {
|
||||
testUsingContext('getDevices', () async {
|
||||
// Test that DeviceManager.getDevices() doesn't throw.
|
||||
final DeviceManager deviceManager = DeviceManager();
|
||||
final List<Device> devices = await deviceManager.getDevices().toList();
|
||||
final List<Device> devices = await deviceManager.getDevices();
|
||||
expect(devices, isList);
|
||||
});
|
||||
|
||||
@ -30,7 +30,7 @@ void main() {
|
||||
final DeviceManager deviceManager = TestDeviceManager(devices);
|
||||
|
||||
Future<void> expectDevice(String id, List<Device> expected) async {
|
||||
expect(await deviceManager.getDevicesById(id).toList(), expected);
|
||||
expect(await deviceManager.getDevicesById(id), expected);
|
||||
}
|
||||
await expectDevice('01abfc49119c410e', <Device>[device2]);
|
||||
await expectDevice('Nexus 5X', <Device>[device2]);
|
||||
@ -170,9 +170,7 @@ class TestDeviceManager extends DeviceManager {
|
||||
bool isAlwaysSupportedOverride;
|
||||
|
||||
@override
|
||||
Stream<Device> getAllConnectedDevices() {
|
||||
return Stream<Device>.fromIterable(allDevices);
|
||||
}
|
||||
Future<List<Device>> getAllConnectedDevices() async => allDevices;
|
||||
|
||||
@override
|
||||
bool isDeviceSupportedForProject(Device device, FlutterProject flutterProject) {
|
||||
|
@ -201,16 +201,15 @@ class FakeDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<Device> getAllConnectedDevices() => Stream<Device>.fromIterable(devices);
|
||||
Future<List<Device>> getAllConnectedDevices() async => devices;
|
||||
|
||||
@override
|
||||
Stream<Device> getDevicesById(String deviceId) {
|
||||
return Stream<Device>.fromIterable(
|
||||
devices.where((Device device) => device.id == deviceId));
|
||||
Future<List<Device>> getDevicesById(String deviceId) async {
|
||||
return devices.where((Device device) => device.id == deviceId).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<Device> getDevices() {
|
||||
Future<List<Device>> getDevices() {
|
||||
return hasSpecifiedDeviceId
|
||||
? getDevicesById(specifiedDeviceId)
|
||||
: getAllConnectedDevices();
|
||||
|
Loading…
x
Reference in New Issue
Block a user