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