From fee84ca0951629d26f14ff7759a717e324ec46ca Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Tue, 13 Jul 2021 10:52:01 +0900 Subject: [PATCH 1/6] Add setting channel unit test Signed-off-by: MuHong Byun --- shell/platform/tizen/BUILD.gn | 2 + .../tizen/channels/platform_view_channel.cc | 6 +- .../tizen/channels/settings_channel.cc | 20 ++----- .../tizen/channels/settings_channel.h | 13 ++--- .../tizen/channels/settings_channel_device.cc | 35 ++++++++++++ .../tizen/channels/settings_channel_stub.cc | 9 ++- .../tizen/flutter_tizen_engine_unittest.cc | 55 ++++++++++++++++++- 7 files changed, 109 insertions(+), 31 deletions(-) create mode 100644 shell/platform/tizen/channels/settings_channel_device.cc diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index ba5670b5b4ccd..962ba74506096 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -130,6 +130,7 @@ template("embedder_for_profile") { "channels/localization_channel.cc", "channels/platform_channel.cc", "channels/settings_channel.cc", + "channels/settings_channel_device.cc", "external_texture_pixel_gl.cc", "external_texture_surface_gl.cc", "tizen_log.cc", @@ -245,6 +246,7 @@ template("embedder_executable") { sources += [ "channels/localization_channel_stub.cc", "channels/platform_channel_stub.cc", + "channels/settings_channel.cc", "channels/settings_channel_stub.cc", "external_texture_pixel_gl_stub.cc", "external_texture_surface_gl_stub.cc", diff --git a/shell/platform/tizen/channels/platform_view_channel.cc b/shell/platform/tizen/channels/platform_view_channel.cc index 462c372e23fc2..3dbce1bd14e9e 100644 --- a/shell/platform/tizen/channels/platform_view_channel.cc +++ b/shell/platform/tizen/channels/platform_view_channel.cc @@ -12,10 +12,12 @@ #include "flutter/shell/platform/tizen/public/flutter_platform_view.h" #include "flutter/shell/platform/tizen/tizen_log.h" -static constexpr char kChannelName[] = "flutter/platform_views"; - namespace flutter { +namespace { +constexpr char kChannelName[] = "flutter/platform_views"; +} // namespace + template bool GetValueFromEncodableMap(const EncodableValue& arguments, std::string key, diff --git a/shell/platform/tizen/channels/settings_channel.cc b/shell/platform/tizen/channels/settings_channel.cc index 54daa65c248a1..2cd5515d98bdc 100644 --- a/shell/platform/tizen/channels/settings_channel.cc +++ b/shell/platform/tizen/channels/settings_channel.cc @@ -23,23 +23,19 @@ SettingsChannel::SettingsChannel(BinaryMessenger* messenger) messenger, kChannelName, &JsonMessageCodec::GetInstance())) { - system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, - OnSettingsChangedCallback, this); + Init(); SendSettingsEvent(); } SettingsChannel::~SettingsChannel() { - system_settings_unset_changed_cb( - SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR); + Dispose(); } void SettingsChannel::SendSettingsEvent() { - rapidjson::Document event(rapidjson::kObjectType); - auto& allocator = event.GetAllocator(); bool value = false; - int ret = system_settings_get_value_bool( - SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &value); - if (ret == SYSTEM_SETTINGS_ERROR_NONE) { + if (GetSettingValueOf24Format(&value)) { + rapidjson::Document event(rapidjson::kObjectType); + auto& allocator = event.GetAllocator(); event.AddMember(kTextScaleFactorKey, 1.0, allocator); event.AddMember(kPlatformBrightnessKey, "light", allocator); event.AddMember(kAlwaysUse24HourFormatKey, value, allocator); @@ -47,10 +43,4 @@ void SettingsChannel::SendSettingsEvent() { } } -void SettingsChannel::OnSettingsChangedCallback(system_settings_key_e key, - void* user_data) { - auto settings_channel = reinterpret_cast(user_data); - settings_channel->SendSettingsEvent(); -} - } // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel.h b/shell/platform/tizen/channels/settings_channel.h index b99a03126c9f3..3ba36c9d6dfa6 100644 --- a/shell/platform/tizen/channels/settings_channel.h +++ b/shell/platform/tizen/channels/settings_channel.h @@ -5,10 +5,6 @@ #ifndef EMBEDDER_SETTINGS_CHANNEL_H_ #define EMBEDDER_SETTINGS_CHANNEL_H_ -#ifndef __X64_SHELL__ -#include -#endif - #include #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" @@ -21,15 +17,14 @@ class SettingsChannel { public: explicit SettingsChannel(BinaryMessenger* messenger); virtual ~SettingsChannel(); + void SendSettingsEvent(); private: -#ifndef __X64_SHELL__ - static void OnSettingsChangedCallback(system_settings_key_e key, - void* user_data); - void SendSettingsEvent(); + bool GetSettingValueOf24Format(bool* value); + void Init(); + void Dispose(); std::unique_ptr> channel_; -#endif }; } // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel_device.cc b/shell/platform/tizen/channels/settings_channel_device.cc new file mode 100644 index 0000000000000..a42c06cc3f981 --- /dev/null +++ b/shell/platform/tizen/channels/settings_channel_device.cc @@ -0,0 +1,35 @@ +// Copyright 2021 Samsung Electronics Co., Ltd. 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 "settings_channel.h" + +namespace flutter { + +static void OnSettingsChangedCallback(system_settings_key_e key, + void* user_data) { + auto settings_channel = reinterpret_cast(user_data); + settings_channel->SendSettingsEvent(); +} + +void SettingsChannel::Init() { + system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, + OnSettingsChangedCallback, this); +} + +void SettingsChannel::Dispose() { + system_settings_unset_changed_cb( + SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR); +} + +bool SettingsChannel::GetSettingValueOf24Format(bool* value) { + if (system_settings_get_value_bool( + SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, value) == + SYSTEM_SETTINGS_ERROR_NONE) { + return true; + } + return false; +} + +} // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel_stub.cc b/shell/platform/tizen/channels/settings_channel_stub.cc index 10809f2d919db..ef80e47385d51 100644 --- a/shell/platform/tizen/channels/settings_channel_stub.cc +++ b/shell/platform/tizen/channels/settings_channel_stub.cc @@ -6,8 +6,13 @@ namespace flutter { -SettingsChannel::SettingsChannel(BinaryMessenger* messenger) {} +void SettingsChannel::Init() {} -SettingsChannel::~SettingsChannel() {} +void SettingsChannel::Dispose() {} + +bool SettingsChannel::GetSettingValueOf24Format(bool* value) { + *value = false; + return true; +} } // namespace flutter diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index a8e89a2b2edd9..274b63346bc6c 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -2,7 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + +#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" +#include "flutter/shell/platform/tizen/testing/engine_modifier.h" #include "gtest/gtest.h" namespace flutter { @@ -18,9 +22,9 @@ class FlutterTizenEngineTest : public ::testing::Test { protected: void SetUp() { FlutterDesktopEngineProperties engine_prop = {}; - engine_prop.assets_path = "foo/flutter_assets"; - engine_prop.icu_data_path = "foo/icudtl.dat"; - engine_prop.aot_library_path = "foo/libapp.so"; + engine_prop.assets_path = "/foo/flutter_assets"; + engine_prop.icu_data_path = "/foo/icudtl.dat"; + engine_prop.aot_library_path = "/foo/libapp.so"; FlutterProjectBundle project(engine_prop); auto engine = std::make_unique(project); @@ -81,5 +85,50 @@ TEST_F(FlutterTizenEngineTestHeaded, GetTextureRegistrar) { EXPECT_TRUE(engine_->GetTextureRegistrar() != nullptr); } +TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { + EngineModifier modifier(engine_); + bool run_called = false; + modifier.embedder_api().Run = MOCK_ENGINE_PROC( + Run, ([&run_called, engine_instance = engine_]( + size_t version, const FlutterRendererConfig* config, + const FlutterProjectArgs* args, void* user_data, + FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) { + std::string current_path = std::filesystem::current_path().string(); + run_called = true; + *engine_out = reinterpret_cast(1); + + EXPECT_EQ(version, (size_t)FLUTTER_ENGINE_VERSION); + EXPECT_NE(config, nullptr); + EXPECT_EQ(user_data, engine_instance); + + EXPECT_STREQ(args->assets_path, "/foo/flutter_assets"); + EXPECT_STREQ(args->icu_data_path, "/foo/icudtl.dat"); + EXPECT_EQ(args->dart_entrypoint_argc, 0); + EXPECT_NE(args->platform_message_callback, nullptr); + EXPECT_NE(args->custom_task_runners, nullptr); + EXPECT_EQ(args->custom_dart_entrypoint, nullptr); + + return kSuccess; + })); + + // And it should send initial settings info. + bool settings_message_sent = false; + modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC( + SendPlatformMessage, + ([&settings_message_sent](auto engine, auto message) { + if (std::string(message->channel) == std::string("flutter/settings")) { + settings_message_sent = true; + } + + return kSuccess; + })); + + engine_->RunEngine(); + + EXPECT_TRUE(run_called); + EXPECT_TRUE(settings_message_sent); + + modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; +} } // namespace testing } // namespace flutter From fd3997d1f9bbcb59756bbfdbe5b6626aca5c4390 Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Fri, 16 Jul 2021 09:15:09 +0900 Subject: [PATCH 2/6] Add localization_channel unit test Signed-off-by: MuHong Byun --- shell/platform/tizen/BUILD.gn | 2 + .../tizen/channels/localization_channel.cc | 152 +--------------- .../tizen/channels/localization_channel.h | 3 + .../channels/localization_channel_device.cc | 163 ++++++++++++++++++ .../channels/localization_channel_stub.cc | 19 +- .../tizen/flutter_tizen_engine_unittest.cc | 15 ++ 6 files changed, 203 insertions(+), 151 deletions(-) create mode 100644 shell/platform/tizen/channels/localization_channel_device.cc diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 962ba74506096..cae31988714e1 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -128,6 +128,7 @@ template("embedder_for_profile") { sources = _flutter_tizen_source sources += [ "channels/localization_channel.cc", + "channels/localization_channel_device.cc", "channels/platform_channel.cc", "channels/settings_channel.cc", "channels/settings_channel_device.cc", @@ -244,6 +245,7 @@ template("embedder_executable") { sources = _flutter_tizen_source sources += [ + "channels/localization_channel.cc", "channels/localization_channel_stub.cc", "channels/platform_channel_stub.cc", "channels/settings_channel.cc", diff --git a/shell/platform/tizen/channels/localization_channel.cc b/shell/platform/tizen/channels/localization_channel.cc index 4a911cf94e042..68e32857de182 100644 --- a/shell/platform/tizen/channels/localization_channel.cc +++ b/shell/platform/tizen/channels/localization_channel.cc @@ -4,56 +4,20 @@ #include "localization_channel.h" -#include - -#include - #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" -#include "rapidjson/document.h" -#include "rapidjson/writer.h" - -static constexpr char kChannelName[] = "flutter/localization"; namespace flutter { LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine) - : engine_(engine) {} + : engine_(engine) { + SendLocales(); +} LocalizationChannel::~LocalizationChannel() {} void LocalizationChannel::SendLocales() { - const char* defualt_locale = nullptr; - FlutterLocale* flutter_locale = nullptr; - std::vector flutter_locales; - - int ret = i18n_ulocale_set_default(getenv("LANG")); - ret = i18n_ulocale_get_default(&defualt_locale); - if (ret != I18N_ERROR_NONE) { - FT_LOGE("i18n_ulocale_get_default() failed."); - return; - } - - std::string without_encoding_type(defualt_locale); - auto n = without_encoding_type.find('.'); - without_encoding_type.erase(n, without_encoding_type.length() - n); - - flutter_locale = GetFlutterLocale(without_encoding_type.data()); - if (flutter_locale) { - FT_LOGI("Choose Default locale[%s]", without_encoding_type.data()); - flutter_locales.push_back(flutter_locale); - } - - int32_t count = i18n_ulocale_count_available(); - for (int i = 0; i < count; i++) { - const char* locale = i18n_ulocale_get_available(i); - if (without_encoding_type.compare(locale) != 0) { - flutter_locale = GetFlutterLocale(locale); - if (flutter_locale) { - flutter_locales.push_back(flutter_locale); - } - } - } + std::vector flutter_locales = GetFlutterLocales(); FT_LOGI("Send %zu available locales", flutter_locales.size()); // Send locales to engine @@ -66,114 +30,6 @@ void LocalizationChannel::SendLocales() { } } -void LocalizationChannel::SendPlatformResolvedLocale() { - const char* locale; - int ret = i18n_ulocale_get_default(&locale); - if (ret != I18N_ERROR_NONE) { - FT_LOGE("i18n_ulocale_get_default() failed."); - return; - } - - FlutterLocale* flutter_locale = GetFlutterLocale(locale); - if (!flutter_locale) { - FT_LOGE("Language code is required but not present."); - return; - } - - rapidjson::Document document; - auto& allocator = document.GetAllocator(); - - document.SetObject(); - document.AddMember("method", "setPlatformResolvedLocale", allocator); - - rapidjson::Value language_code, country_code, script_code, variant_code; - language_code.SetString(flutter_locale->language_code, allocator); - country_code.SetString( - flutter_locale->country_code ? flutter_locale->country_code : "", - allocator); - script_code.SetString( - flutter_locale->script_code ? flutter_locale->script_code : "", - allocator); - variant_code.SetString( - flutter_locale->variant_code ? flutter_locale->variant_code : "", - allocator); - - rapidjson::Value args(rapidjson::kArrayType); - args.Reserve(4, allocator); - args.PushBack(language_code, allocator); - args.PushBack(country_code, allocator); - args.PushBack(script_code, allocator); - args.PushBack(variant_code, allocator); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - if (!document.Accept(writer)) { - FT_LOGE("document.Accept failed!"); - return; - } - - engine_->SendPlatformMessage( - kChannelName, reinterpret_cast(buffer.GetString()), - buffer.GetSize(), nullptr, nullptr); - - DestroyFlutterLocale(flutter_locale); -} - -FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { - int capacity = 128; - char buffer[128] = {0}; - int bufSize; - int error; - char* language = nullptr; - char* country = nullptr; - char* script = nullptr; - char* variant = nullptr; - - // set language code, language code is a required field - error = i18n_ulocale_get_language(locale, buffer, capacity, &bufSize); - if (error == I18N_ERROR_NONE && bufSize > 0) { - language = new char[bufSize + 1]; - memcpy(language, buffer, bufSize); - language[bufSize] = '\0'; - } else { - FT_LOGE("i18n_ulocale_get_language failed!"); - return nullptr; - } - - // set country code, country code is an optional field - bufSize = i18n_ulocale_get_country(locale, buffer, capacity, &error); - if (error == I18N_ERROR_NONE && bufSize > 0) { - country = new char[bufSize + 1]; - memcpy(country, buffer, bufSize); - country[bufSize] = '\0'; - } - - // set script code, script code is an optional field - bufSize = i18n_ulocale_get_script(locale, buffer, capacity); - if (bufSize > 0) { - script = new char[bufSize + 1]; - memcpy(script, buffer, bufSize); - script[bufSize] = '\0'; - } - - // set variant code, variant code is an optional field - bufSize = i18n_ulocale_get_variant(locale, buffer, capacity); - if (bufSize > 0) { - variant = new char[bufSize + 1]; - memcpy(variant, buffer, bufSize); - variant[bufSize] = '\0'; - } - - FlutterLocale* flutter_locale = new FlutterLocale; - flutter_locale->struct_size = sizeof(FlutterLocale); - flutter_locale->language_code = language; - flutter_locale->country_code = country; - flutter_locale->script_code = script; - flutter_locale->variant_code = variant; - - return flutter_locale; -} - void LocalizationChannel::DestroyFlutterLocale(FlutterLocale* flutter_locale) { if (flutter_locale) { if (flutter_locale->language_code) { diff --git a/shell/platform/tizen/channels/localization_channel.h b/shell/platform/tizen/channels/localization_channel.h index a5743a4cd3da4..70005567f81fa 100644 --- a/shell/platform/tizen/channels/localization_channel.h +++ b/shell/platform/tizen/channels/localization_channel.h @@ -5,6 +5,8 @@ #ifndef EMBEDDER_LOCALIZATION_CHANNEL_H_ #define EMBEDDER_LOCALIZATION_CHANNEL_H_ +#include + #include "flutter/shell/platform/embedder/embedder.h" namespace flutter { @@ -20,6 +22,7 @@ class LocalizationChannel { private: void SendPlatformResolvedLocale(); + std::vector GetFlutterLocales(); FlutterLocale* GetFlutterLocale(const char* locale); void DestroyFlutterLocale(FlutterLocale* flutter_locale); diff --git a/shell/platform/tizen/channels/localization_channel_device.cc b/shell/platform/tizen/channels/localization_channel_device.cc new file mode 100644 index 0000000000000..917e53aa822a7 --- /dev/null +++ b/shell/platform/tizen/channels/localization_channel_device.cc @@ -0,0 +1,163 @@ +// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "localization_channel.h" + +#include +#include "rapidjson/document.h" +#include "rapidjson/writer.h" + +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" +#include "flutter/shell/platform/tizen/tizen_log.h" + +namespace flutter { + +namespace { +constexpr char kChannelName[] = "flutter/localization"; +} + +void LocalizationChannel::SendPlatformResolvedLocale() { + const char* locale; + int ret = i18n_ulocale_get_default(&locale); + if (ret != I18N_ERROR_NONE) { + FT_LOGE("i18n_ulocale_get_default() failed."); + return; + } + + FlutterLocale* flutter_locale = GetFlutterLocale(locale); + if (!flutter_locale) { + FT_LOGE("Language code is required but not present."); + return; + } + + rapidjson::Document document; + auto& allocator = document.GetAllocator(); + + document.SetObject(); + document.AddMember("method", "setPlatformResolvedLocale", allocator); + + rapidjson::Value language_code, country_code, script_code, variant_code; + language_code.SetString(flutter_locale->language_code, allocator); + country_code.SetString( + flutter_locale->country_code ? flutter_locale->country_code : "", + allocator); + script_code.SetString( + flutter_locale->script_code ? flutter_locale->script_code : "", + allocator); + variant_code.SetString( + flutter_locale->variant_code ? flutter_locale->variant_code : "", + allocator); + + rapidjson::Value args(rapidjson::kArrayType); + args.Reserve(4, allocator); + args.PushBack(language_code, allocator); + args.PushBack(country_code, allocator); + args.PushBack(script_code, allocator); + args.PushBack(variant_code, allocator); + + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + if (!document.Accept(writer)) { + FT_LOGE("document.Accept failed!"); + return; + } + + engine_->SendPlatformMessage( + kChannelName, reinterpret_cast(buffer.GetString()), + buffer.GetSize(), nullptr, nullptr); + + DestroyFlutterLocale(flutter_locale); +} + +std::vector LocalizationChannel::GetFlutterLocales() { + const char* defualt_locale = nullptr; + FlutterLocale* flutter_locale = nullptr; + std::vector flutter_locales; + + int ret = i18n_ulocale_set_default(getenv("LANG")); + ret = i18n_ulocale_get_default(&defualt_locale); + if (ret != I18N_ERROR_NONE) { + FT_LOGE("i18n_ulocale_get_default() failed."); + return flutter_locales; + } + + std::string without_encoding_type(defualt_locale); + auto n = without_encoding_type.find('.'); + without_encoding_type.erase(n, without_encoding_type.length() - n); + + flutter_locale = GetFlutterLocale(without_encoding_type.data()); + if (flutter_locale) { + FT_LOGI("Choose Default locale[%s]", without_encoding_type.data()); + flutter_locales.push_back(flutter_locale); + } + + int32_t count = i18n_ulocale_count_available(); + for (int i = 0; i < count; i++) { + const char* locale = i18n_ulocale_get_available(i); + if (without_encoding_type.compare(locale) != 0) { + flutter_locale = GetFlutterLocale(locale); + if (flutter_locale) { + flutter_locales.push_back(flutter_locale); + } + } + } + return flutter_locales; +} + +FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { + int capacity = 128; + char buffer[128] = {0}; + int bufSize; + int error; + char* language = nullptr; + char* country = nullptr; + char* script = nullptr; + char* variant = nullptr; + + // set language code, language code is a required field + error = i18n_ulocale_get_language(locale, buffer, capacity, &bufSize); + if (error == I18N_ERROR_NONE && bufSize > 0) { + language = new char[bufSize + 1]; + memcpy(language, buffer, bufSize); + language[bufSize] = '\0'; + } else { + FT_LOGE("i18n_ulocale_get_language failed!"); + return nullptr; + } + + // set country code, country code is an optional field + bufSize = i18n_ulocale_get_country(locale, buffer, capacity, &error); + if (error == I18N_ERROR_NONE && bufSize > 0) { + country = new char[bufSize + 1]; + memcpy(country, buffer, bufSize); + country[bufSize] = '\0'; + } + + // set script code, script code is an optional field + bufSize = i18n_ulocale_get_script(locale, buffer, capacity); + if (bufSize > 0) { + script = new char[bufSize + 1]; + memcpy(script, buffer, bufSize); + script[bufSize] = '\0'; + } + + // set variant code, variant code is an optional field + bufSize = i18n_ulocale_get_variant(locale, buffer, capacity); + if (bufSize > 0) { + variant = new char[bufSize + 1]; + memcpy(variant, buffer, bufSize); + variant[bufSize] = '\0'; + } + + FlutterLocale* flutter_locale = new FlutterLocale; + flutter_locale->struct_size = sizeof(FlutterLocale); + flutter_locale->language_code = language; + flutter_locale->country_code = country; + flutter_locale->script_code = script; + flutter_locale->variant_code = variant; + + return flutter_locale; +} + +} // namespace flutter diff --git a/shell/platform/tizen/channels/localization_channel_stub.cc b/shell/platform/tizen/channels/localization_channel_stub.cc index 810b10b60e14b..f00faa6c4e2b3 100644 --- a/shell/platform/tizen/channels/localization_channel_stub.cc +++ b/shell/platform/tizen/channels/localization_channel_stub.cc @@ -6,10 +6,23 @@ namespace flutter { -LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine) {} +void LocalizationChannel::SendPlatformResolvedLocale() {} -LocalizationChannel::~LocalizationChannel() {} +std::vector LocalizationChannel::GetFlutterLocales() { + FlutterLocale* flutter_locale = GetFlutterLocale(nullptr); + std::vector flutter_locales; + flutter_locales.push_back(flutter_locale); + return flutter_locales; +} -void LocalizationChannel::SendLocales() {} +FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { + FlutterLocale* flutter_locale = new FlutterLocale; + flutter_locale->struct_size = sizeof(FlutterLocale); + flutter_locale->language_code = new char[1]; + flutter_locale->country_code = new char[1]; + flutter_locale->script_code = new char[1]; + flutter_locale->variant_code = new char[1]; + return flutter_locale; +} } // namespace flutter diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index 274b63346bc6c..b430bedf710e6 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -111,6 +111,19 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { return kSuccess; })); + // It should send locale info. + bool update_locales_called = false; + modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC( + UpdateLocales, + ([&update_locales_called](auto engine, const FlutterLocale** locales, + size_t locales_count) { + update_locales_called = true; + EXPECT_GT(locales_count, (size_t)0); + EXPECT_NE(locales, nullptr); + + return kSuccess; + })); + // And it should send initial settings info. bool settings_message_sent = false; modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC( @@ -126,6 +139,8 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { engine_->RunEngine(); EXPECT_TRUE(run_called); + EXPECT_TRUE(update_locales_called); + EXPECT_TRUE(settings_message_sent); EXPECT_TRUE(settings_message_sent); modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; From 295e57724d8a490918013bef977c10ee324691bb Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Mon, 19 Jul 2021 07:39:38 +0900 Subject: [PATCH 3/6] Revert "Add localization_channel unit test" This reverts commit fd3997d1f9bbcb59756bbfdbe5b6626aca5c4390. --- shell/platform/tizen/BUILD.gn | 2 - .../tizen/channels/localization_channel.cc | 152 +++++++++++++++- .../tizen/channels/localization_channel.h | 3 - .../channels/localization_channel_device.cc | 163 ------------------ .../channels/localization_channel_stub.cc | 19 +- .../tizen/flutter_tizen_engine_unittest.cc | 15 -- 6 files changed, 151 insertions(+), 203 deletions(-) delete mode 100644 shell/platform/tizen/channels/localization_channel_device.cc diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index cae31988714e1..962ba74506096 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -128,7 +128,6 @@ template("embedder_for_profile") { sources = _flutter_tizen_source sources += [ "channels/localization_channel.cc", - "channels/localization_channel_device.cc", "channels/platform_channel.cc", "channels/settings_channel.cc", "channels/settings_channel_device.cc", @@ -245,7 +244,6 @@ template("embedder_executable") { sources = _flutter_tizen_source sources += [ - "channels/localization_channel.cc", "channels/localization_channel_stub.cc", "channels/platform_channel_stub.cc", "channels/settings_channel.cc", diff --git a/shell/platform/tizen/channels/localization_channel.cc b/shell/platform/tizen/channels/localization_channel.cc index 68e32857de182..4a911cf94e042 100644 --- a/shell/platform/tizen/channels/localization_channel.cc +++ b/shell/platform/tizen/channels/localization_channel.cc @@ -4,20 +4,56 @@ #include "localization_channel.h" +#include + +#include + #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" +#include "rapidjson/document.h" +#include "rapidjson/writer.h" + +static constexpr char kChannelName[] = "flutter/localization"; namespace flutter { LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine) - : engine_(engine) { - SendLocales(); -} + : engine_(engine) {} LocalizationChannel::~LocalizationChannel() {} void LocalizationChannel::SendLocales() { - std::vector flutter_locales = GetFlutterLocales(); + const char* defualt_locale = nullptr; + FlutterLocale* flutter_locale = nullptr; + std::vector flutter_locales; + + int ret = i18n_ulocale_set_default(getenv("LANG")); + ret = i18n_ulocale_get_default(&defualt_locale); + if (ret != I18N_ERROR_NONE) { + FT_LOGE("i18n_ulocale_get_default() failed."); + return; + } + + std::string without_encoding_type(defualt_locale); + auto n = without_encoding_type.find('.'); + without_encoding_type.erase(n, without_encoding_type.length() - n); + + flutter_locale = GetFlutterLocale(without_encoding_type.data()); + if (flutter_locale) { + FT_LOGI("Choose Default locale[%s]", without_encoding_type.data()); + flutter_locales.push_back(flutter_locale); + } + + int32_t count = i18n_ulocale_count_available(); + for (int i = 0; i < count; i++) { + const char* locale = i18n_ulocale_get_available(i); + if (without_encoding_type.compare(locale) != 0) { + flutter_locale = GetFlutterLocale(locale); + if (flutter_locale) { + flutter_locales.push_back(flutter_locale); + } + } + } FT_LOGI("Send %zu available locales", flutter_locales.size()); // Send locales to engine @@ -30,6 +66,114 @@ void LocalizationChannel::SendLocales() { } } +void LocalizationChannel::SendPlatformResolvedLocale() { + const char* locale; + int ret = i18n_ulocale_get_default(&locale); + if (ret != I18N_ERROR_NONE) { + FT_LOGE("i18n_ulocale_get_default() failed."); + return; + } + + FlutterLocale* flutter_locale = GetFlutterLocale(locale); + if (!flutter_locale) { + FT_LOGE("Language code is required but not present."); + return; + } + + rapidjson::Document document; + auto& allocator = document.GetAllocator(); + + document.SetObject(); + document.AddMember("method", "setPlatformResolvedLocale", allocator); + + rapidjson::Value language_code, country_code, script_code, variant_code; + language_code.SetString(flutter_locale->language_code, allocator); + country_code.SetString( + flutter_locale->country_code ? flutter_locale->country_code : "", + allocator); + script_code.SetString( + flutter_locale->script_code ? flutter_locale->script_code : "", + allocator); + variant_code.SetString( + flutter_locale->variant_code ? flutter_locale->variant_code : "", + allocator); + + rapidjson::Value args(rapidjson::kArrayType); + args.Reserve(4, allocator); + args.PushBack(language_code, allocator); + args.PushBack(country_code, allocator); + args.PushBack(script_code, allocator); + args.PushBack(variant_code, allocator); + + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + if (!document.Accept(writer)) { + FT_LOGE("document.Accept failed!"); + return; + } + + engine_->SendPlatformMessage( + kChannelName, reinterpret_cast(buffer.GetString()), + buffer.GetSize(), nullptr, nullptr); + + DestroyFlutterLocale(flutter_locale); +} + +FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { + int capacity = 128; + char buffer[128] = {0}; + int bufSize; + int error; + char* language = nullptr; + char* country = nullptr; + char* script = nullptr; + char* variant = nullptr; + + // set language code, language code is a required field + error = i18n_ulocale_get_language(locale, buffer, capacity, &bufSize); + if (error == I18N_ERROR_NONE && bufSize > 0) { + language = new char[bufSize + 1]; + memcpy(language, buffer, bufSize); + language[bufSize] = '\0'; + } else { + FT_LOGE("i18n_ulocale_get_language failed!"); + return nullptr; + } + + // set country code, country code is an optional field + bufSize = i18n_ulocale_get_country(locale, buffer, capacity, &error); + if (error == I18N_ERROR_NONE && bufSize > 0) { + country = new char[bufSize + 1]; + memcpy(country, buffer, bufSize); + country[bufSize] = '\0'; + } + + // set script code, script code is an optional field + bufSize = i18n_ulocale_get_script(locale, buffer, capacity); + if (bufSize > 0) { + script = new char[bufSize + 1]; + memcpy(script, buffer, bufSize); + script[bufSize] = '\0'; + } + + // set variant code, variant code is an optional field + bufSize = i18n_ulocale_get_variant(locale, buffer, capacity); + if (bufSize > 0) { + variant = new char[bufSize + 1]; + memcpy(variant, buffer, bufSize); + variant[bufSize] = '\0'; + } + + FlutterLocale* flutter_locale = new FlutterLocale; + flutter_locale->struct_size = sizeof(FlutterLocale); + flutter_locale->language_code = language; + flutter_locale->country_code = country; + flutter_locale->script_code = script; + flutter_locale->variant_code = variant; + + return flutter_locale; +} + void LocalizationChannel::DestroyFlutterLocale(FlutterLocale* flutter_locale) { if (flutter_locale) { if (flutter_locale->language_code) { diff --git a/shell/platform/tizen/channels/localization_channel.h b/shell/platform/tizen/channels/localization_channel.h index 70005567f81fa..a5743a4cd3da4 100644 --- a/shell/platform/tizen/channels/localization_channel.h +++ b/shell/platform/tizen/channels/localization_channel.h @@ -5,8 +5,6 @@ #ifndef EMBEDDER_LOCALIZATION_CHANNEL_H_ #define EMBEDDER_LOCALIZATION_CHANNEL_H_ -#include - #include "flutter/shell/platform/embedder/embedder.h" namespace flutter { @@ -22,7 +20,6 @@ class LocalizationChannel { private: void SendPlatformResolvedLocale(); - std::vector GetFlutterLocales(); FlutterLocale* GetFlutterLocale(const char* locale); void DestroyFlutterLocale(FlutterLocale* flutter_locale); diff --git a/shell/platform/tizen/channels/localization_channel_device.cc b/shell/platform/tizen/channels/localization_channel_device.cc deleted file mode 100644 index 917e53aa822a7..0000000000000 --- a/shell/platform/tizen/channels/localization_channel_device.cc +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "localization_channel.h" - -#include -#include "rapidjson/document.h" -#include "rapidjson/writer.h" - -#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" -#include "flutter/shell/platform/tizen/tizen_log.h" - -namespace flutter { - -namespace { -constexpr char kChannelName[] = "flutter/localization"; -} - -void LocalizationChannel::SendPlatformResolvedLocale() { - const char* locale; - int ret = i18n_ulocale_get_default(&locale); - if (ret != I18N_ERROR_NONE) { - FT_LOGE("i18n_ulocale_get_default() failed."); - return; - } - - FlutterLocale* flutter_locale = GetFlutterLocale(locale); - if (!flutter_locale) { - FT_LOGE("Language code is required but not present."); - return; - } - - rapidjson::Document document; - auto& allocator = document.GetAllocator(); - - document.SetObject(); - document.AddMember("method", "setPlatformResolvedLocale", allocator); - - rapidjson::Value language_code, country_code, script_code, variant_code; - language_code.SetString(flutter_locale->language_code, allocator); - country_code.SetString( - flutter_locale->country_code ? flutter_locale->country_code : "", - allocator); - script_code.SetString( - flutter_locale->script_code ? flutter_locale->script_code : "", - allocator); - variant_code.SetString( - flutter_locale->variant_code ? flutter_locale->variant_code : "", - allocator); - - rapidjson::Value args(rapidjson::kArrayType); - args.Reserve(4, allocator); - args.PushBack(language_code, allocator); - args.PushBack(country_code, allocator); - args.PushBack(script_code, allocator); - args.PushBack(variant_code, allocator); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - if (!document.Accept(writer)) { - FT_LOGE("document.Accept failed!"); - return; - } - - engine_->SendPlatformMessage( - kChannelName, reinterpret_cast(buffer.GetString()), - buffer.GetSize(), nullptr, nullptr); - - DestroyFlutterLocale(flutter_locale); -} - -std::vector LocalizationChannel::GetFlutterLocales() { - const char* defualt_locale = nullptr; - FlutterLocale* flutter_locale = nullptr; - std::vector flutter_locales; - - int ret = i18n_ulocale_set_default(getenv("LANG")); - ret = i18n_ulocale_get_default(&defualt_locale); - if (ret != I18N_ERROR_NONE) { - FT_LOGE("i18n_ulocale_get_default() failed."); - return flutter_locales; - } - - std::string without_encoding_type(defualt_locale); - auto n = without_encoding_type.find('.'); - without_encoding_type.erase(n, without_encoding_type.length() - n); - - flutter_locale = GetFlutterLocale(without_encoding_type.data()); - if (flutter_locale) { - FT_LOGI("Choose Default locale[%s]", without_encoding_type.data()); - flutter_locales.push_back(flutter_locale); - } - - int32_t count = i18n_ulocale_count_available(); - for (int i = 0; i < count; i++) { - const char* locale = i18n_ulocale_get_available(i); - if (without_encoding_type.compare(locale) != 0) { - flutter_locale = GetFlutterLocale(locale); - if (flutter_locale) { - flutter_locales.push_back(flutter_locale); - } - } - } - return flutter_locales; -} - -FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { - int capacity = 128; - char buffer[128] = {0}; - int bufSize; - int error; - char* language = nullptr; - char* country = nullptr; - char* script = nullptr; - char* variant = nullptr; - - // set language code, language code is a required field - error = i18n_ulocale_get_language(locale, buffer, capacity, &bufSize); - if (error == I18N_ERROR_NONE && bufSize > 0) { - language = new char[bufSize + 1]; - memcpy(language, buffer, bufSize); - language[bufSize] = '\0'; - } else { - FT_LOGE("i18n_ulocale_get_language failed!"); - return nullptr; - } - - // set country code, country code is an optional field - bufSize = i18n_ulocale_get_country(locale, buffer, capacity, &error); - if (error == I18N_ERROR_NONE && bufSize > 0) { - country = new char[bufSize + 1]; - memcpy(country, buffer, bufSize); - country[bufSize] = '\0'; - } - - // set script code, script code is an optional field - bufSize = i18n_ulocale_get_script(locale, buffer, capacity); - if (bufSize > 0) { - script = new char[bufSize + 1]; - memcpy(script, buffer, bufSize); - script[bufSize] = '\0'; - } - - // set variant code, variant code is an optional field - bufSize = i18n_ulocale_get_variant(locale, buffer, capacity); - if (bufSize > 0) { - variant = new char[bufSize + 1]; - memcpy(variant, buffer, bufSize); - variant[bufSize] = '\0'; - } - - FlutterLocale* flutter_locale = new FlutterLocale; - flutter_locale->struct_size = sizeof(FlutterLocale); - flutter_locale->language_code = language; - flutter_locale->country_code = country; - flutter_locale->script_code = script; - flutter_locale->variant_code = variant; - - return flutter_locale; -} - -} // namespace flutter diff --git a/shell/platform/tizen/channels/localization_channel_stub.cc b/shell/platform/tizen/channels/localization_channel_stub.cc index f00faa6c4e2b3..810b10b60e14b 100644 --- a/shell/platform/tizen/channels/localization_channel_stub.cc +++ b/shell/platform/tizen/channels/localization_channel_stub.cc @@ -6,23 +6,10 @@ namespace flutter { -void LocalizationChannel::SendPlatformResolvedLocale() {} +LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine) {} -std::vector LocalizationChannel::GetFlutterLocales() { - FlutterLocale* flutter_locale = GetFlutterLocale(nullptr); - std::vector flutter_locales; - flutter_locales.push_back(flutter_locale); - return flutter_locales; -} +LocalizationChannel::~LocalizationChannel() {} -FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { - FlutterLocale* flutter_locale = new FlutterLocale; - flutter_locale->struct_size = sizeof(FlutterLocale); - flutter_locale->language_code = new char[1]; - flutter_locale->country_code = new char[1]; - flutter_locale->script_code = new char[1]; - flutter_locale->variant_code = new char[1]; - return flutter_locale; -} +void LocalizationChannel::SendLocales() {} } // namespace flutter diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index b430bedf710e6..274b63346bc6c 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -111,19 +111,6 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { return kSuccess; })); - // It should send locale info. - bool update_locales_called = false; - modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC( - UpdateLocales, - ([&update_locales_called](auto engine, const FlutterLocale** locales, - size_t locales_count) { - update_locales_called = true; - EXPECT_GT(locales_count, (size_t)0); - EXPECT_NE(locales, nullptr); - - return kSuccess; - })); - // And it should send initial settings info. bool settings_message_sent = false; modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC( @@ -139,8 +126,6 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { engine_->RunEngine(); EXPECT_TRUE(run_called); - EXPECT_TRUE(update_locales_called); - EXPECT_TRUE(settings_message_sent); EXPECT_TRUE(settings_message_sent); modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; From dbeaa9f865a0346d022669a8c5fa1d6c1fd0df88 Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Mon, 19 Jul 2021 07:46:35 +0900 Subject: [PATCH 4/6] Update minor things: * Update flutter_tizen_engine_unittest (localization) * Rename file : settings_channel_device.cc -> settings_channel_tizen.cc settings_channel_stub.cc -> settings_channel_linux.cc Signed-off-by: MuHong Byun --- shell/platform/tizen/BUILD.gn | 4 +- .../tizen/channels/settings_channel_linux.cc | 40 +++++++++++++++++++ .../tizen/channels/settings_channel_stub.cc | 18 --------- ...el_device.cc => settings_channel_tizen.cc} | 0 .../tizen/flutter_tizen_engine_unittest.cc | 14 +++++++ 5 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 shell/platform/tizen/channels/settings_channel_linux.cc delete mode 100644 shell/platform/tizen/channels/settings_channel_stub.cc rename shell/platform/tizen/channels/{settings_channel_device.cc => settings_channel_tizen.cc} (100%) diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 962ba74506096..3a2bc8ead4abd 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -130,7 +130,7 @@ template("embedder_for_profile") { "channels/localization_channel.cc", "channels/platform_channel.cc", "channels/settings_channel.cc", - "channels/settings_channel_device.cc", + "channels/settings_channel_tizen.cc", "external_texture_pixel_gl.cc", "external_texture_surface_gl.cc", "tizen_log.cc", @@ -247,7 +247,7 @@ template("embedder_executable") { "channels/localization_channel_stub.cc", "channels/platform_channel_stub.cc", "channels/settings_channel.cc", - "channels/settings_channel_stub.cc", + "channels/settings_channel_linux.cc", "external_texture_pixel_gl_stub.cc", "external_texture_surface_gl_stub.cc", "tizen_log_stub.cc", diff --git a/shell/platform/tizen/channels/settings_channel_linux.cc b/shell/platform/tizen/channels/settings_channel_linux.cc new file mode 100644 index 0000000000000..6f5ad6a573e8d --- /dev/null +++ b/shell/platform/tizen/channels/settings_channel_linux.cc @@ -0,0 +1,40 @@ +// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "settings_channel.h" + +#include +#include + +namespace flutter { + +void SettingsChannel::Init() { + std::locale::global(std::locale("")); +} + +void SettingsChannel::Dispose() {} + +bool SettingsChannel::GetSettingValueOf24Format(bool* value) { + // This is a temporary implementation because I didn't know how to properly implement it. + // I believe someone will replace it with a better implementation. + // This function operates normally only in the following locale. + // en_US.UTF-8, ko_KR.UTF-8 + char buf[64]; + std::time_t current = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + if(!strftime(buf, sizeof(buf), "%c", std::localtime(¤t))){ + return false; + } + std::string current_local_time(buf); + if ((current_local_time.find("AM")!=std::string::npos) + || (current_local_time.find("PM")!=std::string::npos) + || (current_local_time.find("오전")!=std::string::npos) + || (current_local_time.find("오후")!=std::string::npos) + ){ + *value = true; + } + *value = false; + return true; +} + +} // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel_stub.cc b/shell/platform/tizen/channels/settings_channel_stub.cc deleted file mode 100644 index ef80e47385d51..0000000000000 --- a/shell/platform/tizen/channels/settings_channel_stub.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "settings_channel.h" - -namespace flutter { - -void SettingsChannel::Init() {} - -void SettingsChannel::Dispose() {} - -bool SettingsChannel::GetSettingValueOf24Format(bool* value) { - *value = false; - return true; -} - -} // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel_device.cc b/shell/platform/tizen/channels/settings_channel_tizen.cc similarity index 100% rename from shell/platform/tizen/channels/settings_channel_device.cc rename to shell/platform/tizen/channels/settings_channel_tizen.cc diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index 274b63346bc6c..d94b668bcad7d 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -111,6 +111,19 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { return kSuccess; })); + // It should send locale info. + bool update_locales_called = false; + modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC( + UpdateLocales, + ([&update_locales_called](auto engine, const FlutterLocale** locales, + size_t locales_count) { + update_locales_called = true; + EXPECT_GT(locales_count, (size_t)0); + EXPECT_NE(locales, nullptr); + + return kSuccess; + })); + // And it should send initial settings info. bool settings_message_sent = false; modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC( @@ -126,6 +139,7 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { engine_->RunEngine(); EXPECT_TRUE(run_called); + EXPECT_TRUE(update_locales_called); EXPECT_TRUE(settings_message_sent); modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; From 2d187dc7184d76ed63cb204e2928927bae28aa81 Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Mon, 19 Jul 2021 11:16:51 +0900 Subject: [PATCH 5/6] Apply review's comment Signed-off-by: MuHong Byun --- .../tizen/channels/settings_channel.cc | 15 +++++-------- .../tizen/channels/settings_channel.h | 2 +- .../tizen/channels/settings_channel_linux.cc | 22 ++----------------- .../tizen/channels/settings_channel_tizen.cc | 8 +++---- .../tizen/flutter_tizen_engine_unittest.cc | 2 +- 5 files changed, 14 insertions(+), 35 deletions(-) diff --git a/shell/platform/tizen/channels/settings_channel.cc b/shell/platform/tizen/channels/settings_channel.cc index 2cd5515d98bdc..28377a5a3070b 100644 --- a/shell/platform/tizen/channels/settings_channel.cc +++ b/shell/platform/tizen/channels/settings_channel.cc @@ -32,15 +32,12 @@ SettingsChannel::~SettingsChannel() { } void SettingsChannel::SendSettingsEvent() { - bool value = false; - if (GetSettingValueOf24Format(&value)) { - rapidjson::Document event(rapidjson::kObjectType); - auto& allocator = event.GetAllocator(); - event.AddMember(kTextScaleFactorKey, 1.0, allocator); - event.AddMember(kPlatformBrightnessKey, "light", allocator); - event.AddMember(kAlwaysUse24HourFormatKey, value, allocator); - channel_->Send(event); - } + rapidjson::Document event(rapidjson::kObjectType); + auto& allocator = event.GetAllocator(); + event.AddMember(kTextScaleFactorKey, 1.0, allocator); + event.AddMember(kPlatformBrightnessKey, "light", allocator); + event.AddMember(kAlwaysUse24HourFormatKey, Prefer24HourTime(), allocator); + channel_->Send(event); } } // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel.h b/shell/platform/tizen/channels/settings_channel.h index 3ba36c9d6dfa6..0b864c98fed40 100644 --- a/shell/platform/tizen/channels/settings_channel.h +++ b/shell/platform/tizen/channels/settings_channel.h @@ -20,7 +20,7 @@ class SettingsChannel { void SendSettingsEvent(); private: - bool GetSettingValueOf24Format(bool* value); + bool Prefer24HourTime(); void Init(); void Dispose(); diff --git a/shell/platform/tizen/channels/settings_channel_linux.cc b/shell/platform/tizen/channels/settings_channel_linux.cc index 6f5ad6a573e8d..f11ef08a51929 100644 --- a/shell/platform/tizen/channels/settings_channel_linux.cc +++ b/shell/platform/tizen/channels/settings_channel_linux.cc @@ -15,26 +15,8 @@ void SettingsChannel::Init() { void SettingsChannel::Dispose() {} -bool SettingsChannel::GetSettingValueOf24Format(bool* value) { - // This is a temporary implementation because I didn't know how to properly implement it. - // I believe someone will replace it with a better implementation. - // This function operates normally only in the following locale. - // en_US.UTF-8, ko_KR.UTF-8 - char buf[64]; - std::time_t current = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - if(!strftime(buf, sizeof(buf), "%c", std::localtime(¤t))){ - return false; - } - std::string current_local_time(buf); - if ((current_local_time.find("AM")!=std::string::npos) - || (current_local_time.find("PM")!=std::string::npos) - || (current_local_time.find("오전")!=std::string::npos) - || (current_local_time.find("오후")!=std::string::npos) - ){ - *value = true; - } - *value = false; - return true; +bool SettingsChannel::Prefer24HourTime() { + return false; } } // namespace flutter diff --git a/shell/platform/tizen/channels/settings_channel_tizen.cc b/shell/platform/tizen/channels/settings_channel_tizen.cc index a42c06cc3f981..be86a732bfc9a 100644 --- a/shell/platform/tizen/channels/settings_channel_tizen.cc +++ b/shell/platform/tizen/channels/settings_channel_tizen.cc @@ -23,13 +23,13 @@ void SettingsChannel::Dispose() { SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR); } -bool SettingsChannel::GetSettingValueOf24Format(bool* value) { +bool SettingsChannel::Prefer24HourTime() { + bool value = false; if (system_settings_get_value_bool( - SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, value) == + SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &value) == SYSTEM_SETTINGS_ERROR_NONE) { - return true; } - return false; + return value; } } // namespace flutter diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index d94b668bcad7d..3eec89cdaa606 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -93,7 +93,6 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { size_t version, const FlutterRendererConfig* config, const FlutterProjectArgs* args, void* user_data, FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) { - std::string current_path = std::filesystem::current_path().string(); run_called = true; *engine_out = reinterpret_cast(1); @@ -144,5 +143,6 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; } + } // namespace testing } // namespace flutter From 22c726c49137ef7a504ca7fe3b5c8ec3fac2ad14 Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Mon, 19 Jul 2021 14:01:50 +0900 Subject: [PATCH 6/6] Add review's commit Signed-off-by: MuHong Byun --- shell/platform/tizen/channels/settings_channel_tizen.cc | 3 ++- shell/platform/tizen/flutter_tizen_engine_unittest.cc | 3 +-- .../tizen/flutter_tizen_texture_registrar_unittests.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/platform/tizen/channels/settings_channel_tizen.cc b/shell/platform/tizen/channels/settings_channel_tizen.cc index be86a732bfc9a..9253b22c67506 100644 --- a/shell/platform/tizen/channels/settings_channel_tizen.cc +++ b/shell/platform/tizen/channels/settings_channel_tizen.cc @@ -28,8 +28,9 @@ bool SettingsChannel::Prefer24HourTime() { if (system_settings_get_value_bool( SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &value) == SYSTEM_SETTINGS_ERROR_NONE) { + return value; } - return value; + return false; } } // namespace flutter diff --git a/shell/platform/tizen/flutter_tizen_engine_unittest.cc b/shell/platform/tizen/flutter_tizen_engine_unittest.cc index 3eec89cdaa606..2ffd863c03a10 100644 --- a/shell/platform/tizen/flutter_tizen_engine_unittest.cc +++ b/shell/platform/tizen/flutter_tizen_engine_unittest.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include +#include #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/testing/engine_modifier.h" -#include "gtest/gtest.h" namespace flutter { namespace testing { diff --git a/shell/platform/tizen/flutter_tizen_texture_registrar_unittests.cc b/shell/platform/tizen/flutter_tizen_texture_registrar_unittests.cc index 1ec19707c5433..803c8b0ccef7e 100644 --- a/shell/platform/tizen/flutter_tizen_texture_registrar_unittests.cc +++ b/shell/platform/tizen/flutter_tizen_texture_registrar_unittests.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/flutter_tizen_texture_registrar.h" #include "flutter/shell/platform/tizen/testing/engine_modifier.h" -#include "gtest/gtest.h" namespace flutter { namespace testing {