Revert "Allow specifying device-vmservice-port and host-vmservice-port (#44027)" (#44843)
This reverts commit c0af77bf878a78057bc9b51a5b601ecaf746eb5c.
diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart
index 5aea8b3..1e6b0f3 100644
--- a/packages/flutter_tools/lib/src/android/android_device.dart
+++ b/packages/flutter_tools/lib/src/android/android_device.dart
@@ -549,8 +549,7 @@
observatoryDiscovery = ProtocolDiscovery.observatory(
getLogReader(),
portForwarder: portForwarder,
- hostPort: debuggingOptions.hostVmServicePort,
- devicePort: debuggingOptions.deviceVmServicePort,
+ hostPort: debuggingOptions.observatoryPort,
ipv6: ipv6,
);
}
diff --git a/packages/flutter_tools/lib/src/commands/attach.dart b/packages/flutter_tools/lib/src/commands/attach.dart
index ee6a0e0..b9f35b5 100644
--- a/packages/flutter_tools/lib/src/commands/attach.dart
+++ b/packages/flutter_tools/lib/src/commands/attach.dart
@@ -232,8 +232,7 @@
observatoryUri = await MDnsObservatoryDiscovery.instance.getObservatoryUri(
appId,
device,
- usesIpv6: usesIpv6,
- deviceVmservicePort: deviceVmservicePort,
+ usesIpv6,
);
}
// If MDNS discovery fails or we're not on iOS, fallback to ProtocolDiscovery.
@@ -243,9 +242,6 @@
observatoryDiscovery = ProtocolDiscovery.observatory(
device.getLogReader(),
portForwarder: device.portForwarder,
- ipv6: ipv6,
- devicePort: deviceVmservicePort,
- hostPort: hostVmservicePort,
);
printStatus('Waiting for a connection from Flutter on ${device.name}...');
observatoryUri = await observatoryDiscovery.uri;
@@ -263,7 +259,7 @@
device,
debugUri?.host ?? hostname,
devicePort ?? debugUri.port,
- hostVmservicePort,
+ observatoryPort,
debugUri?.path,
);
}
diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart
index 680a817..4d89864 100644
--- a/packages/flutter_tools/lib/src/commands/drive.dart
+++ b/packages/flutter_tools/lib/src/commands/drive.dart
@@ -273,7 +273,7 @@
debuggingOptions: DebuggingOptions.enabled(
command.getBuildInfo(),
startPaused: true,
- hostVmServicePort: command.hostVmservicePort,
+ observatoryPort: command.observatoryPort,
verboseSystemLogs: command.verboseSystemLogs,
cacheSkSL: command.cacheSkSL,
dumpSkpOnShaderCompilation: command.dumpSkpOnShaderCompilation,
diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart
index e87b586..6f10357 100644
--- a/packages/flutter_tools/lib/src/commands/run.dart
+++ b/packages/flutter_tools/lib/src/commands/run.dart
@@ -315,8 +315,7 @@
traceSystrace: argResults['trace-systrace'],
dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation,
cacheSkSL: cacheSkSL,
- deviceVmServicePort: deviceVmservicePort,
- hostVmServicePort: hostVmservicePort,
+ observatoryPort: observatoryPort,
verboseSystemLogs: argResults['verbose-system-logs'],
initializePlatform: argResults['web-initialize-platform'],
hostname: featureFlags.isWebEnabled ? argResults['web-hostname'] : '',
diff --git a/packages/flutter_tools/lib/src/desktop_device.dart b/packages/flutter_tools/lib/src/desktop_device.dart
index f577989..341aa1d 100644
--- a/packages/flutter_tools/lib/src/desktop_device.dart
+++ b/packages/flutter_tools/lib/src/desktop_device.dart
@@ -109,11 +109,7 @@
return LaunchResult.succeeded();
}
_deviceLogReader.initializeProcess(process);
- final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_deviceLogReader,
- devicePort: debuggingOptions?.deviceVmServicePort,
- hostPort: debuggingOptions?.hostVmServicePort,
- ipv6: ipv6,
- );
+ final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_deviceLogReader);
try {
final Uri observatoryUri = await observatoryDiscovery.uri;
onAttached(package, buildMode, process);
diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart
index 6fe8a06..adb04a3 100644
--- a/packages/flutter_tools/lib/src/device.dart
+++ b/packages/flutter_tools/lib/src/device.dart
@@ -502,8 +502,7 @@
this.cacheSkSL = false,
this.useTestFonts = false,
this.verboseSystemLogs = false,
- this.hostVmServicePort,
- this.deviceVmServicePort,
+ this.observatoryPort,
this.initializePlatform = true,
this.hostname,
this.port,
@@ -523,8 +522,7 @@
traceSystrace = false,
dumpSkpOnShaderCompilation = false,
verboseSystemLogs = false,
- hostVmServicePort = null,
- deviceVmServicePort = null,
+ observatoryPort = null,
browserLaunch = true,
vmserviceOutFile = null;
@@ -544,15 +542,14 @@
final bool verboseSystemLogs;
/// Whether to invoke webOnlyInitializePlatform in Flutter for web.
final bool initializePlatform;
- final int hostVmServicePort;
- final int deviceVmServicePort;
+ final int observatoryPort;
final String port;
final String hostname;
final bool browserLaunch;
/// A file where the vmservice uri should be written after the application is started.
final String vmserviceOutFile;
- bool get hasObservatoryPort => hostVmServicePort != null;
+ bool get hasObservatoryPort => observatoryPort != null;
}
class LaunchResult {
diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart
index bb481a5..3fff840 100644
--- a/packages/flutter_tools/lib/src/ios/devices.dart
+++ b/packages/flutter_tools/lib/src/ios/devices.dart
@@ -356,8 +356,7 @@
observatoryDiscovery = ProtocolDiscovery.observatory(
getLogReader(app: package),
portForwarder: portForwarder,
- hostPort: debuggingOptions.hostVmServicePort,
- devicePort: debuggingOptions.deviceVmServicePort,
+ hostPort: debuggingOptions.observatoryPort,
ipv6: ipv6,
);
}
@@ -384,8 +383,8 @@
localUri = await MDnsObservatoryDiscovery.instance.getObservatoryUri(
packageId,
this,
- usesIpv6: ipv6,
- hostVmservicePort: debuggingOptions.hostVmServicePort,
+ ipv6,
+ debuggingOptions.observatoryPort,
);
if (localUri != null) {
UsageEvent('ios-mdns', 'success').send();
diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart
index 05847fe..5084d7e 100644
--- a/packages/flutter_tools/lib/src/ios/simulators.dart
+++ b/packages/flutter_tools/lib/src/ios/simulators.dart
@@ -374,18 +374,14 @@
if (debuggingOptions.disableServiceAuthCodes) '--disable-service-auth-codes',
if (debuggingOptions.skiaDeterministicRendering) '--skia-deterministic-rendering',
if (debuggingOptions.useTestFonts) '--use-test-fonts',
- '--observatory-port=${debuggingOptions.hostVmServicePort ?? 0}',
+ '--observatory-port=${debuggingOptions.observatoryPort ?? 0}',
],
];
ProtocolDiscovery observatoryDiscovery;
if (debuggingOptions.debuggingEnabled) {
observatoryDiscovery = ProtocolDiscovery.observatory(
- getLogReader(app: package),
- ipv6: ipv6,
- hostPort: debuggingOptions.hostVmServicePort,
- devicePort: debuggingOptions.deviceVmServicePort,
- );
+ getLogReader(app: package), ipv6: ipv6);
}
// Launch the updated application in the simulator.
diff --git a/packages/flutter_tools/lib/src/mdns_discovery.dart b/packages/flutter_tools/lib/src/mdns_discovery.dart
index d824fb3..6fc3bd4 100644
--- a/packages/flutter_tools/lib/src/mdns_discovery.dart
+++ b/packages/flutter_tools/lib/src/mdns_discovery.dart
@@ -50,8 +50,7 @@
/// If it is null and there is only one available instance of Observatory,
/// it will return that instance's information regardless of what application
/// the Observatory instance is for.
- // TODO(jonahwilliams): use `deviceVmservicePort` to filter mdns results.
- Future<MDnsObservatoryDiscoveryResult> query({String applicationId, int deviceVmservicePort}) async {
+ Future<MDnsObservatoryDiscoveryResult> query({String applicationId}) async {
printTrace('Checking for advertised Dart observatories...');
try {
await client.start();
@@ -137,27 +136,14 @@
}
}
- Future<Uri> getObservatoryUri(String applicationId, Device device, {
- bool usesIpv6 = false,
- int hostVmservicePort,
- int deviceVmservicePort,
- }) async {
- final MDnsObservatoryDiscoveryResult result = await query(
- applicationId: applicationId,
- deviceVmservicePort: deviceVmservicePort,
- );
+ Future<Uri> getObservatoryUri(String applicationId, Device device, [bool usesIpv6 = false, int observatoryPort]) async {
+ final MDnsObservatoryDiscoveryResult result = await query(applicationId: applicationId);
Uri observatoryUri;
if (result != null) {
final String host = usesIpv6
? InternetAddress.loopbackIPv6.address
: InternetAddress.loopbackIPv4.address;
- observatoryUri = await buildObservatoryUri(
- device,
- host,
- result.port,
- hostVmservicePort,
- result.authCode,
- );
+ observatoryUri = await buildObservatoryUri(device, host, result.port, observatoryPort, result.authCode);
}
return observatoryUri;
}
@@ -173,7 +159,7 @@
Device device,
String host,
int devicePort, [
- int hostVmservicePort,
+ int observatoryPort,
String authCode,
]) async {
String path = '/';
@@ -185,6 +171,7 @@
if (!path.endsWith('/')) {
path += '/';
}
- final int actualHostPort = await device.portForwarder.forward(devicePort, hostPort: hostVmservicePort);
- return Uri(scheme: 'http', host: host, port: actualHostPort, path: path);
+ final int localPort = observatoryPort
+ ?? await device.portForwarder.forward(devicePort);
+ return Uri(scheme: 'http', host: host, port: localPort, path: path);
}
diff --git a/packages/flutter_tools/lib/src/protocol_discovery.dart b/packages/flutter_tools/lib/src/protocol_discovery.dart
index 803c957..33768ed 100644
--- a/packages/flutter_tools/lib/src/protocol_discovery.dart
+++ b/packages/flutter_tools/lib/src/protocol_discovery.dart
@@ -4,8 +4,6 @@
import 'dart:async';
-import 'package:meta/meta.dart';
-
import 'base/io.dart';
import 'device.dart';
import 'globals.dart';
@@ -18,7 +16,6 @@
this.serviceName, {
this.portForwarder,
this.hostPort,
- this.devicePort,
this.ipv6,
}) : assert(logReader != null) {
_deviceLogSubscription = logReader.logLines.listen(_handleLine);
@@ -27,9 +24,8 @@
factory ProtocolDiscovery.observatory(
DeviceLogReader logReader, {
DevicePortForwarder portForwarder,
- @required int hostPort,
- @required int devicePort,
- @required bool ipv6,
+ int hostPort,
+ bool ipv6 = false,
}) {
const String kObservatoryService = 'Observatory';
return ProtocolDiscovery._(
@@ -37,7 +33,6 @@
kObservatoryService,
portForwarder: portForwarder,
hostPort: hostPort,
- devicePort: devicePort,
ipv6: ipv6,
);
}
@@ -46,7 +41,6 @@
final String serviceName;
final DevicePortForwarder portForwarder;
final int hostPort;
- final int devicePort;
final bool ipv6;
final Completer<Uri> _completer = Completer<Uri>();
@@ -77,22 +71,17 @@
if (match != null) {
try {
uri = Uri.parse(match[1]);
- } on FormatException catch (error, stackTrace) {
+ } catch (error, stackTrace) {
_stopScrapingLogs();
_completer.completeError(error, stackTrace);
}
}
- if (uri == null) {
- return;
- }
- if (devicePort != null && uri.port != devicePort) {
- printTrace('skipping potential observatory $uri due to device port mismatch');
- return;
- }
- assert(!_completer.isCompleted);
- _stopScrapingLogs();
- _completer.complete(uri);
+ if (uri != null) {
+ assert(!_completer.isCompleted);
+ _stopScrapingLogs();
+ _completer.complete(uri);
+ }
}
Future<Uri> _forwardPort(Uri deviceUri) async {
diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart
index 4f4c3e2..81ec070 100644
--- a/packages/flutter_tools/lib/src/runner/flutter_command.dart
+++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart
@@ -216,60 +216,23 @@
/// Adds options for connecting to the Dart VM observatory port.
void usesPortOptions() {
argParser.addOption(observatoryPortOption,
- help: '(deprecated use host-vmservice-port instead)'
- 'Listen to the given port for an observatory debugger connection.\n'
+ help: 'Listen to the given port for an observatory debugger connection.\n'
'Specifying port 0 (the default) will find a random free port.',
);
- argParser.addOption('device-vmservice-port',
- help: 'Look for vmservice connections only from the specified port.\n'
- 'Specifying port 0 (the default) will accept the first vmservice '
- 'discovered.',
- );
- argParser.addOption('host-vmservice-port',
- help: 'When a device-side vmservice port is forwarded to a host-side '
- 'port, use this value as the host port.\nSpecifying port 0 '
- '(the default) will find a random free host port.'
- );
_usesPortOption = true;
}
- /// Gets the vmservice port provided to in the 'observatory-port' or
- /// 'host-vmservice-port option.
- ///
- /// Only one of "host-vmservice-port" and "observatory-port" may be
- /// specified.
+ /// Gets the observatory port provided to in the 'observatory-port' option.
///
/// If no port is set, returns null.
- int get hostVmservicePort {
- if (!_usesPortOption ||
- argResults['observatory-port'] == null ||
- argResults['host-vmservice-port'] == null) {
- return null;
- }
- if (argResults.wasParsed('observatory-port') &&
- argResults.wasParsed('host-vmservice-port')) {
- throwToolExit('Only one of "--observatory-port" and '
- '"--host-vmservice-port" may be specified.');
- }
- try {
- return int.parse(argResults['observatory-port'] ?? argResults['host-vmservice-port']);
- } on FormatException catch (error) {
- throwToolExit('Invalid port for `--observatory-port/--host-vmservice-port`: $error');
- }
- return null;
- }
-
- /// Gets the vmservice port provided to in the 'device-vmservice-port' option.
- ///
- /// If no port is set, returns null.
- int get deviceVmservicePort {
- if (!_usesPortOption || argResults['device-vmservice-port'] == null) {
+ int get observatoryPort {
+ if (!_usesPortOption || argResults['observatory-port'] == null) {
return null;
}
try {
- return int.parse(argResults['device-vmservice-port']);
- } on FormatException catch (error) {
- throwToolExit('Invalid port for `--device-vmservice-port`: $error');
+ return int.parse(argResults['observatory-port']);
+ } catch (error) {
+ throwToolExit('Invalid port for `--observatory-port`: $error');
}
return null;
}
diff --git a/packages/flutter_tools/lib/src/tester/flutter_tester.dart b/packages/flutter_tools/lib/src/tester/flutter_tester.dart
index 213cf3c..75844c9 100644
--- a/packages/flutter_tools/lib/src/tester/flutter_tester.dart
+++ b/packages/flutter_tools/lib/src/tester/flutter_tester.dart
@@ -134,7 +134,7 @@
command.add('--disable-service-auth-codes');
}
if (debuggingOptions.hasObservatoryPort) {
- command.add('--observatory-port=${debuggingOptions.hostVmServicePort}');
+ command.add('--observatory-port=${debuggingOptions.observatoryPort}');
}
}
@@ -187,9 +187,7 @@
final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(
getLogReader(),
- hostPort: debuggingOptions.hostVmServicePort,
- devicePort: debuggingOptions.deviceVmServicePort,
- ipv6: ipv6,
+ hostPort: debuggingOptions.observatoryPort,
);
final Uri observatoryUri = await observatoryDiscovery.uri;
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
index f257a09..b4fb892 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
@@ -400,7 +400,7 @@
],
);
await completer.future;
- verifyNever(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')));
+ verifyNever(portForwarder.forward(devicePort));
await expectLoggerInterruptEndsTask(task, logger);
await loggerSubscription.cancel();
@@ -432,7 +432,7 @@
],
);
await completer.future;
- verifyNever(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')));
+ verifyNever(portForwarder.forward(devicePort));
await expectLoggerInterruptEndsTask(task, logger);
await loggerSubscription.cancel();
diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
index 56d7b72..1bea916 100644
--- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
@@ -259,7 +259,7 @@
port: 1234,
path: 'observatory',
);
- when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, usesIpv6: anyNamed('usesIpv6')))
+ when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, any))
.thenAnswer((Invocation invocation) => Future<Uri>.value(uri));
final LaunchResult launchResult = await device.startApp(mockApp,
@@ -329,7 +329,7 @@
mockLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
});
- when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, usesIpv6: anyNamed('usesIpv6')))
+ when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, any))
.thenAnswer((Invocation invocation) => Future<Uri>.value(null));
final LaunchResult launchResult = await device.startApp(mockApp,
@@ -362,7 +362,7 @@
mockLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http:/:/127.0.0.1:$devicePort');
});
- when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, usesIpv6: anyNamed('usesIpv6')))
+ when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, any))
.thenAnswer((Invocation invocation) => Future<Uri>.value(null));
final LaunchResult launchResult = await device.startApp(mockApp,
@@ -411,7 +411,7 @@
port: 1234,
path: 'observatory',
);
- when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, usesIpv6: anyNamed('usesIpv6')))
+ when(mockMDnsObservatoryDiscovery.getObservatoryUri(any, any, any))
.thenAnswer((Invocation invocation) => Future<Uri>.value(uri));
List<String> args;
diff --git a/packages/flutter_tools/test/general.shard/protocol_discovery_test.dart b/packages/flutter_tools/test/general.shard/protocol_discovery_test.dart
index db074a0..6ad073f 100644
--- a/packages/flutter_tools/test/general.shard/protocol_discovery_test.dart
+++ b/packages/flutter_tools/test/general.shard/protocol_discovery_test.dart
@@ -17,8 +17,6 @@
ProtocolDiscovery discoverer;
group('no port forwarding', () {
- int devicePort;
-
/// Performs test set-up functionality that must be performed as part of
/// the `test()` pass and not part of the `setUp()` pass.
///
@@ -37,7 +35,7 @@
/// See also: [runZoned]
void initialize() {
logReader = MockDeviceLogReader();
- discoverer = ProtocolDiscovery.observatory(logReader, ipv6: false, hostPort: null, devicePort: devicePort);
+ discoverer = ProtocolDiscovery.observatory(logReader);
}
tearDown(() {
@@ -121,28 +119,6 @@
expect(uri.port, 54804);
expect('$uri', 'http://127.0.0.1:54804/PTwjm8Ii8qg=/');
});
-
- testUsingContext('skips uri if port does not match the requested vmservice - requested last', () async {
- devicePort = 12346;
- initialize();
- final Future<Uri> uriFuture = discoverer.uri;
- logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:12345/PTwjm8Ii8qg=/');
- logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:12346/PTwjm8Ii8qg=/');
- final Uri uri = await uriFuture;
- expect(uri.port, 12346);
- expect('$uri', 'http://127.0.0.1:12346/PTwjm8Ii8qg=/');
- });
-
- testUsingContext('skips uri if port does not match the requested vmservice - requested first', () async {
- devicePort = 12346;
- initialize();
- final Future<Uri> uriFuture = discoverer.uri;
- logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:12346/PTwjm8Ii8qg=/');
- logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:12345/PTwjm8Ii8qg=/');
- final Uri uri = await uriFuture;
- expect(uri.port, 12346);
- expect('$uri', 'http://127.0.0.1:12346/PTwjm8Ii8qg=/');
- });
});
group('port forwarding', () {
@@ -151,9 +127,6 @@
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
- hostPort: null,
- devicePort: null,
- ipv6: false,
);
// Get next port future.
@@ -173,8 +146,6 @@
logReader,
portForwarder: MockPortForwarder(99),
hostPort: 1243,
- devicePort: null,
- ipv6: false,
);
// Get next port future.
@@ -194,8 +165,6 @@
logReader,
portForwarder: MockPortForwarder(99),
hostPort: 0,
- devicePort: null,
- ipv6: false,
);
// Get next port future.
@@ -216,7 +185,6 @@
portForwarder: MockPortForwarder(99),
hostPort: 54777,
ipv6: true,
- devicePort: null,
);
// Get next port future.
@@ -237,7 +205,6 @@
portForwarder: MockPortForwarder(99),
hostPort: 54777,
ipv6: true,
- devicePort: null,
);
// Get next port future.