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