Unverified Commit cc26a1aa authored by Victoria Ashworth's avatar Victoria Ashworth Committed by GitHub

Update device filtering and introduce isConnected and connectionInterface (#121359)

Update device filtering and introduce isConnected and connectionInterface
parent c590086b
...@@ -883,7 +883,7 @@ class DeviceDomain extends Domain { ...@@ -883,7 +883,7 @@ class DeviceDomain extends Domain {
Future<List<Map<String, Object?>>> getDevices([ Map<String, Object?>? args ]) async { Future<List<Map<String, Object?>>> getDevices([ Map<String, Object?>? args ]) async {
return <Map<String, Object?>>[ return <Map<String, Object?>>[
for (final PollingDeviceDiscovery discoverer in _discoverers) for (final PollingDeviceDiscovery discoverer in _discoverers)
for (final Device device in await discoverer.devices) for (final Device device in await discoverer.devices())
await _deviceToMap(device), await _deviceToMap(device),
]; ];
} }
...@@ -1069,7 +1069,7 @@ class DeviceDomain extends Domain { ...@@ -1069,7 +1069,7 @@ class DeviceDomain extends Domain {
/// Return the device matching the deviceId field in the args. /// Return the device matching the deviceId field in the args.
Future<Device?> _getDevice(String? deviceId) async { Future<Device?> _getDevice(String? deviceId) async {
for (final PollingDeviceDiscovery discoverer in _discoverers) { for (final PollingDeviceDiscovery discoverer in _discoverers) {
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
Device? device; Device? device;
for (final Device localDevice in devices) { for (final Device localDevice in devices) {
if (localDevice.id == deviceId) { if (localDevice.id == deviceId) {
......
...@@ -62,7 +62,7 @@ class DevicesCommand extends FlutterCommand { ...@@ -62,7 +62,7 @@ class DevicesCommand extends FlutterCommand {
exitCode: 1); exitCode: 1);
} }
final List<Device> devices = await globals.deviceManager?.refreshAllConnectedDevices(timeout: deviceDiscoveryTimeout) ?? <Device>[]; final List<Device> devices = await globals.deviceManager?.refreshAllDevices(timeout: deviceDiscoveryTimeout) ?? <Device>[];
if (boolArgDeprecated('machine')) { if (boolArgDeprecated('machine')) {
await printDevicesAsJson(devices); await printDevicesAsJson(devices);
......
...@@ -209,7 +209,9 @@ class DriveCommand extends RunCommandBase { ...@@ -209,7 +209,9 @@ class DriveCommand extends RunCommandBase {
String? get applicationBinaryPath => stringArgDeprecated(FlutterOptions.kUseApplicationBinary); String? get applicationBinaryPath => stringArgDeprecated(FlutterOptions.kUseApplicationBinary);
Future<Device?> get targetedDevice async { Future<Device?> get targetedDevice async {
return findTargetDevice(includeUnsupportedDevices: applicationBinaryPath == null); return findTargetDevice(
includeDevicesUnsupportedByProject: applicationBinaryPath == null,
);
} }
// Network devices need `publish-port` to be enabled because it requires mDNS. // Network devices need `publish-port` to be enabled because it requires mDNS.
......
...@@ -36,7 +36,7 @@ class LogsCommand extends FlutterCommand { ...@@ -36,7 +36,7 @@ class LogsCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> verifyThenRunCommand(String? commandPath) async { Future<FlutterCommandResult> verifyThenRunCommand(String? commandPath) async {
device = await findTargetDevice(includeUnsupportedDevices: true); device = await findTargetDevice(includeDevicesUnsupportedByProject: true);
if (device == null) { if (device == null) {
throwToolExit(null); throwToolExit(null);
} }
......
This diff is collapsed.
...@@ -688,7 +688,7 @@ class DeviceValidator extends DoctorValidator { ...@@ -688,7 +688,7 @@ class DeviceValidator extends DoctorValidator {
@override @override
Future<ValidationResult> validate() async { Future<ValidationResult> validate() async {
final List<Device> devices = await _deviceManager.getAllConnectedDevices(); final List<Device> devices = await _deviceManager.getAllDevices();
List<ValidationMessage> installedMessages = <ValidationMessage>[]; List<ValidationMessage> installedMessages = <ValidationMessage>[];
if (devices.isNotEmpty) { if (devices.isNotEmpty) {
installedMessages = (await Device.descriptions(devices)) installedMessages = (await Device.descriptions(devices))
......
...@@ -57,11 +57,14 @@ class ProxiedDevices extends DeviceDiscovery { ...@@ -57,11 +57,14 @@ class ProxiedDevices extends DeviceDiscovery {
List<Device>? _devices; List<Device>? _devices;
@override @override
Future<List<Device>> get devices async => Future<List<Device>> devices({DeviceDiscoveryFilter? filter}) async =>
_devices ?? await discoverDevices(); _devices ?? await discoverDevices(filter: filter);
@override @override
Future<List<Device>> discoverDevices({Duration? timeout}) async { Future<List<Device>> discoverDevices({
Duration? timeout,
DeviceDiscoveryFilter? filter
}) async {
final List<Map<String, Object?>> discoveredDevices = _cast<List<dynamic>>(await connection.sendRequest('device.discoverDevices')).cast<Map<String, Object?>>(); final List<Map<String, Object?>> discoveredDevices = _cast<List<dynamic>>(await connection.sendRequest('device.discoverDevices')).cast<Map<String, Object?>>();
final List<ProxiedDevice> devices = <ProxiedDevice>[ final List<ProxiedDevice> devices = <ProxiedDevice>[
for (final Map<String, Object?> device in discoveredDevices) for (final Map<String, Object?> device in discoveredDevices)
......
...@@ -1491,7 +1491,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1491,7 +1491,7 @@ abstract class FlutterCommand extends Command<void> {
/// If no device can be found that meets specified criteria, /// If no device can be found that meets specified criteria,
/// then print an error message and return null. /// then print an error message and return null.
Future<List<Device>?> findAllTargetDevices({ Future<List<Device>?> findAllTargetDevices({
bool includeUnsupportedDevices = false, bool includeDevicesUnsupportedByProject = false,
}) async { }) async {
if (!globals.doctor!.canLaunchAnything) { if (!globals.doctor!.canLaunchAnything) {
globals.printError(userMessages.flutterNoDevelopmentDevice); globals.printError(userMessages.flutterNoDevelopmentDevice);
...@@ -1499,14 +1499,14 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1499,14 +1499,14 @@ abstract class FlutterCommand extends Command<void> {
} }
final DeviceManager deviceManager = globals.deviceManager!; final DeviceManager deviceManager = globals.deviceManager!;
List<Device> devices = await deviceManager.findTargetDevices( List<Device> devices = await deviceManager.findTargetDevices(
includeUnsupportedDevices ? null : FlutterProject.current(), includeDevicesUnsupportedByProject: includeDevicesUnsupportedByProject,
timeout: deviceDiscoveryTimeout, timeout: deviceDiscoveryTimeout,
); );
if (devices.isEmpty) { if (devices.isEmpty) {
if (deviceManager.hasSpecifiedDeviceId) { if (deviceManager.hasSpecifiedDeviceId) {
globals.logger.printStatus(userMessages.flutterNoMatchingDevice(deviceManager.specifiedDeviceId!)); globals.logger.printStatus(userMessages.flutterNoMatchingDevice(deviceManager.specifiedDeviceId!));
final List<Device> allDevices = await deviceManager.getAllConnectedDevices(); final List<Device> allDevices = await deviceManager.getAllDevices();
if (allDevices.isNotEmpty) { if (allDevices.isNotEmpty) {
globals.logger.printStatus(''); globals.logger.printStatus('');
globals.logger.printStatus('The following devices were found:'); globals.logger.printStatus('The following devices were found:');
...@@ -1543,7 +1543,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1543,7 +1543,7 @@ abstract class FlutterCommand extends Command<void> {
} else { } else {
// Show an error message asking the user to specify `-d all` if they // Show an error message asking the user to specify `-d all` if they
// want to run on multiple devices. // want to run on multiple devices.
final List<Device> allDevices = await deviceManager.getAllConnectedDevices(); final List<Device> allDevices = await deviceManager.getAllDevices();
globals.logger.printStatus(userMessages.flutterSpecifyDeviceWithAllOption); globals.logger.printStatus(userMessages.flutterSpecifyDeviceWithAllOption);
globals.logger.printStatus(''); globals.logger.printStatus('');
await Device.printDevices(allDevices, globals.logger); await Device.printDevices(allDevices, globals.logger);
...@@ -1607,18 +1607,20 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1607,18 +1607,20 @@ abstract class FlutterCommand extends Command<void> {
/// If a device cannot be found that meets specified criteria, /// If a device cannot be found that meets specified criteria,
/// then print an error message and return null. /// then print an error message and return null.
/// ///
/// If [includeUnsupportedDevices] is true, the tool does not filter /// If [includeDevicesUnsupportedByProject] is true, the tool does not filter
/// the list by the current project support list. /// the list by the current project support list.
Future<Device?> findTargetDevice({ Future<Device?> findTargetDevice({
bool includeUnsupportedDevices = false, bool includeDevicesUnsupportedByProject = false,
}) async { }) async {
List<Device>? deviceList = await findAllTargetDevices(includeUnsupportedDevices: includeUnsupportedDevices); List<Device>? deviceList = await findAllTargetDevices(
includeDevicesUnsupportedByProject: includeDevicesUnsupportedByProject,
);
if (deviceList == null) { if (deviceList == null) {
return null; return null;
} }
if (deviceList.length > 1) { if (deviceList.length > 1) {
globals.printStatus(userMessages.flutterSpecifyDevice); globals.printStatus(userMessages.flutterSpecifyDevice);
deviceList = await globals.deviceManager!.getAllConnectedDevices(); deviceList = await globals.deviceManager!.getAllDevices();
globals.printStatus(''); globals.printStatus('');
await Device.printDevices(deviceList, globals.logger); await Device.printDevices(deviceList, globals.logger);
return null; return null;
......
...@@ -1240,6 +1240,9 @@ class FakeAndroidDevice extends Fake implements AndroidDevice { ...@@ -1240,6 +1240,9 @@ class FakeAndroidDevice extends Fake implements AndroidDevice {
@override @override
bool isSupported() => true; bool isSupported() => true;
@override
bool get isConnected => true;
@override @override
bool get supportsHotRestart => true; bool get supportsHotRestart => true;
...@@ -1340,6 +1343,9 @@ class FakeIOSDevice extends Fake implements IOSDevice { ...@@ -1340,6 +1343,9 @@ class FakeIOSDevice extends Fake implements IOSDevice {
@override @override
bool isSupportedForProject(FlutterProject project) => true; bool isSupportedForProject(FlutterProject project) => true;
@override
bool get isConnected => true;
} }
class FakeMDnsClient extends Fake implements MDnsClient { class FakeMDnsClient extends Fake implements MDnsClient {
......
...@@ -50,7 +50,7 @@ void main() { ...@@ -50,7 +50,7 @@ void main() {
testUsingContext("get devices' platform types", () async { testUsingContext("get devices' platform types", () async {
final List<String> platformTypes = Device.devicesPlatformTypes( final List<String> platformTypes = Device.devicesPlatformTypes(
await globals.deviceManager!.getAllConnectedDevices(), await globals.deviceManager!.getAllDevices(),
); );
expect(platformTypes, <String>['android', 'web']); expect(platformTypes, <String>['android', 'web']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -134,12 +134,14 @@ class _FakeDeviceManager extends DeviceManager { ...@@ -134,12 +134,14 @@ class _FakeDeviceManager extends DeviceManager {
_FakeDeviceManager() : super(logger: testLogger); _FakeDeviceManager() : super(logger: testLogger);
@override @override
Future<List<Device>> getAllConnectedDevices() => Future<List<Device>> getAllDevices({DeviceDiscoveryFilter? filter}) =>
Future<List<Device>>.value(fakeDevices.map((FakeDeviceJsonData d) => d.dev).toList()); Future<List<Device>>.value(fakeDevices.map((FakeDeviceJsonData d) => d.dev).toList());
@override @override
Future<List<Device>> refreshAllConnectedDevices({Duration? timeout}) => Future<List<Device>> refreshAllDevices({
getAllConnectedDevices(); Duration? timeout,
DeviceDiscoveryFilter? filter,
}) => getAllDevices(filter: filter);
@override @override
Future<List<String>> getDeviceDiagnostics() => Future<List<String>>.value( Future<List<String>> getDeviceDiagnostics() => Future<List<String>>.value(
...@@ -154,11 +156,16 @@ class NoDevicesManager extends DeviceManager { ...@@ -154,11 +156,16 @@ class NoDevicesManager extends DeviceManager {
NoDevicesManager() : super(logger: testLogger); NoDevicesManager() : super(logger: testLogger);
@override @override
Future<List<Device>> getAllConnectedDevices() async => <Device>[]; Future<List<Device>> getAllDevices({
DeviceDiscoveryFilter? filter,
}) async => <Device>[];
@override @override
Future<List<Device>> refreshAllConnectedDevices({Duration? timeout}) => Future<List<Device>> refreshAllDevices({
getAllConnectedDevices(); Duration? timeout,
DeviceDiscoveryFilter? filter,
}) =>
getAllDevices();
@override @override
List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[]; List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[];
......
...@@ -1192,7 +1192,9 @@ class FakeDeviceManager extends Fake implements DeviceManager { ...@@ -1192,7 +1192,9 @@ class FakeDeviceManager extends Fake implements DeviceManager {
List<Device> devices = <Device>[]; List<Device> devices = <Device>[];
@override @override
Future<List<Device>> getAllConnectedDevices() async => devices; Future<List<Device>> getAllDevices({
DeviceDiscoveryFilter? filter,
}) async => devices;
@override @override
Future<List<String>> getDeviceDiagnostics() async => diagnostics; Future<List<String>> getDeviceDiagnostics() async => diagnostics;
......
...@@ -587,10 +587,16 @@ class FakeDeviceManager extends Fake implements DeviceManager { ...@@ -587,10 +587,16 @@ class FakeDeviceManager extends Fake implements DeviceManager {
String? specifiedDeviceId; String? specifiedDeviceId;
@override @override
Future<List<Device>> getDevices() async => devices; Future<List<Device>> getDevices({
DeviceDiscoveryFilter? filter,
}) async => devices;
@override @override
Future<List<Device>> findTargetDevices(FlutterProject? flutterProject, {Duration? timeout, bool promptUserToChooseDevice = true}) async => devices; Future<List<Device>> findTargetDevices({
bool includeDevicesUnsupportedByProject = false,
Duration? timeout,
bool promptUserToChooseDevice = true,
}) async => devices;
} }
/// A [FlutterDriverFactory] that creates a [NeverEndingDriverService]. /// A [FlutterDriverFactory] that creates a [NeverEndingDriverService].
......
...@@ -98,7 +98,7 @@ void main() { ...@@ -98,7 +98,7 @@ void main() {
final ProxiedDevices proxiedDevices = ProxiedDevices(clientDaemonConnection, logger: bufferLogger); final ProxiedDevices proxiedDevices = ProxiedDevices(clientDaemonConnection, logger: bufferLogger);
final List<Device> devices = await proxiedDevices.devices; final List<Device> devices = await proxiedDevices.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices[0]; final Device device = devices[0];
final bool supportsRuntimeMode = await device.supportsRuntimeMode(BuildMode.release); final bool supportsRuntimeMode = await device.supportsRuntimeMode(BuildMode.release);
...@@ -121,7 +121,7 @@ void main() { ...@@ -121,7 +121,7 @@ void main() {
final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader(); final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader();
fakeDevice.logReader = fakeLogReader; fakeDevice.logReader = fakeLogReader;
final List<Device> devices = await proxiedDevices.devices; final List<Device> devices = await proxiedDevices.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices[0]; final Device device = devices[0];
final DeviceLogReader logReader = await device.getLogReader(); final DeviceLogReader logReader = await device.getLogReader();
...@@ -153,7 +153,7 @@ void main() { ...@@ -153,7 +153,7 @@ void main() {
dummyApplicationBinary.writeAsStringSync('dummy content'); dummyApplicationBinary.writeAsStringSync('dummy content');
prebuiltApplicationPackage.applicationPackage = dummyApplicationBinary; prebuiltApplicationPackage.applicationPackage = dummyApplicationBinary;
final List<Device> devices = await proxiedDevices.devices; final List<Device> devices = await proxiedDevices.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices[0]; final Device device = devices[0];
...@@ -200,7 +200,7 @@ void main() { ...@@ -200,7 +200,7 @@ void main() {
final ProxiedDevices proxiedDevices = ProxiedDevices(clientDaemonConnection, logger: bufferLogger); final ProxiedDevices proxiedDevices = ProxiedDevices(clientDaemonConnection, logger: bufferLogger);
final List<Device> devices = await proxiedDevices.devices; final List<Device> devices = await proxiedDevices.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices[0]; final Device device = devices[0];
......
...@@ -1054,6 +1054,9 @@ class FakeDevice extends Fake implements Device { ...@@ -1054,6 +1054,9 @@ class FakeDevice extends Fake implements Device {
@override @override
bool get supportsFastStart => false; bool get supportsFastStart => false;
@override
bool get isConnected => true;
bool supported = true; bool supported = true;
@override @override
......
...@@ -920,7 +920,9 @@ class _FakeDeviceManager extends DeviceManager { ...@@ -920,7 +920,9 @@ class _FakeDeviceManager extends DeviceManager {
final List<Device> _connectedDevices; final List<Device> _connectedDevices;
@override @override
Future<List<Device>> getAllConnectedDevices() async => _connectedDevices; Future<List<Device>> getAllDevices({
DeviceDiscoveryFilter? filter,
}) async => _connectedDevices;
@override @override
List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[]; List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[];
......
...@@ -88,7 +88,10 @@ class FakeDeviceManager extends Fake implements DeviceManager { ...@@ -88,7 +88,10 @@ class FakeDeviceManager extends Fake implements DeviceManager {
String? specifiedDeviceId; String? specifiedDeviceId;
@override @override
Future<List<Device>> refreshAllConnectedDevices({Duration? timeout}) async { Future<List<Device>> refreshAllDevices({
Duration? timeout,
DeviceDiscoveryFilter? filter,
}) async {
return devices; return devices;
} }
} }
...@@ -166,7 +166,7 @@ void main() { ...@@ -166,7 +166,7 @@ void main() {
directory: dir, directory: dir,
logger: BufferLogger.test() logger: BufferLogger.test()
) )
).devices, <Device>[]); ).devices(), <Device>[]);
}); });
testWithoutContext('CustomDevice: no devices listed if custom devices feature flag disabled', () async { testWithoutContext('CustomDevice: no devices listed if custom devices feature flag disabled', () async {
...@@ -184,7 +184,7 @@ void main() { ...@@ -184,7 +184,7 @@ void main() {
directory: dir, directory: dir,
logger: BufferLogger.test() logger: BufferLogger.test()
) )
).devices, <Device>[]); ).devices(), <Device>[]);
}); });
testWithoutContext('CustomDevices.devices', () async { testWithoutContext('CustomDevices.devices', () async {
...@@ -208,7 +208,7 @@ void main() { ...@@ -208,7 +208,7 @@ void main() {
directory: dir, directory: dir,
logger: BufferLogger.test() logger: BufferLogger.test()
) )
).devices, ).devices(),
hasLength(1) hasLength(1)
); );
}); });
......
...@@ -67,7 +67,7 @@ void main() { ...@@ -67,7 +67,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
).devices, <Device>[]); ).devices(), <Device>[]);
}); });
testWithoutContext('LinuxDevice: no devices listed if Linux feature flag disabled', () async { testWithoutContext('LinuxDevice: no devices listed if Linux feature flag disabled', () async {
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
).devices, <Device>[]); ).devices(), <Device>[]);
}); });
testWithoutContext('LinuxDevice: devices', () async { testWithoutContext('LinuxDevice: devices', () async {
...@@ -89,7 +89,7 @@ void main() { ...@@ -89,7 +89,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
).devices, hasLength(1)); ).devices(), hasLength(1));
}); });
testWithoutContext('LinuxDevice has well known id "linux"', () async { testWithoutContext('LinuxDevice has well known id "linux"', () async {
......
...@@ -93,7 +93,7 @@ void main() { ...@@ -93,7 +93,7 @@ void main() {
featureFlags: TestFeatureFlags(isMacOSEnabled: true), featureFlags: TestFeatureFlags(isMacOSEnabled: true),
platform: linux, platform: linux,
), ),
).devices, isEmpty); ).devices(), isEmpty);
}); });
testWithoutContext('No devices listed if platform is supported and feature is disabled', () async { testWithoutContext('No devices listed if platform is supported and feature is disabled', () async {
...@@ -109,7 +109,7 @@ void main() { ...@@ -109,7 +109,7 @@ void main() {
), ),
); );
expect(await macOSDevices.devices, isEmpty); expect(await macOSDevices.devices(), isEmpty);
}); });
testWithoutContext('devices listed if platform is supported and feature is enabled', () async { testWithoutContext('devices listed if platform is supported and feature is enabled', () async {
...@@ -125,7 +125,7 @@ void main() { ...@@ -125,7 +125,7 @@ void main() {
), ),
); );
expect(await macOSDevices.devices, hasLength(1)); expect(await macOSDevices.devices(), hasLength(1));
}); });
testWithoutContext('has a well known device id macos', () async { testWithoutContext('has a well known device id macos', () async {
......
...@@ -50,7 +50,7 @@ void main() { ...@@ -50,7 +50,7 @@ void main() {
); );
expect(discoverer.supportsPlatform, isTrue); expect(discoverer.supportsPlatform, isTrue);
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
expect(devices, isEmpty); expect(devices, isEmpty);
}); });
...@@ -66,7 +66,7 @@ void main() { ...@@ -66,7 +66,7 @@ void main() {
); );
expect(discoverer.supportsPlatform, isTrue); expect(discoverer.supportsPlatform, isTrue);
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
expect(devices, isEmpty); expect(devices, isEmpty);
}); });
...@@ -82,7 +82,7 @@ void main() { ...@@ -82,7 +82,7 @@ void main() {
); );
expect(discoverer.supportsPlatform, isTrue); expect(discoverer.supportsPlatform, isTrue);
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
expect(devices, isEmpty); expect(devices, isEmpty);
}); });
...@@ -98,7 +98,7 @@ void main() { ...@@ -98,7 +98,7 @@ void main() {
); );
expect(discoverer.supportsPlatform, isTrue); expect(discoverer.supportsPlatform, isTrue);
List<Device> devices = await discoverer.devices; List<Device> devices = await discoverer.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices.single; final Device device = devices.single;
......
...@@ -47,7 +47,7 @@ void main() { ...@@ -47,7 +47,7 @@ void main() {
testWithoutContext('no device', () async { testWithoutContext('no device', () async {
final FlutterTesterDevices discoverer = setUpFlutterTesterDevices(); final FlutterTesterDevices discoverer = setUpFlutterTesterDevices();
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
expect(devices, isEmpty); expect(devices, isEmpty);
}); });
...@@ -55,7 +55,7 @@ void main() { ...@@ -55,7 +55,7 @@ void main() {
FlutterTesterDevices.showFlutterTesterDevice = true; FlutterTesterDevices.showFlutterTesterDevice = true;
final FlutterTesterDevices discoverer = setUpFlutterTesterDevices(); final FlutterTesterDevices discoverer = setUpFlutterTesterDevices();
final List<Device> devices = await discoverer.devices; final List<Device> devices = await discoverer.devices();
expect(devices, hasLength(1)); expect(devices, hasLength(1));
final Device device = devices.single; final Device device = devices.single;
......
...@@ -48,7 +48,7 @@ void main() { ...@@ -48,7 +48,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
).devices, <Device>[]); ).devices(), <Device>[]);
}); });
testWithoutContext('WindowsDevices lists a devices if the workflow is supported', () async { testWithoutContext('WindowsDevices lists a devices if the workflow is supported', () async {
...@@ -61,7 +61,7 @@ void main() { ...@@ -61,7 +61,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
).devices, hasLength(1)); ).devices(), hasLength(1));
}); });
testWithoutContext('isSupportedForProject is true with editable host app', () async { testWithoutContext('isSupportedForProject is true with editable host app', () async {
......
...@@ -207,21 +207,31 @@ class FakeDeviceManager implements DeviceManager { ...@@ -207,21 +207,31 @@ class FakeDeviceManager implements DeviceManager {
} }
@override @override
Future<List<Device>> getAllConnectedDevices() async => devices; Future<List<Device>> getAllDevices({
DeviceDiscoveryFilter? filter,
}) async => devices;
@override @override
Future<List<Device>> refreshAllConnectedDevices({ Duration? timeout }) async => devices; Future<List<Device>> refreshAllDevices({
Duration? timeout,
DeviceDiscoveryFilter? filter,
}) async => devices;
@override @override
Future<List<Device>> getDevicesById(String deviceId) async { Future<List<Device>> getDevicesById(
String deviceId, {
DeviceDiscoveryFilter? filter,
}) async {
return devices.where((Device device) => device.id == deviceId).toList(); return devices.where((Device device) => device.id == deviceId).toList();
} }
@override @override
Future<List<Device>> getDevices() { Future<List<Device>> getDevices({
DeviceDiscoveryFilter? filter,
}) {
return hasSpecifiedDeviceId return hasSpecifiedDeviceId
? getDevicesById(specifiedDeviceId!) ? getDevicesById(specifiedDeviceId!, filter: filter)
: getAllConnectedDevices(); : getAllDevices(filter: filter);
} }
void addDevice(Device device) => devices.add(device); void addDevice(Device device) => devices.add(device);
...@@ -236,16 +246,27 @@ class FakeDeviceManager implements DeviceManager { ...@@ -236,16 +246,27 @@ class FakeDeviceManager implements DeviceManager {
List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[]; List<DeviceDiscovery> get deviceDiscoverers => <DeviceDiscovery>[];
@override @override
bool isDeviceSupportedForProject(Device device, FlutterProject? flutterProject) { Future<List<Device>> findTargetDevices({
return device.isSupportedForProject(flutterProject!); bool includeDevicesUnsupportedByProject = false,
Duration? timeout,
bool promptUserToChooseDevice = true,
}) async {
return devices;
} }
@override @override
Future<List<Device>> findTargetDevices(FlutterProject? flutterProject, { Duration? timeout, bool promptUserToChooseDevice = true }) async { DeviceDiscoverySupportFilter deviceSupportFilter({
return devices; bool includeDevicesUnsupportedByProject = false,
FlutterProject? flutterProject,
}) {
return TestDeviceDiscoverySupportFilter();
} }
} }
class TestDeviceDiscoverySupportFilter extends Fake implements DeviceDiscoverySupportFilter {
TestDeviceDiscoverySupportFilter();
}
class FakeAndroidLicenseValidator extends Fake implements AndroidLicenseValidator { class FakeAndroidLicenseValidator extends Fake implements AndroidLicenseValidator {
@override @override
Future<LicensesAccepted> get licensesAccepted async => LicensesAccepted.all; Future<LicensesAccepted> get licensesAccepted async => LicensesAccepted.all;
......
...@@ -62,6 +62,8 @@ class FakeDevice extends Device { ...@@ -62,6 +62,8 @@ class FakeDevice extends Device {
bool ephemeral = true, bool ephemeral = true,
bool isSupported = true, bool isSupported = true,
bool isSupportedForProject = true, bool isSupportedForProject = true,
this.isConnected = true,
this.connectionInterface = DeviceConnectionInterface.attached,
PlatformType type = PlatformType.web, PlatformType type = PlatformType.web,
LaunchResult? launchResult, LaunchResult? launchResult,
}) : _isSupported = isSupported, }) : _isSupported = isSupported,
...@@ -118,6 +120,12 @@ class FakeDevice extends Device { ...@@ -118,6 +120,12 @@ class FakeDevice extends Device {
@override @override
bool isSupported() => _isSupported; bool isSupported() => _isSupported;
@override
bool isConnected;
@override
DeviceConnectionInterface connectionInterface;
@override @override
Future<bool> isLocalEmulator = Future<bool>.value(true); Future<bool> isLocalEmulator = Future<bool>.value(true);
...@@ -174,7 +182,10 @@ class FakePollingDeviceDiscovery extends PollingDeviceDiscovery { ...@@ -174,7 +182,10 @@ class FakePollingDeviceDiscovery extends PollingDeviceDiscovery {
bool discoverDevicesCalled = false; bool discoverDevicesCalled = false;
@override @override
Future<List<Device>> discoverDevices({Duration? timeout}) { Future<List<Device>> discoverDevices({
Duration? timeout,
DeviceDiscoveryFilter? filter,
}) {
discoverDevicesCalled = true; discoverDevicesCalled = true;
return super.discoverDevices(timeout: timeout); return super.discoverDevices(timeout: timeout);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment