Allow --ipv6 flag for flutter attach on iOS devices (#123822)

Allow --ipv6 flag for flutter attach on iOS devices
This commit is contained in:
Victoria Ashworth
2023-04-04 17:33:28 -05:00
committed by GitHub
parent dbc18bbdb8
commit 842873c2fc
4 changed files with 81 additions and 13 deletions

View File

@@ -219,11 +219,19 @@ known, it can be explicitly provided to attach via the command-line, e.g.
MacOSDesignedForIPadDevices.allowDiscovery = true;
await super.validateCommand();
if (await findTargetDevice() == null) {
final Device? targetDevice = await findTargetDevice();
if (targetDevice == null) {
throwToolExit(null);
}
debugPort;
if (debugPort == null && debugUri == null && argResults!.wasParsed(FlutterCommand.ipv6Flag)) {
// Allow --ipv6 for iOS devices even if --debug-port and --debug-url
// are unknown
if (!_isIOSDevice(targetDevice) &&
debugPort == null &&
debugUri == null &&
argResults!.wasParsed(FlutterCommand.ipv6Flag)) {
throwToolExit(
'When the --debug-port or --debug-url is unknown, this command determines '
'the value of --ipv6 on its own.',
@@ -311,7 +319,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
}
rethrow;
}
} else if ((device is IOSDevice) || (device is IOSSimulator) || (device is MacOSDesignedForIPadDevice)) {
} else if (_isIOSDevice(device)) {
// 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+.
@@ -395,8 +403,6 @@ known, it can be explicitly provided to attach via the command-line, e.g.
);
_logger.printStatus('Waiting for a connection from Flutter on ${device.name}...');
vmServiceUri = vmServiceDiscovery.uris;
// Determine ipv6 status from the scanned logs.
usesIpv6 = vmServiceDiscovery.ipv6;
}
} else {
vmServiceUri = Stream<Uri>
@@ -544,6 +550,12 @@ known, it can be explicitly provided to attach via the command-line, e.g.
}
Future<void> _validateArguments() async { }
bool _isIOSDevice(Device device) {
return (device is IOSDevice) ||
(device is IOSSimulator) ||
(device is MacOSDesignedForIPadDevice);
}
}
class HotRunnerFactory {

View File

@@ -20,9 +20,10 @@ class ProtocolDiscovery {
required this.throttleDuration,
this.hostPort,
this.devicePort,
required this.ipv6,
required bool ipv6,
required Logger logger,
}) : _logger = logger {
}) : _logger = logger,
_ipv6 = ipv6 {
_deviceLogSubscription = logReader.logLines.listen(
_handleLine,
onDone: _stopScrapingLogs,
@@ -56,7 +57,7 @@ class ProtocolDiscovery {
final DevicePortForwarder? portForwarder;
final int? hostPort;
final int? devicePort;
final bool ipv6;
final bool _ipv6;
final Logger _logger;
/// The time to wait before forwarding a new VM Service URIs from [logReader].
@@ -144,7 +145,7 @@ class ProtocolDiscovery {
hostUri = deviceUri.replace(port: actualHostPort);
}
if (InternetAddress(hostUri.host).isLoopback && ipv6) {
if (InternetAddress(hostUri.host).isLoopback && _ipv6) {
hostUri = hostUri.replace(host: InternetAddress.loopbackIPv6.host);
}
return hostUri;

View File

@@ -603,8 +603,7 @@ abstract class FlutterCommand extends Command<void> {
argParser.addFlag(ipv6Flag,
negatable: false,
help: 'Binds to IPv6 localhost instead of IPv4 when the flutter tool '
'forwards the host port to a device port. Not used when the '
'"--debug-port" flag is not set.',
'forwards the host port to a device port.',
hide: !verboseHelp,
);
_usesIpv6Flag = true;