Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 19fe574

Browse files
committed
Add flag to not publish the observatory port over mDNS
1 parent 042c7f0 commit 19fe574

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

common/settings.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ std::string Settings::ToString() const {
4646
stream << "enable_dart_profiling: " << enable_dart_profiling << std::endl;
4747
stream << "disable_dart_asserts: " << disable_dart_asserts << std::endl;
4848
stream << "enable_observatory: " << enable_observatory << std::endl;
49+
stream << "enable_observatory_publication: " << enable_observatory_publication
50+
<< std::endl;
4951
stream << "observatory_host: " << observatory_host << std::endl;
5052
stream << "observatory_port: " << observatory_port << std::endl;
5153
stream << "use_test_fonts: " << use_test_fonts << std::endl;

common/settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ struct Settings {
126126
// Whether the Dart VM service should be enabled.
127127
bool enable_observatory = false;
128128

129+
// Whether to publish the observatory URL over mDNS.
130+
// On iOS 14 this prompts a local network permission dialog,
131+
// which cannot be accepted or dismissed in a CI environment.
132+
bool enable_observatory_publication = false;
133+
129134
// The IP address to which the Dart VM service is bound.
130135
std::string observatory_host;
131136

shell/common/switches.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
221221
settings.enable_observatory =
222222
!command_line.HasOption(FlagForSwitch(Switch::DisableObservatory));
223223

224+
// Enable mDNS Observatory Publication
225+
settings.enable_observatory_publication = !command_line.HasOption(
226+
FlagForSwitch(Switch::DisableObservatoryPublication));
227+
224228
// Set Observatory Host
225229
if (command_line.HasOption(FlagForSwitch(Switch::DeviceObservatoryHost))) {
226230
command_line.GetOptionValue(FlagForSwitch(Switch::DeviceObservatoryHost),

shell/common/switches.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ DEF_SWITCH(DisableObservatory,
7979
"disable-observatory",
8080
"Disable the Dart Observatory. The observatory is never available "
8181
"in release mode.")
82+
DEF_SWITCH(DisableObservatoryPublication,
83+
"disable-observatory-publication",
84+
"Disable mDNS Dart Observatory publication.")
8285
DEF_SWITCH(IPv6,
8386
"ipv6",
8487
"Bind to the IPv6 localhost address for the Dart Observatory. "

shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ @implementation FlutterObservatoryPublisher
4343
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
4444
#include "flutter/fml/task_runner.h"
4545
#include "flutter/runtime/dart_service_isolate.h"
46+
#include "flutter/shell/common/switches.h"
47+
#include "flutter/shell/platform/darwin/common/command_line.h"
4648

4749
@protocol FlutterObservatoryPublisherDelegate
4850
- (instancetype)initWithOwner:(FlutterObservatoryPublisher*)owner;
@@ -219,27 +221,32 @@ - (instancetype)init {
219221
self = [super init];
220222
NSAssert(self, @"Super must not return null on init.");
221223

222-
if (@available(iOS 9.3, *)) {
223-
_delegate.reset([[ObservatoryDNSServiceDelegate alloc] initWithOwner:self]);
224+
auto command_line = flutter::CommandLineFromNSProcessInfo();
225+
auto settings = flutter::SettingsFromCommandLine(command_line);
226+
if (settings.enable_observatory_publication) {
227+
if (@available(iOS 9.3, *)) {
228+
_delegate.reset([[ObservatoryDNSServiceDelegate alloc] initWithOwner:self]);
229+
} else {
230+
_delegate.reset([[ObservatoryNSNetServiceDelegate alloc] initWithOwner:self]);
231+
}
232+
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterObservatoryPublisher>>(self);
233+
234+
fml::MessageLoop::EnsureInitializedForCurrentThread();
235+
_callbackHandle = flutter::DartServiceIsolate::AddServerStatusCallback(
236+
[weak = _weakFactory->GetWeakPtr(),
237+
runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) {
238+
if (!uri.empty()) {
239+
runner->PostTask([weak, uri]() {
240+
if (weak) {
241+
[[weak.get() delegate]
242+
publishServiceProtocolPort:[NSString stringWithUTF8String:uri.c_str()]];
243+
}
244+
});
245+
}
246+
});
224247
} else {
225-
_delegate.reset([[ObservatoryNSNetServiceDelegate alloc] initWithOwner:self]);
248+
FML_LOG(INFO) << "Skipping mDNS obsesrvatory publishing";
226249
}
227-
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterObservatoryPublisher>>(self);
228-
229-
fml::MessageLoop::EnsureInitializedForCurrentThread();
230-
231-
_callbackHandle = flutter::DartServiceIsolate::AddServerStatusCallback(
232-
[weak = _weakFactory->GetWeakPtr(),
233-
runner = fml::MessageLoop::GetCurrent().GetTaskRunner()](const std::string& uri) {
234-
if (!uri.empty()) {
235-
runner->PostTask([weak, uri]() {
236-
if (weak) {
237-
[[weak.get() delegate]
238-
publishServiceProtocolPort:[NSString stringWithUTF8String:uri.c_str()]];
239-
}
240-
});
241-
}
242-
});
243250

244251
return self;
245252
}
@@ -262,7 +269,9 @@ - (NSData*)createTxtData:(NSURL*)url {
262269
- (void)dealloc {
263270
[_delegate stopService];
264271

265-
flutter::DartServiceIsolate::RemoveServerStatusCallback(std::move(_callbackHandle));
272+
if (_callbackHandle) {
273+
flutter::DartServiceIsolate::RemoveServerStatusCallback(std::move(_callbackHandle));
274+
}
266275
[super dealloc];
267276
}
268277
@end

0 commit comments

Comments
 (0)