diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 7eec11ad58..2a5be4e4d7 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -1014,6 +1014,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cm FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx +FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tzdata_tests.cmx FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/jit_product_runtime FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/jit_runtime FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view.cc @@ -1021,6 +1022,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.h +FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc +FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner_unittest.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.cc diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx index cb0587353f..5539713b9a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx @@ -4,6 +4,7 @@ }, "sandbox": { "features": [ + "config-data", "deprecated-ambient-replace-as-executable", "root-ssl-certificates" ], diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_runner.cmx index cb0587353f..5539713b9a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_runner.cmx @@ -4,6 +4,7 @@ }, "sandbox": { "features": [ + "config-data", "deprecated-ambient-replace-as-executable", "root-ssl-certificates" ], diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_product_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_product_runner.cmx index bbf0d394c5..f8a61ac927 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_product_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_product_runner.cmx @@ -4,8 +4,9 @@ }, "sandbox": { "features": [ - "root-ssl-certificates", - "deprecated-ambient-replace-as-executable" + "config-data", + "deprecated-ambient-replace-as-executable", + "root-ssl-certificates" ], "services": [ "fuchsia.feedback.CrashReporter", diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_runner.cmx index bbf0d394c5..f8a61ac927 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/meta/dart_jit_runner.cmx @@ -4,8 +4,9 @@ }, "sandbox": { "features": [ - "root-ssl-certificates", - "deprecated-ambient-replace-as-executable" + "config-data", + "deprecated-ambient-replace-as-executable", + "root-ssl-certificates" ], "services": [ "fuchsia.feedback.CrashReporter", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn index 0549a1f753..2db9b474ee 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn @@ -308,6 +308,9 @@ executable("flutter_runner_unittests") { "platform_view.cc", "platform_view.h", "platform_view_unittest.cc", + "runner.cc", + "runner.h", + "runner_unittest.cc", "surface.cc", "surface.h", "task_observers.cc", @@ -335,6 +338,7 @@ executable("flutter_runner_unittests") { "//build/fuchsia/pkg:scenic_cpp", "//build/fuchsia/pkg:sys_cpp_testing", "//flutter/lib/ui", + "//flutter/runtime", "//flutter/shell/common", "//flutter/shell/platform/fuchsia/runtime/dart/utils", "//flutter/testing", @@ -343,6 +347,40 @@ executable("flutter_runner_unittests") { ] } +executable("flutter_runner_tzdata_unittests") { + testonly = true + + output_name = "flutter_runner_tzdata_tests" + + sources = [ + "runner.cc", + "runner.h", + "runner_tzdata_unittest.cc", + ] + + # This is needed for //third_party/googletest for linking zircon symbols. + libs = [ "//fuchsia/sdk/$host_os/arch/$target_cpu/sysroot/lib/libzircon.so" ] + + deps = [ + ":aot", + ":flutter_runner_fixtures", + "//build/fuchsia/fidl:fuchsia.accessibility.semantics", + "//build/fuchsia/pkg:async-loop-cpp", + "//build/fuchsia/pkg:async-loop-default", + "//build/fuchsia/pkg:scenic_cpp", + "//build/fuchsia/pkg:sys_cpp_testing", + "//flutter/lib/ui", + "//flutter/runtime", + "//flutter/shell/common", + "//flutter/shell/platform/fuchsia/runtime/dart/utils", + "//flutter/testing", + "//third_party/dart/runtime:libdart_jit", + "//third_party/dart/runtime/platform:libdart_platform_jit", + "//third_party/icu", + "//third_party/skia", + ] +} + fuchsia_archive("flutter_runner_tests") { testonly = true @@ -352,6 +390,49 @@ fuchsia_archive("flutter_runner_tests") { binary = "$target_name" + resources = [ + { + path = rebase_path("//third_party/icu/common/icudtl.dat") + dest = "icudtl.dat" + }, + { + path = rebase_path( + "$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/metaZones.res") + dest = "tzdata/metaZones.res" + }, + { + path = rebase_path( + "$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/timezoneTypes.res") + dest = "tzdata/timezoneTypes.res" + }, + { + path = rebase_path( + "$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/zoneinfo64.res") + dest = "tzdata/zoneinfo64.res" + }, + ] + + meta_dir = "$flutter_root/shell/platform/fuchsia/flutter/meta" + + libraries = common_libs + + meta = [ + { + path = rebase_path("meta/$target_name.cmx") + dest = "$target_name.cmx" + }, + ] +} + +fuchsia_archive("flutter_runner_tzdata_tests") { + testonly = true + + deps = [ + ":flutter_runner_tzdata_unittests", + ] + + binary = "$target_name" + resources = [ { path = rebase_path("//third_party/icu/common/icudtl.dat") diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_product_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_product_runner.cmx index b127787027..d3c76ec76d 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_product_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_product_runner.cmx @@ -4,8 +4,9 @@ }, "sandbox": { "features": [ - "root-ssl-certificates", + "config-data", "deprecated-ambient-replace-as-executable", + "root-ssl-certificates", "vulkan" ], "services": [ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx index 244761694a..af0c724590 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx @@ -4,8 +4,9 @@ }, "sandbox": { "features": [ - "root-ssl-certificates", + "config-data", "deprecated-ambient-replace-as-executable", + "root-ssl-certificates", "vulkan" ], "services": [ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx index 912b534df9..ee97b1e63c 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx @@ -4,9 +4,10 @@ }, "sandbox": { "features": [ + "config-data", + "deprecated-ambient-replace-as-executable", "root-ssl-certificates", - "vulkan", - "deprecated-ambient-replace-as-executable" + "vulkan" ], "services": [ "fuchsia.accessibility.SettingsManager", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx index 1119b279dd..af0c724590 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx @@ -4,9 +4,10 @@ }, "sandbox": { "features": [ + "config-data", + "deprecated-ambient-replace-as-executable", "root-ssl-certificates", - "vulkan", - "deprecated-ambient-replace-as-executable" + "vulkan" ], "services": [ "fuchsia.accessibility.SettingsManager", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx index ea275dd650..1893721bff 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx @@ -1,11 +1,14 @@ { "program": { - "binary": "bin/app" + "binary": "bin/app", + "env_vars": [ + "ICU_TIMEZONE_FILES_DIR=/pkg/data/tzdata" + ] }, "sandbox": { "features": [ - "vulkan", - "deprecated-ambient-replace-as-executable" + "deprecated-ambient-replace-as-executable", + "vulkan" ], "services": [ "fuchsia.accessibility.semantics.SemanticsManager", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tzdata_tests.cmx b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tzdata_tests.cmx new file mode 100644 index 0000000000..53c38f2948 --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tzdata_tests.cmx @@ -0,0 +1,16 @@ +{ + "program": { + "binary": "bin/app" + }, + "sandbox": { + "features": [ + "deprecated-ambient-replace-as-executable", + "vulkan" + ], + "services": [ + "fuchsia.accessibility.semantics.SemanticsManager", + "fuchsia.intl.PropertyProvider", + "fuchsia.process.Launcher" + ] + } +} diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/runner.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/runner.cc index 876645b1b1..2fe0b5626a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/runner.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/runner.cc @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -29,6 +31,13 @@ namespace { static constexpr char kIcuDataPath[] = "/pkg/data/icudtl.dat"; +// Environment variable containing the path to the directory containing the +// timezone files. +static constexpr char kICUTZEnv[] = "ICU_TIMEZONE_FILES_DIR"; + +// The data directory containing ICU timezone data files. +static constexpr char kICUTZDataDir[] = "/config/data/tzdata/icu/44/le"; + // Map the memory into the process and return a pointer to the memory. uintptr_t GetICUData(const fuchsia::mem::Buffer& icu_data) { uint64_t data_size = icu_data.size; @@ -46,6 +55,33 @@ uintptr_t GetICUData(const fuchsia::mem::Buffer& icu_data) { return 0u; } +// Initializes the timezone data if available. Timezone data file in Fuchsia +// is at a fixed directory path. Returns true on success. As a side effect +// sets the value of the environment variable "ICU_TIMEZONE_FILES_DIR" to a +// fixed value which is fuchsia-specific. +bool InitializeTZData() { + // We need the ability to change the env variable for testing, so not + // overwriting if set. + setenv(kICUTZEnv, kICUTZDataDir, 0 /* No overwrite */); + + const std::string tzdata_dir = getenv(kICUTZEnv); + // Try opening the path to check if present. No need to verify that it is a + // directory since ICU loading will return an error if the TZ data path is + // wrong. + int fd = openat(AT_FDCWD, tzdata_dir.c_str(), O_RDONLY); + if (fd < 0) { + FML_LOG(INFO) << "Could not open: '" << tzdata_dir + << "', proceeding without loading the timezone database: " + << strerror(errno); + return false; + } + if (!close(fd)) { + FML_LOG(WARNING) << "Could not close: " << tzdata_dir << ": " + << strerror(errno); + } + return true; +} + // Return value indicates if initialization was successful. bool InitializeICU() { const char* data_path = kIcuDataPath; @@ -60,10 +96,18 @@ bool InitializeICU() { return false; } + // If the loading fails, soldier on. The loading is optional as we don't + // want to crash the engine in transition. + InitializeTZData(); + // Pass the data to ICU. UErrorCode err = U_ZERO_ERROR; udata_setCommonData(reinterpret_cast(data), &err); - return err == U_ZERO_ERROR; + if (err != U_ZERO_ERROR) { + FML_LOG(ERROR) << "error loading ICU data: " << err; + return false; + } + return true; } } // namespace @@ -223,11 +267,23 @@ void Runner::OnApplicationTerminate(const Application* application) { } void Runner::SetupICU() { - if (!InitializeICU()) { + // Exposes the TZ data setup for testing. Failing here is not fatal. + Runner::SetupTZDataInternal(); + if (!Runner::SetupICUInternal()) { FML_LOG(ERROR) << "Could not initialize ICU data."; } } +// static +bool Runner::SetupICUInternal() { + return InitializeICU(); +} + +// static +bool Runner::SetupTZDataInternal() { + return InitializeTZData(); +} + #if !defined(DART_PRODUCT) void Runner::SetupTraceObserver() { trace_observer_ = std::make_unique(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/runner.h b/engine/src/flutter/shell/platform/fuchsia/flutter/runner.h index ca4cb70d3e..4abba33a60 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/runner.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/runner.h @@ -64,6 +64,15 @@ class Runner final : public fuchsia::sys::Runner { void SetupTraceObserver(); #endif // !defined(DART_PRODUCT) + // Called from SetupICU, for testing only. Returns false on error. + static bool SetupICUInternal(); + // Called from SetupICU, for testing only. Returns false on error. + static bool SetupTZDataInternal(); +#if defined(FRIEND_TEST) + FRIEND_TEST(RunnerTest, TZData); + FRIEND_TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent); +#endif // defined(FRIEND_TEST) + FML_DISALLOW_COPY_AND_ASSIGN(Runner); }; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc new file mode 100644 index 0000000000..c90239c917 --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc @@ -0,0 +1,20 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "runner.h" +#include "third_party/icu/source/i18n/unicode/timezone.h" + +namespace flutter_runner { + +// This test has not been configured with tzdata files. This test shows that +// even without the data files, the runner continues initialization. It will +// use whatever the base data exists in icudtl.dat. +TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent) { + bool success = Runner::SetupICUInternal(); + ASSERT_TRUE(success) << "failed to load set up ICU data"; +} + +} // namespace flutter_runner diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/runner_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/runner_unittest.cc new file mode 100644 index 0000000000..f0ec0b7889 --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/runner_unittest.cc @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "runner.h" +#include "third_party/icu/source/i18n/unicode/timezone.h" + +namespace flutter_runner { + +TEST(RunnerTest, TZData) { + UErrorCode err = U_ZERO_ERROR; + const auto version_before = std::string(icu::TimeZone::getTZDataVersion(err)); + ASSERT_EQ(U_ZERO_ERROR, err) << "unicode error: " << u_errorName(err); + + // This loads the tzdata. In Fuchsia, we force the data from this package + // to be version 2019a, so that we can test the resource load. + bool success = Runner::SetupICUInternal(); + ASSERT_TRUE(success) << "failed to load timezone data"; + + const auto version_after = std::string(icu::TimeZone::getTZDataVersion(err)); + ASSERT_EQ(U_ZERO_ERROR, err) << "unicode error: " << u_errorName(err); + + EXPECT_EQ("2019a", version_after); +} + +} // namespace flutter_runner diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/metaZones.res b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/metaZones.res new file mode 100644 index 0000000000..3b3ee01349 Binary files /dev/null and b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/metaZones.res differ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/timezoneTypes.res b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/timezoneTypes.res new file mode 100644 index 0000000000..895ed2174c Binary files /dev/null and b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/timezoneTypes.res differ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/zoneinfo64.res b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/zoneinfo64.res new file mode 100644 index 0000000000..7e0afd4055 Binary files /dev/null and b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/zoneinfo64.res differ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/README.md b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/README.md new file mode 100644 index 0000000000..bc384ec408 --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/tzdata/README.md @@ -0,0 +1,6 @@ +# Timezone data for testing + +This directory contains the fixed timezone data version 2019a for testing. It +is used in the runner tests to show that loading these files from a specified +location results in the TZ data version "2019a" becoming available to the +binaries.