Skip to content

Commit

Permalink
Revert "[fuchsia] Temporarily disable intl provider (flutter#13696)" (f…
Browse files Browse the repository at this point in the history
…lutter#13721)

This reverts commit 6c763bb.

The reverted code was not the root cause of the issues with rolling
flutter into fuchsia, so adding it back.

In addition, lowering the severity of the connection error at the outset
to WARNING; since it is not a hard failure.
  • Loading branch information
filmil authored and iskakaushik committed Nov 9, 2019
1 parent 8a99d10 commit 20e3c5b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
55 changes: 55 additions & 0 deletions shell/platform/fuchsia/flutter/engine.cc
Expand Up @@ -41,6 +41,13 @@ static void UpdateNativeThreadLabelNames(const std::string& label,
set_thread_name(runners.GetIOTaskRunner(), label, ".io");
}

static fml::RefPtr<flutter::PlatformMessage> MakeLocalizationPlatformMessage(
const fuchsia::intl::Profile& intl_profile) {
return fml::MakeRefCounted<flutter::PlatformMessage>(
"flutter/localization", MakeLocalizationPlatformMessageData(intl_profile),
nullptr);
}

Engine::Engine(Delegate& delegate,
std::string thread_label,
std::shared_ptr<sys::ServiceDirectory> svc,
Expand Down Expand Up @@ -256,6 +263,54 @@ Engine::Engine(Delegate& delegate,
// notification. Fire one eagerly.
shell_->GetPlatformView()->NotifyCreated();

// Connect to the intl property provider. If the connection fails, the
// initialization of the engine will simply proceed, printing a warning
// message. The engine will be fully functional, except that the user's
// locale preferences would not be communicated to flutter engine.
{
intl_property_provider_.set_error_handler([](zx_status_t status) {
FML_LOG(WARNING) << "Failed to connect to "
<< fuchsia::intl::PropertyProvider::Name_ << ": "
<< zx_status_get_string(status)
<< " This is not a fatal error, but the user locale "
<< " preferences will not be forwarded to flutter apps";
});

// Note that we're using the runner's services, not the component's.
// Flutter locales should be updated regardless of whether the component has
// direct access to the fuchsia.intl.PropertyProvider service.
ZX_ASSERT(runner_services->Connect(intl_property_provider_.NewRequest()) ==
ZX_OK);

auto get_profile_callback = [flutter_runner_engine =
weak_factory_.GetWeakPtr()](
const fuchsia::intl::Profile& profile) {
if (!flutter_runner_engine) {
return;
}
if (!profile.has_locales()) {
FML_LOG(WARNING) << "Got intl Profile without locales";
}
auto message = MakeLocalizationPlatformMessage(profile);
FML_VLOG(-1) << "Sending LocalizationPlatformMessage";
flutter_runner_engine->shell_->GetPlatformView()->DispatchPlatformMessage(
message);
};

FML_VLOG(-1) << "Requesting intl Profile";

// Make the initial request
intl_property_provider_->GetProfile(get_profile_callback);

// And register for changes
intl_property_provider_.events().OnChange = [this, runner_services,
get_profile_callback]() {
FML_VLOG(-1) << fuchsia::intl::PropertyProvider::Name_ << ": OnChange";
runner_services->Connect(intl_property_provider_.NewRequest());
intl_property_provider_->GetProfile(get_profile_callback);
};
}

// Launch the engine in the appropriate configuration.
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
settings_, task_runners.GetIOTaskRunner());
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx
Expand Up @@ -15,6 +15,7 @@
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider",
Expand Down
Expand Up @@ -15,6 +15,7 @@
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider",
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx
Expand Up @@ -15,6 +15,7 @@
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider",
Expand Down
Expand Up @@ -9,6 +9,7 @@
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.intl.PropertyProvider",
"fuchsia.sys.Launcher"
]
}
Expand Down

0 comments on commit 20e3c5b

Please sign in to comment.