Skip to content

Commit d7d1241

Browse files
authored
Re-enable the Dart Development Service (DDS) (#64671)
This change re-enables DDS and outputs the DDS URI in place of the VM service URI on the console. If --disable-dds is not provided, --host-vmservice-port will be used to determine the port for DDS rather than the host port for the VM service, which will instead be randomly chosen.
1 parent 45495c7 commit d7d1241

23 files changed

Lines changed: 111 additions & 55 deletions

packages/flutter_tools/lib/src/android/android_device.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class AndroidDevice extends Device {
620620
observatoryDiscovery = ProtocolDiscovery.observatory(
621621
await getLogReader(),
622622
portForwarder: portForwarder,
623-
hostPort: debuggingOptions.hostVmServicePort,
623+
hostPort: debuggingOptions.disableDds ? debuggingOptions.hostVmServicePort : 0,
624624
devicePort: debuggingOptions.deviceVmServicePort,
625625
ipv6: ipv6,
626626
);

packages/flutter_tools/lib/src/base/dds.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,24 @@ import 'logger.dart';
1515
class DartDevelopmentService {
1616
DartDevelopmentService({@required this.logger});
1717

18-
// TODO(bkonyi): enable once VM service can handle SSE forwarding for
19-
// Devtools (https://github.com/flutter/flutter/issues/62507)
20-
static const bool ddsDisabled = true;
2118
final Logger logger;
2219
dds.DartDevelopmentService _ddsInstance;
2320

21+
Uri get uri => _ddsInstance.uri;
22+
2423
Future<void> startDartDevelopmentService(
2524
Uri observatoryUri,
25+
int hostPort,
2626
bool ipv6,
27+
bool disableServiceAuthCodes,
2728
) async {
28-
if (ddsDisabled) {
29-
logger.printTrace(
30-
'DDS is currently disabled due to '
31-
'https://github.com/flutter/flutter/issues/62507'
32-
);
33-
return;
34-
}
3529
final Uri ddsUri = Uri(
3630
scheme: 'http',
3731
host: (ipv6 ?
3832
io.InternetAddress.loopbackIPv6 :
3933
io.InternetAddress.loopbackIPv4
4034
).host,
41-
port: 0,
35+
port: hostPort ?? 0,
4236
);
4337
logger.printTrace(
4438
'Launching a Dart Developer Service (DDS) instance at $ddsUri, '
@@ -48,6 +42,7 @@ class DartDevelopmentService {
4842
_ddsInstance = await dds.DartDevelopmentService.startDartDevelopmentService(
4943
observatoryUri,
5044
serviceUri: ddsUri,
45+
enableAuthCodes: !disableServiceAuthCodes,
5146
);
5247
logger.printTrace('DDS is listening at ${_ddsInstance.uri}.');
5348
} on dds.DartDevelopmentServiceException catch (e) {

packages/flutter_tools/lib/src/commands/drive.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ class DriveCommand extends RunCommandBase {
240240
// If there's another flutter_tools instance still connected to the target
241241
// application, DDS will already be running remotely and this call will fail.
242242
// We can ignore this and continue to use the remote DDS instance.
243-
await device.dds.startDartDevelopmentService(Uri.parse(observatoryUri), ipv6);
243+
await device.dds.startDartDevelopmentService(
244+
Uri.parse(observatoryUri),
245+
hostVmservicePort,
246+
ipv6,
247+
disableServiceAuthCodes,
248+
);
244249
} on dds.DartDevelopmentServiceException catch(_) {
245250
globals.printTrace('Note: DDS is already connected to $observatoryUri.');
246251
}
@@ -478,7 +483,7 @@ Future<LaunchResult> _startApp(
478483
debuggingOptions: DebuggingOptions.enabled(
479484
command.getBuildInfo(),
480485
startPaused: true,
481-
hostVmServicePort: command.hostVmservicePort,
486+
hostVmServicePort: (webUri != null || command.disableDds) ? command.hostVmservicePort : 0,
482487
verboseSystemLogs: command.verboseSystemLogs,
483488
cacheSkSL: command.cacheSkSL,
484489
dumpSkpOnShaderCompilation: command.dumpSkpOnShaderCompilation,

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
6666
help: 'A file to write the attached vmservice uri to after an'
6767
' application is started.',
6868
valueHelp: 'project/example/out.txt'
69-
);
69+
)
70+
..addFlag('disable-service-auth-codes',
71+
negatable: false,
72+
hide: !verboseHelp,
73+
help: 'No longer require an authentication code to connect to the VM '
74+
'service (not recommended).');
7075
usesWebOptions(hide: !verboseHelp);
7176
usesTargetOption();
7277
usesPortOptions();
@@ -75,13 +80,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
7580
usesTrackWidgetCreation(verboseHelp: verboseHelp);
7681
addNullSafetyModeOptions(hide: !verboseHelp);
7782
usesDeviceUserOption();
83+
addDdsOptions(verboseHelp: verboseHelp);
7884
}
7985

8086
bool get traceStartup => boolArg('trace-startup');
8187
bool get cacheSkSL => boolArg('cache-sksl');
8288
bool get dumpSkpOnShaderCompilation => boolArg('dump-skp-on-shader-compilation');
8389
bool get purgePersistentCache => boolArg('purge-persistent-cache');
84-
90+
bool get disableServiceAuthCodes => boolArg('disable-service-auth-codes');
8591
String get route => stringArg('route');
8692
}
8793

@@ -205,11 +211,6 @@ class RunCommand extends RunCommandBase {
205211
'results out to "refresh_benchmark.json", and exit. This flag is '
206212
'intended for use in generating automated flutter benchmarks.',
207213
)
208-
..addFlag('disable-service-auth-codes',
209-
negatable: false,
210-
hide: !verboseHelp,
211-
help: 'No longer require an authentication code to connect to the VM '
212-
'service (not recommended).')
213214
..addFlag('web-initialize-platform',
214215
negatable: true,
215216
defaultsTo: true,
@@ -226,7 +227,6 @@ class RunCommand extends RunCommandBase {
226227
'Currently this is only supported on Android devices. This option '
227228
'cannot be paired with --use-application-binary.'
228229
);
229-
addDdsOptions(verboseHelp: verboseHelp);
230230
}
231231

232232
@override

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class TestCommand extends FlutterCommand {
130130
'This flag is ignored if --start-paused or coverage are requested. '
131131
'The vmservice will be enabled no matter what in those cases.'
132132
);
133+
addDdsOptions(verboseHelp: verboseHelp);
133134
}
134135

135136
/// The interface for starting and configuring the tester.
@@ -254,6 +255,7 @@ class TestCommand extends FlutterCommand {
254255
enableObservatory: collector != null || startPaused || boolArg('enable-vmservice'),
255256
startPaused: startPaused,
256257
disableServiceAuthCodes: disableServiceAuthCodes,
258+
disableDds: disableDds,
257259
ipv6: boolArg('ipv6'),
258260
machine: machine,
259261
buildMode: BuildMode.debug,

packages/flutter_tools/lib/src/desktop_device.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ abstract class DesktopDevice extends Device {
134134
}
135135
final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_deviceLogReader,
136136
devicePort: debuggingOptions?.deviceVmServicePort,
137-
hostPort: debuggingOptions?.hostVmServicePort,
137+
hostPort: (debuggingOptions?.disableDds ?? false) ? debuggingOptions?.hostVmServicePort : 0,
138138
ipv6: ipv6,
139139
);
140140
try {

packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ Future<vm_service.VmService> _kDefaultFuchsiaIsolateDiscoveryConnector(Uri uri)
5555
Future<void> _kDefaultDartDevelopmentServiceStarter(
5656
Device device,
5757
Uri observatoryUri,
58+
bool disableServiceAuthCodes,
5859
) async {
59-
await device.dds.startDartDevelopmentService(observatoryUri, true);
60+
await device.dds.startDartDevelopmentService(
61+
observatoryUri,
62+
0,
63+
true,
64+
disableServiceAuthCodes,
65+
);
6066
}
6167

6268
/// Read the log for a particular device.
@@ -738,7 +744,7 @@ class FuchsiaIsolateDiscoveryProtocol {
738744
final String _isolateName;
739745
final Completer<Uri> _foundUri = Completer<Uri>();
740746
final Future<vm_service.VmService> Function(Uri) _vmServiceConnector;
741-
final Future<void> Function(Device, Uri) _ddsStarter;
747+
final Future<void> Function(Device, Uri, bool) _ddsStarter;
742748
// whether to only poll once.
743749
final bool _pollOnce;
744750
Timer _pollingTimer;
@@ -781,8 +787,8 @@ class FuchsiaIsolateDiscoveryProtocol {
781787
final int localPort = await _device.portForwarder.forward(port);
782788
try {
783789
final Uri uri = Uri.parse('http://[$_ipv6Loopback]:$localPort');
784-
await _ddsStarter(_device, uri);
785-
service = await _vmServiceConnector(uri);
790+
await _ddsStarter(_device, uri, true);
791+
service = await _vmServiceConnector(_device.dds.uri);
786792
_ports[port] = service;
787793
} on SocketException catch (err) {
788794
globals.printTrace('Failed to connect to $localPort: $err');

packages/flutter_tools/lib/src/ios/devices.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class IOSDevice extends Device {
399399
observatoryDiscovery = ProtocolDiscovery.observatory(
400400
getLogReader(app: package),
401401
portForwarder: portForwarder,
402-
hostPort: debuggingOptions.hostVmServicePort,
402+
hostPort: debuggingOptions.disableDds ? debuggingOptions.hostVmServicePort : 0,
403403
devicePort: debuggingOptions.deviceVmServicePort,
404404
ipv6: ipv6,
405405
);
@@ -436,7 +436,7 @@ class IOSDevice extends Device {
436436
assumedDevicePort: assumedObservatoryPort,
437437
device: this,
438438
usesIpv6: ipv6,
439-
hostVmservicePort: debuggingOptions.hostVmServicePort,
439+
hostVmservicePort: debuggingOptions.disableDds ? debuggingOptions.hostVmServicePort : 0,
440440
packageId: packageId,
441441
packageName: FlutterProject.current().manifest.appName,
442442
);

packages/flutter_tools/lib/src/ios/simulators.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,11 @@ class IOSSimulator extends Device {
424424
if (debuggingOptions.skiaDeterministicRendering) '--skia-deterministic-rendering',
425425
if (debuggingOptions.useTestFonts) '--use-test-fonts',
426426
if (debuggingOptions.traceAllowlist != null) '--trace-allowlist="${debuggingOptions.traceAllowlist}"',
427-
if (dartVmFlags.isNotEmpty) '--dart-flags=$dartVmFlags'
428-
'--observatory-port=${debuggingOptions.hostVmServicePort ?? 0}',
427+
if (dartVmFlags.isNotEmpty) '--dart-flags=$dartVmFlags',
428+
if (debuggingOptions.disableDds)
429+
'--observatory-port=${debuggingOptions.hostVmServicePort ?? 0}'
430+
else
431+
'--observatory-port=0'
429432
],
430433
];
431434

@@ -434,7 +437,7 @@ class IOSSimulator extends Device {
434437
observatoryDiscovery = ProtocolDiscovery.observatory(
435438
getLogReader(app: package),
436439
ipv6: ipv6,
437-
hostPort: debuggingOptions.hostVmServicePort,
440+
hostPort: debuggingOptions.disableDds ? debuggingOptions.hostVmServicePort : 0,
438441
devicePort: debuggingOptions.deviceVmServicePort,
439442
);
440443
}

packages/flutter_tools/lib/src/resident_runner.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class FlutterDevice {
205205
ReloadMethod reloadMethod,
206206
GetSkSLMethod getSkSLMethod,
207207
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
208+
int hostVmServicePort,
209+
bool disableServiceAuthCodes = false,
208210
bool disableDds = false,
209211
bool ipv6 = false,
210212
}) {
@@ -220,12 +222,14 @@ class FlutterDevice {
220222
if (!disableDds) {
221223
await device.dds.startDartDevelopmentService(
222224
observatoryUri,
225+
hostVmServicePort,
223226
ipv6,
227+
disableServiceAuthCodes,
224228
);
225229
}
226230
try {
227231
service = await connectToVmService(
228-
observatoryUri,
232+
disableDds ? observatoryUri : device.dds.uri,
229233
reloadSources: reloadSources,
230234
restart: restart,
231235
compileExpression: compileExpression,
@@ -1232,10 +1236,12 @@ abstract class ResidentRunner {
12321236
restart: restart,
12331237
compileExpression: compileExpression,
12341238
disableDds: debuggingOptions.disableDds,
1239+
hostVmServicePort: debuggingOptions.hostVmServicePort,
12351240
reloadMethod: reloadMethod,
12361241
getSkSLMethod: getSkSLMethod,
12371242
printStructuredErrorLogMethod: printStructuredErrorLog,
12381243
ipv6: ipv6,
1244+
disableServiceAuthCodes: debuggingOptions.disableServiceAuthCodes
12391245
);
12401246
// This will wait for at least one flutter view before returning.
12411247
final Status status = globals.logger.startProgress(

0 commit comments

Comments
 (0)