Skip to content

Commit

Permalink
Use term wireless instead of network (#124232)
Browse files Browse the repository at this point in the history
Rename variables, update comments, etc from `network` to `wireless` to keep it more uniform.

Also, move non-overriden messages related to device selection into the file they're used.

Part 7 in breakdown of flutter/flutter#121262.
  • Loading branch information
vashworth authored Apr 19, 2023
1 parent 14e191f commit 48bb3c0
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 94 deletions.
9 changes: 0 additions & 9 deletions packages/flutter_tools/lib/src/base/user_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,15 @@ class UserMessages {
String get flutterNoDevelopmentDevice =>
"Unable to locate a development device; please run 'flutter doctor' "
'for information about installing additional components.';
String flutterNoMatchingDevice(String deviceId) => 'No supported devices found with name or id '
"matching '$deviceId'.";
String get flutterNoDevicesFound => 'No devices found.';
String get flutterNoSupportedDevices => 'No supported devices connected.';
String flutterMissPlatformProjects(List<String> unsupportedDevicesType) =>
'If you would like your app to run on ${unsupportedDevicesType.join(' or ')}, consider running `flutter create .` to generate projects for these platforms.';
String get flutterFoundButUnsupportedDevices => 'The following devices were found, but are not supported by this project:';
String flutterFoundSpecifiedDevices(int count, String deviceId) =>
'Found $count devices with name or id matching $deviceId:';
String flutterChooseDevice(int option, String name, String deviceId) => '[$option]: $name ($deviceId)';
String get flutterChooseOne => 'Please choose one (or "q" to quit)';
String get flutterSpecifyDeviceWithAllOption =>
'More than one device connected; please specify a device with '
"the '-d <deviceId>' flag, or use '-d all' to act on all devices.";
String get flutterSpecifyDevice =>
'More than one device connected; please specify a device with '
"the '-d <deviceId>' flag.";
String get flutterNoConnectedDevices => 'No connected devices.';
String get flutterNoPubspec =>
'Error: No pubspec.yaml file found.\n'
'This command should be run from the root of your Flutter project.';
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter_tools/lib/src/commands/attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.

debugPort;
// Allow --ipv6 for iOS devices even if --debug-port and --debug-url
// are unknown
// are unknown.
if (!_isIOSDevice(targetDevice) &&
debugPort == null &&
debugUri == null &&
Expand Down Expand Up @@ -298,9 +298,9 @@ known, it can be explicitly provided to attach via the command-line, e.g.
final String ipv6Loopback = InternetAddress.loopbackIPv6.address;
final String ipv4Loopback = InternetAddress.loopbackIPv4.address;
final String hostname = usesIpv6 ? ipv6Loopback : ipv4Loopback;
final bool isNetworkDevice = (device is IOSDevice) && device.isWirelesslyConnected;
final bool isWirelessIOSDevice = (device is IOSDevice) && device.isWirelesslyConnected;

if ((debugPort == null && debugUri == null) || isNetworkDevice) {
if ((debugPort == null && debugUri == null) || isWirelessIOSDevice) {
if (device is FuchsiaDevice) {
final String? module = stringArg('module');
if (module == null) {
Expand All @@ -323,10 +323,10 @@ known, it can be explicitly provided to attach via the command-line, e.g.
// Protocol Discovery relies on logging. On iOS earlier than 13, logging is gathered using syslog.
// syslog is not available for iOS 13+. For iOS 13+, Protocol Discovery gathers logs from the VMService.
// Since we don't have access to the VMService yet, Protocol Discovery cannot be used for iOS 13+.
// Also, network devices must be found using mDNS and cannot use Protocol Discovery.
// Also, wireless devices must be found using mDNS and cannot use Protocol Discovery.
final bool compatibleWithProtocolDiscovery = (device is IOSDevice) &&
device.majorSdkVersion < IOSDeviceLogReader.minimumUniversalLoggingSdkVersion &&
!isNetworkDevice;
!isWirelessIOSDevice;

_logger.printStatus('Waiting for a connection from Flutter on ${device.name}...');
final Status discoveryStatus = _logger.startSpinner(
Expand Down Expand Up @@ -357,7 +357,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
appId,
device,
usesIpv6: usesIpv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: isWirelessIOSDevice,
deviceVmservicePort: devicePort,
);

Expand Down
10 changes: 5 additions & 5 deletions packages/flutter_tools/lib/src/commands/drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ class DriveCommand extends RunCommandBase {
);
}

// Network devices need `publish-port` to be enabled because it requires mDNS.
// If the flag wasn't provided as an actual argument and it's a network device,
// Wireless iOS devices need `publish-port` to be enabled because it requires mDNS.
// If the flag wasn't provided as an actual argument and it's a wireless device,
// change it to be enabled.
@override
Future<bool> get disablePortPublication async {
final ArgResults? localArgResults = argResults;
final Device? device = await targetedDevice;
final bool isNetworkDevice = device is IOSDevice && device.isWirelesslyConnected;
if (isNetworkDevice && localArgResults != null && !localArgResults.wasParsed('publish-port')) {
_logger.printTrace('Network device is being used. Changing `publish-port` to be enabled.');
final bool isWirelessIOSDevice = device is IOSDevice && device.isWirelesslyConnected;
if (isWirelessIOSDevice && localArgResults != null && !localArgResults.wasParsed('publish-port')) {
_logger.printTrace('A wireless iOS device is being used. Changing `publish-port` to be enabled.');
return false;
}
return !boolArg('publish-port');
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class RunCommand extends RunCommandBase {
bool isEmulator;
bool anyAndroidDevices = false;
bool anyIOSDevices = false;
bool anyIOSNetworkDevices = false;
bool anyWirelessIOSDevices = false;

if (devices == null || devices!.isEmpty) {
deviceType = 'none';
Expand All @@ -439,7 +439,7 @@ class RunCommand extends RunCommandBase {
anyAndroidDevices = platform == TargetPlatform.android;
anyIOSDevices = platform == TargetPlatform.ios;
if (device is IOSDevice && device.isWirelesslyConnected) {
anyIOSNetworkDevices = true;
anyWirelessIOSDevices = true;
}
deviceType = getNameForTargetPlatform(platform);
deviceOsVersion = await device.sdkNameAndVersion;
Expand All @@ -453,7 +453,7 @@ class RunCommand extends RunCommandBase {
anyAndroidDevices = anyAndroidDevices || (platform == TargetPlatform.android);
anyIOSDevices = anyIOSDevices || (platform == TargetPlatform.ios);
if (device is IOSDevice && device.isWirelesslyConnected) {
anyIOSNetworkDevices = true;
anyWirelessIOSDevices = true;
}
if (anyAndroidDevices && anyIOSDevices) {
break;
Expand All @@ -463,7 +463,7 @@ class RunCommand extends RunCommandBase {

String? iOSInterfaceType;
if (anyIOSDevices) {
iOSInterfaceType = anyIOSNetworkDevices ? 'wireless' : 'usb';
iOSInterfaceType = anyWirelessIOSDevices ? 'wireless' : 'usb';
}

String? androidEmbeddingVersion;
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/ios/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class IOSDevice extends Device {
deviceLogReader.debuggerStream = iosDeployDebugger;
}
}
// Don't port foward if debugging with a network device.
// Don't port foward if debugging with a wireless device.
vmServiceDiscovery = ProtocolDiscovery.vmService(
deviceLogReader,
portForwarder: isWirelesslyConnected ? null : portForwarder,
Expand Down Expand Up @@ -576,7 +576,7 @@ class IOSDevice extends Device {
this,
usesIpv6: ipv6,
deviceVmservicePort: serviceURL.port,
isNetworkDevice: true,
useDeviceIPAsHost: true,
);

mDNSLookupTimer.cancel();
Expand Down
54 changes: 30 additions & 24 deletions packages/flutter_tools/lib/src/mdns_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MDnsVmServiceDiscovery {
/// The [deviceVmservicePort] parameter may be used to specify which port
/// to find.
///
/// The [isNetworkDevice] parameter flags whether to get the device IP
/// The [useDeviceIPAsHost] parameter flags whether to get the device IP
/// and the [ipv6] parameter flags whether to get an iPv6 address
/// (otherwise it will get iPv4).
///
Expand All @@ -80,7 +80,7 @@ class MDnsVmServiceDiscovery {
String? applicationId,
int? deviceVmservicePort,
bool ipv6 = false,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
Duration timeout = const Duration(minutes: 10),
}) async {
// Poll for 5 seconds to see if there are already services running.
Expand All @@ -93,7 +93,7 @@ class MDnsVmServiceDiscovery {
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: ipv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: const Duration(seconds: 5),
);
if (results.isEmpty) {
Expand All @@ -102,7 +102,7 @@ class MDnsVmServiceDiscovery {
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: ipv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: timeout,
);
} else if (results.length > 1) {
Expand Down Expand Up @@ -134,7 +134,7 @@ class MDnsVmServiceDiscovery {
/// if multiple flutter apps are running on different devices, it will
/// only match with the device running the desired app.
///
/// The [isNetworkDevice] parameter flags whether to get the device IP
/// The [useDeviceIPAsHost] parameter flags whether to get the device IP
/// and the [ipv6] parameter flags whether to get an iPv6 address
/// (otherwise it will get iPv4).
///
Expand All @@ -148,7 +148,7 @@ class MDnsVmServiceDiscovery {
required String applicationId,
required int deviceVmservicePort,
bool ipv6 = false,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
Duration timeout = const Duration(minutes: 10),
}) async {
// Query for a specific application and device port.
Expand All @@ -157,7 +157,7 @@ class MDnsVmServiceDiscovery {
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: ipv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: timeout,
);
}
Expand All @@ -171,15 +171,15 @@ class MDnsVmServiceDiscovery {
String? applicationId,
int? deviceVmservicePort,
bool ipv6 = false,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
Duration timeout = const Duration(minutes: 10),
}) async {
final List<MDnsVmServiceDiscoveryResult> results = await _pollingVmService(
client,
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: ipv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: timeout,
quitOnFind: true,
);
Expand All @@ -194,7 +194,7 @@ class MDnsVmServiceDiscovery {
String? applicationId,
int? deviceVmservicePort,
bool ipv6 = false,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
required Duration timeout,
bool quitOnFind = false,
}) async {
Expand Down Expand Up @@ -263,9 +263,9 @@ class MDnsVmServiceDiscovery {
continue;
}

// Get the IP address of the service if using a network device.
// Get the IP address of the device if using the IP as the host.
InternetAddress? ipAddress;
if (isNetworkDevice) {
if (useDeviceIPAsHost) {
List<IPAddressResourceRecord> ipAddresses = await client
.lookup<IPAddressResourceRecord>(
ipv6
Expand Down Expand Up @@ -351,6 +351,9 @@ class MDnsVmServiceDiscovery {
/// Gets Dart VM Service Uri for `flutter attach`.
/// Executes an mDNS query and waits until a Dart VM Service is found.
///
/// When [useDeviceIPAsHost] is true, it will use the device's IP as the
/// host and will not forward the port.
///
/// Differs from `getVMServiceUriForLaunch` because it can search for any available Dart VM Service.
/// Since [applicationId] and [deviceVmservicePort] are optional, it can either look for any service
/// or a specific service matching [applicationId]/[deviceVmservicePort].
Expand All @@ -361,14 +364,14 @@ class MDnsVmServiceDiscovery {
bool usesIpv6 = false,
int? hostVmservicePort,
int? deviceVmservicePort,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
Duration timeout = const Duration(minutes: 10),
}) async {
final MDnsVmServiceDiscoveryResult? result = await queryForAttach(
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: usesIpv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: timeout,
);
return _handleResult(
Expand All @@ -378,13 +381,16 @@ class MDnsVmServiceDiscovery {
deviceVmservicePort: deviceVmservicePort,
hostVmservicePort: hostVmservicePort,
usesIpv6: usesIpv6,
isNetworkDevice: isNetworkDevice
useDeviceIPAsHost: useDeviceIPAsHost
);
}

/// Gets Dart VM Service Uri for `flutter run`.
/// Executes an mDNS query and waits until the Dart VM Service service is found.
///
/// When [useDeviceIPAsHost] is true, it will use the device's IP as the
/// host and will not forward the port.
///
/// Differs from `getVMServiceUriForAttach` because it only searches for a specific service.
/// This is enforced by [applicationId] and [deviceVmservicePort] being required.
Future<Uri?> getVMServiceUriForLaunch(
Expand All @@ -393,14 +399,14 @@ class MDnsVmServiceDiscovery {
bool usesIpv6 = false,
int? hostVmservicePort,
required int deviceVmservicePort,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
Duration timeout = const Duration(minutes: 10),
}) async {
final MDnsVmServiceDiscoveryResult? result = await queryForLaunch(
applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort,
ipv6: usesIpv6,
isNetworkDevice: isNetworkDevice,
useDeviceIPAsHost: useDeviceIPAsHost,
timeout: timeout,
);
return _handleResult(
Expand All @@ -410,7 +416,7 @@ class MDnsVmServiceDiscovery {
deviceVmservicePort: deviceVmservicePort,
hostVmservicePort: hostVmservicePort,
usesIpv6: usesIpv6,
isNetworkDevice: isNetworkDevice
useDeviceIPAsHost: useDeviceIPAsHost
);
}

Expand All @@ -421,7 +427,7 @@ class MDnsVmServiceDiscovery {
int? deviceVmservicePort,
int? hostVmservicePort,
bool usesIpv6 = false,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
}) async {
if (result == null) {
await _checkForIPv4LinkLocal(device);
Expand All @@ -430,7 +436,7 @@ class MDnsVmServiceDiscovery {
final String host;

final InternetAddress? ipAddress = result.ipAddress;
if (isNetworkDevice && ipAddress != null) {
if (useDeviceIPAsHost && ipAddress != null) {
host = ipAddress.address;
} else {
host = usesIpv6
Expand All @@ -443,7 +449,7 @@ class MDnsVmServiceDiscovery {
result.port,
hostVmservicePort,
result.authCode,
isNetworkDevice,
useDeviceIPAsHost,
);
}

Expand Down Expand Up @@ -529,7 +535,7 @@ Future<Uri> buildVMServiceUri(
int devicePort, [
int? hostVmservicePort,
String? authCode,
bool isNetworkDevice = false,
bool useDeviceIPAsHost = false,
]) async {
String path = '/';
if (authCode != null) {
Expand All @@ -543,8 +549,8 @@ Future<Uri> buildVMServiceUri(
hostVmservicePort ??= 0;

final int? actualHostPort;
if (isNetworkDevice) {
// When debugging with a network device, port forwarding is not required
if (useDeviceIPAsHost) {
// When using the device's IP as the host, port forwarding is not required
// so just use the device's port.
actualHostPort = devicePort;
} else {
Expand Down
Loading

0 comments on commit 48bb3c0

Please sign in to comment.