Unverified Commit 53e04de6 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate mdns_discovery and ios simulator to null safety (#92124)

parent b0810bc9
...@@ -44,7 +44,7 @@ import 'flutter_features.dart'; ...@@ -44,7 +44,7 @@ import 'flutter_features.dart';
import 'fuchsia/fuchsia_device.dart' show FuchsiaDeviceTools; import 'fuchsia/fuchsia_device.dart' show FuchsiaDeviceTools;
import 'fuchsia/fuchsia_sdk.dart' show FuchsiaSdk, FuchsiaArtifacts; import 'fuchsia/fuchsia_sdk.dart' show FuchsiaSdk, FuchsiaArtifacts;
import 'fuchsia/fuchsia_workflow.dart' show FuchsiaWorkflow, fuchsiaWorkflow; import 'fuchsia/fuchsia_workflow.dart' show FuchsiaWorkflow, fuchsiaWorkflow;
import 'globals.dart' as globals; import 'globals_null_migrated.dart' as globals;
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
import 'ios/iproxy.dart'; import 'ios/iproxy.dart';
import 'ios/simulators.dart'; import 'ios/simulators.dart';
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
import 'base/context.dart'; import 'base/context.dart';
import 'doctor.dart'; import 'doctor.dart';
import 'ios/simulators.dart';
export 'globals_null_migrated.dart'; export 'globals_null_migrated.dart';
Doctor get doctor => context.get<Doctor>(); Doctor get doctor => context.get<Doctor>();
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
...@@ -31,6 +31,7 @@ import 'device.dart'; ...@@ -31,6 +31,7 @@ import 'device.dart';
import 'fuchsia/fuchsia_sdk.dart'; import 'fuchsia/fuchsia_sdk.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
import 'ios/plist_parser.dart'; import 'ios/plist_parser.dart';
import 'ios/simulators.dart';
import 'ios/xcodeproj.dart'; import 'ios/xcodeproj.dart';
import 'macos/cocoapods.dart'; import 'macos/cocoapods.dart';
import 'macos/cocoapods_validator.dart'; import 'macos/cocoapods_validator.dart';
...@@ -54,6 +55,7 @@ Config get config => context.get<Config>()!; ...@@ -54,6 +55,7 @@ Config get config => context.get<Config>()!;
CrashReporter? get crashReporter => context.get<CrashReporter>(); CrashReporter? get crashReporter => context.get<CrashReporter>();
DeviceManager? get deviceManager => context.get<DeviceManager>(); DeviceManager? get deviceManager => context.get<DeviceManager>();
HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>(); HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>();
IOSSimulatorUtils? get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
Logger get logger => context.get<Logger>()!; Logger get logger => context.get<Logger>()!;
OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!; OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
Signals get signals => context.get<Signals>() ?? LocalSignals.instance; Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:multicast_dns/multicast_dns.dart'; import 'package:multicast_dns/multicast_dns.dart';
...@@ -24,9 +22,9 @@ class MDnsObservatoryDiscovery { ...@@ -24,9 +22,9 @@ class MDnsObservatoryDiscovery {
/// automatically select which application to use if multiple are advertising /// automatically select which application to use if multiple are advertising
/// Dart observatory ports. /// Dart observatory ports.
MDnsObservatoryDiscovery({ MDnsObservatoryDiscovery({
MDnsClient mdnsClient, MDnsClient? mdnsClient,
@required Logger logger, required Logger logger,
@required Usage flutterUsage, required Usage flutterUsage,
}): _client = mdnsClient ?? MDnsClient(), }): _client = mdnsClient ?? MDnsClient(),
_logger = logger, _logger = logger,
_flutterUsage = flutterUsage; _flutterUsage = flutterUsage;
...@@ -38,7 +36,7 @@ class MDnsObservatoryDiscovery { ...@@ -38,7 +36,7 @@ class MDnsObservatoryDiscovery {
@visibleForTesting @visibleForTesting
static const String dartObservatoryName = '_dartobservatory._tcp.local'; static const String dartObservatoryName = '_dartobservatory._tcp.local';
static MDnsObservatoryDiscovery get instance => context.get<MDnsObservatoryDiscovery>(); static MDnsObservatoryDiscovery? get instance => context.get<MDnsObservatoryDiscovery>();
/// Executes an mDNS query for a Dart Observatory. /// Executes an mDNS query for a Dart Observatory.
/// ///
...@@ -59,7 +57,7 @@ class MDnsObservatoryDiscovery { ...@@ -59,7 +57,7 @@ class MDnsObservatoryDiscovery {
/// it will return that instance's information regardless of what application /// it will return that instance's information regardless of what application
/// the Observatory instance is for. /// the Observatory instance is for.
@visibleForTesting @visibleForTesting
Future<MDnsObservatoryDiscoveryResult> query({String applicationId, int deviceVmservicePort}) async { Future<MDnsObservatoryDiscoveryResult?> query({String? applicationId, int? deviceVmservicePort}) async {
_logger.printTrace('Checking for advertised Dart observatories...'); _logger.printTrace('Checking for advertised Dart observatories...');
try { try {
await _client.start(); await _client.start();
...@@ -78,7 +76,7 @@ class MDnsObservatoryDiscovery { ...@@ -78,7 +76,7 @@ class MDnsObservatoryDiscovery {
.map<String>((PtrResourceRecord record) => record.domainName) .map<String>((PtrResourceRecord record) => record.domainName)
.toSet(); .toSet();
String domainName; String? domainName;
if (applicationId != null) { if (applicationId != null) {
for (final String name in uniqueDomainNames) { for (final String name in uniqueDomainNames) {
if (name.toLowerCase().startsWith(applicationId.toLowerCase())) { if (name.toLowerCase().startsWith(applicationId.toLowerCase())) {
...@@ -93,7 +91,7 @@ class MDnsObservatoryDiscovery { ...@@ -93,7 +91,7 @@ class MDnsObservatoryDiscovery {
final StringBuffer buffer = StringBuffer(); final StringBuffer buffer = StringBuffer();
buffer.writeln('There are multiple observatory ports available.'); buffer.writeln('There are multiple observatory ports available.');
buffer.writeln('Rerun this command with one of the following passed in as the appId:'); buffer.writeln('Rerun this command with one of the following passed in as the appId:');
buffer.writeln(''); buffer.writeln();
for (final String uniqueDomainName in uniqueDomainNames) { for (final String uniqueDomainName in uniqueDomainNames) {
buffer.writeln(' flutter attach --app-id ${uniqueDomainName.replaceAll('.$dartObservatoryName', '')}'); buffer.writeln(' flutter attach --app-id ${uniqueDomainName.replaceAll('.$dartObservatoryName', '')}');
} }
...@@ -120,15 +118,18 @@ class MDnsObservatoryDiscovery { ...@@ -120,15 +118,18 @@ class MDnsObservatoryDiscovery {
.lookup<TxtResourceRecord>( .lookup<TxtResourceRecord>(
ResourceRecordQuery.text(domainName), ResourceRecordQuery.text(domainName),
) )
?.toList(); .toList();
if (txt == null || txt.isEmpty) { if (txt == null || txt.isEmpty) {
return MDnsObservatoryDiscoveryResult(srv.first.port, ''); return MDnsObservatoryDiscoveryResult(srv.first.port, '');
} }
const String authCodePrefix = 'authCode='; const String authCodePrefix = 'authCode=';
final String raw = txt.first.text.split('\n').firstWhere( String? raw;
(String s) => s.startsWith(authCodePrefix), for (final String record in txt.first.text.split('\n')) {
orElse: () => null, if (record.startsWith(authCodePrefix)) {
); raw = record;
break;
}
}
if (raw == null) { if (raw == null) {
return MDnsObservatoryDiscoveryResult(srv.first.port, ''); return MDnsObservatoryDiscoveryResult(srv.first.port, '');
} }
...@@ -144,12 +145,12 @@ class MDnsObservatoryDiscovery { ...@@ -144,12 +145,12 @@ class MDnsObservatoryDiscovery {
} }
} }
Future<Uri> getObservatoryUri(String applicationId, Device device, { Future<Uri?> getObservatoryUri(String applicationId, Device device, {
bool usesIpv6 = false, bool usesIpv6 = false,
int hostVmservicePort, int? hostVmservicePort,
int deviceVmservicePort, int? deviceVmservicePort,
}) async { }) async {
final MDnsObservatoryDiscoveryResult result = await query( final MDnsObservatoryDiscoveryResult? result = await query(
applicationId: applicationId, applicationId: applicationId,
deviceVmservicePort: deviceVmservicePort, deviceVmservicePort: deviceVmservicePort,
); );
...@@ -246,8 +247,8 @@ Future<Uri> buildObservatoryUri( ...@@ -246,8 +247,8 @@ Future<Uri> buildObservatoryUri(
Device device, Device device,
String host, String host,
int devicePort, [ int devicePort, [
int hostVmservicePort, int? hostVmservicePort,
String authCode, String? authCode,
]) async { ]) async {
String path = '/'; String path = '/';
if (authCode != null) { if (authCode != null) {
...@@ -259,8 +260,8 @@ Future<Uri> buildObservatoryUri( ...@@ -259,8 +260,8 @@ Future<Uri> buildObservatoryUri(
path += '/'; path += '/';
} }
hostVmservicePort ??= 0; hostVmservicePort ??= 0;
final int actualHostPort = hostVmservicePort == 0 ? final int? actualHostPort = hostVmservicePort == 0 ?
await device.portForwarder.forward(devicePort) : await device.portForwarder?.forward(devicePort) :
hostVmservicePort; hostVmservicePort;
return Uri(scheme: 'http', host: host, port: actualHostPort, path: path); return Uri(scheme: 'http', host: host, port: actualHostPort, path: path);
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
...@@ -15,9 +13,9 @@ import 'convert.dart'; ...@@ -15,9 +13,9 @@ import 'convert.dart';
import 'device.dart'; import 'device.dart';
import 'globals_null_migrated.dart' as globals; import 'globals_null_migrated.dart' as globals;
Future<String> sharedSkSlWriter(Device device, Map<String, Object> data, { Future<String?> sharedSkSlWriter(Device device, Map<String, Object> data, {
File outputFile, File? outputFile,
Logger logger, Logger? logger,
}) async { }) async {
logger ??= globals.logger; logger ??= globals.logger;
if (data.isEmpty) { if (data.isEmpty) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
...@@ -24,9 +22,9 @@ void main() { ...@@ -24,9 +22,9 @@ void main() {
setUp(() { setUp(() {
setNetworkInterfaceLister( setNetworkInterfaceLister(
({ ({
bool includeLoopback, bool? includeLoopback,
bool includeLinkLocal, bool? includeLinkLocal,
InternetAddressType type, InternetAddressType? type,
}) async => <NetworkInterface>[], }) async => <NetworkInterface>[],
); );
}); });
...@@ -44,7 +42,7 @@ void main() { ...@@ -44,7 +42,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final int port = (await portDiscovery.query())?.port; final int? port = (await portDiscovery.query())?.port;
expect(port, isNull); expect(port, isNull);
}); });
...@@ -56,7 +54,7 @@ void main() { ...@@ -56,7 +54,7 @@ void main() {
logger: logger, logger: logger,
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final Uri uri = await portDiscovery.getObservatoryUri( final Uri? uri = await portDiscovery.getObservatoryUri(
'', '',
FakeIOSDevice(), FakeIOSDevice(),
); );
...@@ -81,7 +79,7 @@ void main() { ...@@ -81,7 +79,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final int port = (await portDiscovery.query())?.port; final int? port = (await portDiscovery.query())?.port;
expect(port, 123); expect(port, 123);
}); });
...@@ -107,7 +105,7 @@ void main() { ...@@ -107,7 +105,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final MDnsObservatoryDiscoveryResult result = await portDiscovery.query(); final MDnsObservatoryDiscoveryResult? result = await portDiscovery.query();
expect(result?.port, 123); expect(result?.port, 123);
expect(result?.authCode, 'xyz/'); expect(result?.authCode, 'xyz/');
}); });
...@@ -157,7 +155,7 @@ void main() { ...@@ -157,7 +155,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final int port = (await portDiscovery.query(applicationId: 'fiz'))?.port; final int? port = (await portDiscovery.query(applicationId: 'fiz'))?.port;
expect(port, 321); expect(port, 321);
}); });
...@@ -184,7 +182,7 @@ void main() { ...@@ -184,7 +182,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final int port = (await portDiscovery.query(applicationId: 'bar'))?.port; final int? port = (await portDiscovery.query(applicationId: 'bar'))?.port;
expect(port, 1234); expect(port, 1234);
}); });
...@@ -199,7 +197,7 @@ void main() { ...@@ -199,7 +197,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final int port = (await portDiscovery.query(applicationId: 'bar'))?.port; final int? port = (await portDiscovery.query(applicationId: 'bar'))?.port;
expect(port, isNull); expect(port, isNull);
}); });
...@@ -236,7 +234,7 @@ void main() { ...@@ -236,7 +234,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
flutterUsage: TestUsage(), flutterUsage: TestUsage(),
); );
final Uri uri = await portDiscovery.getObservatoryUri('bar', device, hostVmservicePort: 0); final Uri? uri = await portDiscovery.getObservatoryUri('bar', device, hostVmservicePort: 0);
expect(uri.toString(), 'http://127.0.0.1:123/'); expect(uri.toString(), 'http://127.0.0.1:123/');
}); });
}); });
...@@ -255,10 +253,10 @@ class FakeMDnsClient extends Fake implements MDnsClient { ...@@ -255,10 +253,10 @@ class FakeMDnsClient extends Fake implements MDnsClient {
@override @override
Future<void> start({ Future<void> start({
InternetAddress listenAddress, InternetAddress? listenAddress,
NetworkInterfacesFactory interfacesFactory, NetworkInterfacesFactory? interfacesFactory,
int mDnsPort = 5353, int mDnsPort = 5353,
InternetAddress mDnsAddress, InternetAddress? mDnsAddress,
}) async { }) async {
if (osErrorOnStart) { if (osErrorOnStart) {
throw const OSError('Operation not supported on socket', 102); throw const OSError('Operation not supported on socket', 102);
......
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