Skip to content

Conversation

@vashworth
Copy link
Contributor

This PR moves some of the logic involved in finding target devices into its own class and file. Reason for this is in future updates the logic will be more complex and there will be a Mac-specific class that inherits from the TargetDevices class. It also moves some logic from the flutter devices command to its own class for the same reason.

Part 2 in breakdown of #121262.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems tool Affects the "flutter" command-line tool. See also t: labels. labels Mar 3, 2023
}) async { }
}

class FakeDeviceManager extends Fake implements DeviceManager {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this so it uses the FakeDeviceManager in context.dart instead.

@vashworth vashworth changed the title Wireless device discovery part 2 Move target devices logic to its own classes and file Mar 3, 2023
@vashworth vashworth marked this pull request as ready for review March 3, 2023 22:08
@vashworth vashworth requested a review from jmagman March 3, 2023 22:08
Comment on lines +225 to +227
return devices.where((Device device) {
return device.id == deviceId || device.id.startsWith(deviceId);
}).toList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change this logic in this refactoring PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was needed for this test.

testUsingContext('show error when multiple devices found', () async {
testDeviceManager.specifiedDeviceId = 'device';
testDeviceManager.addDevice(device1);
testDeviceManager.addDevice(device2);
final TargetDevices targetDevices = TargetDevices(
deviceManager: testDeviceManager,
logger: logger,
);
final List<Device>? devices = await targetDevices.findAllTargetDevices();
expect(devices, null);
expect(logger.statusText, contains(UserMessages().flutterFoundSpecifiedDevices(2, 'device')));
});

In the old version of this test, findAllTargetDevices basically mocked the returned device list so it always returned the device list given. So the mocked getDevicesById was never actually called.

@vashworth
Copy link
Contributor Author

@jmagman I made an adjustment - moving the logic that prioritizes ephemeral devices to the DeviceManager to make it more accessible for a g3fix

Comment on lines 259 to 261
List<Device> prioritizeEphemeralDevices(List<Device> devices) {
return devices;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed a few places in your code in previous PRs where you could have used =>, not sure if you're aware of that arrow dart syntax (this isn't even a nit comment, you don't have to change this).

///
/// Note: ephemeral is nullable for device types where this is not well
/// defined.
List<Device> prioritizeEphemeralDevices(List<Device> devices){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name sounds like it should return a bool, like whether it's prioritized, or that it returns a list of the devices with the ephemeral devices sorted first.
How about filterToSingleEphemeralDeviceIfNeeded (or something better than that, it's clunky)?

Copy link
Contributor Author

@vashworth vashworth Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of getSoleEphemeralDevice and change return type to Device? and return null if not found?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the Device? pattern better. How about getSingleEphemeralDevice instead of "sole" since "single" has a meaning in dart (though we def don't need to throw the StateError: https://api.dart.dev/be/180791/dart-core/Iterable/single.html)

@vashworth vashworth added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 13, 2023
@auto-submit auto-submit bot merged commit ee42a30 into flutter:master Mar 13, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
@vashworth vashworth deleted the wireless_device_discovery_part_2 branch September 27, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants