Skip to content

Commit 20e3c5b

Browse files
filmiliskakaushik
authored andcommitted
Revert "[fuchsia] Temporarily disable intl provider (flutter#13696)" (flutter#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.
1 parent 8a99d10 commit 20e3c5b

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ static void UpdateNativeThreadLabelNames(const std::string& label,
4141
set_thread_name(runners.GetIOTaskRunner(), label, ".io");
4242
}
4343

44+
static fml::RefPtr<flutter::PlatformMessage> MakeLocalizationPlatformMessage(
45+
const fuchsia::intl::Profile& intl_profile) {
46+
return fml::MakeRefCounted<flutter::PlatformMessage>(
47+
"flutter/localization", MakeLocalizationPlatformMessageData(intl_profile),
48+
nullptr);
49+
}
50+
4451
Engine::Engine(Delegate& delegate,
4552
std::string thread_label,
4653
std::shared_ptr<sys::ServiceDirectory> svc,
@@ -256,6 +263,54 @@ Engine::Engine(Delegate& delegate,
256263
// notification. Fire one eagerly.
257264
shell_->GetPlatformView()->NotifyCreated();
258265

266+
// Connect to the intl property provider. If the connection fails, the
267+
// initialization of the engine will simply proceed, printing a warning
268+
// message. The engine will be fully functional, except that the user's
269+
// locale preferences would not be communicated to flutter engine.
270+
{
271+
intl_property_provider_.set_error_handler([](zx_status_t status) {
272+
FML_LOG(WARNING) << "Failed to connect to "
273+
<< fuchsia::intl::PropertyProvider::Name_ << ": "
274+
<< zx_status_get_string(status)
275+
<< " This is not a fatal error, but the user locale "
276+
<< " preferences will not be forwarded to flutter apps";
277+
});
278+
279+
// Note that we're using the runner's services, not the component's.
280+
// Flutter locales should be updated regardless of whether the component has
281+
// direct access to the fuchsia.intl.PropertyProvider service.
282+
ZX_ASSERT(runner_services->Connect(intl_property_provider_.NewRequest()) ==
283+
ZX_OK);
284+
285+
auto get_profile_callback = [flutter_runner_engine =
286+
weak_factory_.GetWeakPtr()](
287+
const fuchsia::intl::Profile& profile) {
288+
if (!flutter_runner_engine) {
289+
return;
290+
}
291+
if (!profile.has_locales()) {
292+
FML_LOG(WARNING) << "Got intl Profile without locales";
293+
}
294+
auto message = MakeLocalizationPlatformMessage(profile);
295+
FML_VLOG(-1) << "Sending LocalizationPlatformMessage";
296+
flutter_runner_engine->shell_->GetPlatformView()->DispatchPlatformMessage(
297+
message);
298+
};
299+
300+
FML_VLOG(-1) << "Requesting intl Profile";
301+
302+
// Make the initial request
303+
intl_property_provider_->GetProfile(get_profile_callback);
304+
305+
// And register for changes
306+
intl_property_provider_.events().OnChange = [this, runner_services,
307+
get_profile_callback]() {
308+
FML_VLOG(-1) << fuchsia::intl::PropertyProvider::Name_ << ": OnChange";
309+
runner_services->Connect(intl_property_provider_.NewRequest());
310+
intl_property_provider_->GetProfile(get_profile_callback);
311+
};
312+
}
313+
259314
// Launch the engine in the appropriate configuration.
260315
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
261316
settings_, task_runners.GetIOTaskRunner());

shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"fuchsia.device.NameProvider",
1616
"fuchsia.feedback.CrashReporter",
1717
"fuchsia.fonts.Provider",
18+
"fuchsia.intl.PropertyProvider",
1819
"fuchsia.net.NameLookup",
1920
"fuchsia.netstack.Netstack",
2021
"fuchsia.posix.socket.Provider",

shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"fuchsia.device.NameProvider",
1616
"fuchsia.feedback.CrashReporter",
1717
"fuchsia.fonts.Provider",
18+
"fuchsia.intl.PropertyProvider",
1819
"fuchsia.net.NameLookup",
1920
"fuchsia.netstack.Netstack",
2021
"fuchsia.posix.socket.Provider",

shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"fuchsia.device.NameProvider",
1616
"fuchsia.feedback.CrashReporter",
1717
"fuchsia.fonts.Provider",
18+
"fuchsia.intl.PropertyProvider",
1819
"fuchsia.net.NameLookup",
1920
"fuchsia.netstack.Netstack",
2021
"fuchsia.posix.socket.Provider",

shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
],
1010
"services": [
1111
"fuchsia.accessibility.semantics.SemanticsManager",
12+
"fuchsia.intl.PropertyProvider",
1213
"fuchsia.sys.Launcher"
1314
]
1415
}

0 commit comments

Comments
 (0)