From 14e4054d2abe2cdb9923ab8bc2e31e9de99708d5 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 4 Feb 2020 12:00:58 -0800 Subject: [PATCH] Expose enable-service-port-fallback switch (flutter/engine#16366) --- engine/src/flutter/common/settings.h | 4 ++++ engine/src/flutter/runtime/dart_isolate.cc | 4 +++- engine/src/flutter/runtime/dart_service_isolate.cc | 4 ++++ engine/src/flutter/runtime/dart_service_isolate.h | 1 + engine/src/flutter/shell/common/switches.cc | 5 +++++ engine/src/flutter/shell/common/switches.h | 4 ++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 42c2939d2a3..1eddf4c16fe 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -122,6 +122,10 @@ struct Settings { // the VM service. bool disable_service_auth_codes = true; + // Determine whether the vmservice should fallback to automatic port selection + // after failing to bind to a specified port. + bool enable_service_port_fallback = false; + // Font settings bool use_test_fonts = false; diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 64297625424..b8082c2ff40 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -625,7 +625,9 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate( tonic::DartState::HandleLibraryTag, // embedder library tag handler false, // disable websocket origin check settings.disable_service_auth_codes, // disable VM service auth codes - error // error (out) + settings.enable_service_port_fallback, // enable fallback to port 0 + // when bind fails. + error // error (out) )) { // Error is populated by call to startup. FML_DLOG(ERROR) << *error; diff --git a/engine/src/flutter/runtime/dart_service_isolate.cc b/engine/src/flutter/runtime/dart_service_isolate.cc index d13666be8fd..d1722c26523 100644 --- a/engine/src/flutter/runtime/dart_service_isolate.cc +++ b/engine/src/flutter/runtime/dart_service_isolate.cc @@ -130,6 +130,7 @@ bool DartServiceIsolate::Startup(std::string server_ip, Dart_LibraryTagHandler embedder_tag_handler, bool disable_origin_check, bool disable_service_auth_codes, + bool enable_service_port_fallback, char** error) { Dart_Isolate isolate = Dart_CurrentIsolate(); FML_CHECK(isolate); @@ -196,6 +197,9 @@ bool DartServiceIsolate::Startup(std::string server_ip, Dart_SetField(library, Dart_NewStringFromCString("_authCodesDisabled"), Dart_NewBoolean(disable_service_auth_codes)); SHUTDOWN_ON_ERROR(result); + result = Dart_SetField( + library, Dart_NewStringFromCString("_enableServicePortFallback"), + Dart_NewBoolean(enable_service_port_fallback)); return true; } diff --git a/engine/src/flutter/runtime/dart_service_isolate.h b/engine/src/flutter/runtime/dart_service_isolate.h index 0adbabca9ad..52a18b24580 100644 --- a/engine/src/flutter/runtime/dart_service_isolate.h +++ b/engine/src/flutter/runtime/dart_service_isolate.h @@ -26,6 +26,7 @@ class DartServiceIsolate { Dart_LibraryTagHandler embedder_tag_handler, bool disable_origin_check, bool disable_service_auth_codes, + bool enable_service_port_fallback, char** error); using CallbackHandle = ptrdiff_t; diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index 8efb517aeb8..a23e1156f5e 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -242,6 +242,11 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) { settings.disable_service_auth_codes = command_line.HasOption(FlagForSwitch(Switch::DisableServiceAuthCodes)); + // Allow fallback to automatic port selection if binding to a specified port + // fails. + settings.enable_service_port_fallback = + command_line.HasOption(FlagForSwitch(Switch::EnableServicePortFallback)); + // Checked mode overrides. settings.disable_dart_asserts = command_line.HasOption(FlagForSwitch(Switch::DisableDartAsserts)); diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 45c018cac10..c0faac25d50 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -112,6 +112,10 @@ DEF_SWITCH(DisableServiceAuthCodes, "disable-service-auth-codes", "Disable the requirement for authentication codes for communicating" " with the VM service.") +DEF_SWITCH(EnableServicePortFallback, + "enable-service-port-fallback", + "Allow the VM service to fallback to automatic port selection if" + " binding to a specified port fails.") DEF_SWITCH(StartPaused, "start-paused", "Start the application paused in the Dart debugger.")