From 0a599567ce79a80d8d511505d34fa810b11e034e Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Tue, 28 Mar 2017 20:11:15 +0000 Subject: Merge "Add the missing sr-Latn into png files and rename the png locale header" am: 713d915636 am: dc235b5ab9 am: 5ec12126f0 Change-Id: Ia6b861c91958d3be23a4a7456d6d5d8e4a1607c8 (cherry picked from commit 9166f66eee883d6d6cc280a6c355e5528bb4a3f0) --- minui/Android.mk | 10 +++++-- minui/include/minui/minui.h | 3 ++- minui/resources.cpp | 33 +++++++++++++++++------- recovery.cpp | 2 +- res-hdpi/images/erasing_text.png | Bin 50680 -> 50184 bytes res-hdpi/images/error_text.png | Bin 36036 -> 35856 bytes res-hdpi/images/installing_security_text.png | Bin 113819 -> 113078 bytes res-hdpi/images/installing_text.png | Bin 104768 -> 104002 bytes res-hdpi/images/no_command_text.png | Bin 62037 -> 61417 bytes res-mdpi/images/erasing_text.png | Bin 29898 -> 29660 bytes res-mdpi/images/error_text.png | Bin 21147 -> 21123 bytes res-mdpi/images/installing_security_text.png | Bin 70010 -> 69603 bytes res-mdpi/images/installing_text.png | Bin 61701 -> 61281 bytes res-mdpi/images/no_command_text.png | Bin 34683 -> 34366 bytes res-xhdpi/images/erasing_text.png | Bin 73361 -> 73097 bytes res-xhdpi/images/error_text.png | Bin 52019 -> 52180 bytes res-xhdpi/images/installing_security_text.png | Bin 196871 -> 197146 bytes res-xhdpi/images/installing_text.png | Bin 175570 -> 175660 bytes res-xhdpi/images/no_command_text.png | Bin 86622 -> 86619 bytes res-xxhdpi/images/erasing_text.png | Bin 121608 -> 121637 bytes res-xxhdpi/images/error_text.png | Bin 84727 -> 84961 bytes res-xxhdpi/images/installing_security_text.png | Bin 447158 -> 447228 bytes res-xxhdpi/images/installing_text.png | Bin 415889 -> 416000 bytes res-xxhdpi/images/no_command_text.png | Bin 243028 -> 243226 bytes res-xxxhdpi/images/erasing_text.png | Bin 263768 -> 263646 bytes res-xxxhdpi/images/error_text.png | Bin 176936 -> 178458 bytes res-xxxhdpi/images/installing_security_text.png | Bin 610107 -> 610223 bytes res-xxxhdpi/images/installing_text.png | Bin 567834 -> 567987 bytes res-xxxhdpi/images/no_command_text.png | Bin 331159 -> 331473 bytes tests/unit/locale_test.cpp | 21 ++++++++------- 30 files changed, 45 insertions(+), 24 deletions(-) diff --git a/minui/Android.mk b/minui/Android.mk index 281f64912..4dfc65f8a 100644 --- a/minui/Android.mk +++ b/minui/Android.mk @@ -28,7 +28,10 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \ libdrm \ libsync_recovery -LOCAL_STATIC_LIBRARIES := libpng +LOCAL_STATIC_LIBRARIES := \ + libpng \ + libbase + LOCAL_CFLAGS := -Werror LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include @@ -61,7 +64,10 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libminui LOCAL_WHOLE_STATIC_LIBRARIES += libminui -LOCAL_SHARED_LIBRARIES := libpng +LOCAL_SHARED_LIBRARIES := \ + libpng \ + libbase + LOCAL_CFLAGS := -Werror LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index a1749dfe6..78dd4cb98 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -20,6 +20,7 @@ #include #include +#include // // Graphics. @@ -93,7 +94,7 @@ int ev_get_epollfd(); // Resources // -bool matches_locale(const char* prefix, const char* locale); +bool matches_locale(const std::string& prefix, const std::string& locale); // res_create_*_surface() functions return 0 if no error, else // negative. diff --git a/minui/resources.cpp b/minui/resources.cpp index c0f9c5c85..86c731b02 100644 --- a/minui/resources.cpp +++ b/minui/resources.cpp @@ -25,8 +25,11 @@ #include #include +#include +#include #include +#include #include #include "minui/minui.h" @@ -371,16 +374,26 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) { // This function tests if a locale string stored in PNG (prefix) matches // the locale string provided by the system (locale). -bool matches_locale(const char* prefix, const char* locale) { - if (locale == nullptr) { - return false; - } - - // Return true if the whole string of prefix matches the top part of - // locale. For instance, prefix == "en" matches locale == "en_US"; - // and prefix == "zh_CN" matches locale == "zh_CN_#Hans". - - return (strncmp(prefix, locale, strlen(prefix)) == 0); +bool matches_locale(const std::string& prefix, const std::string& locale) { + // According to the BCP 47 format, A locale string may consists of: + // language-{extlang}-{script}-{region}-{variant} + // The locale headers in PNG mostly consist of language-{region} except for sr-Latn, and some + // android's system locale can have the format language-{script}-{region}. + + // Return true if the whole string of prefix matches the top part of locale. Otherwise try to + // match the locale string without the {script} section. + // For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale + // == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN". + if (android::base::StartsWith(locale, prefix.c_str())) { + return true; + } + + size_t separator = prefix.find('-'); + if (separator == std::string::npos) { + return false; + } + std::regex loc_regex(prefix.substr(0, separator) + "-[A-Za-z]*" + prefix.substr(separator)); + return std::regex_match(locale, loc_regex); } int res_create_localized_alpha_surface(const char* name, diff --git a/recovery.cpp b/recovery.cpp index c2262161a..b24efa963 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -122,7 +122,7 @@ static const int BATTERY_READ_TIMEOUT_IN_SEC = 10; static const int BATTERY_OK_PERCENTAGE = 20; static const int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15; static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe"; -static constexpr const char* DEFAULT_LOCALE = "en_US"; +static constexpr const char* DEFAULT_LOCALE = "en-US"; static std::string locale; static bool has_cache = false; diff --git a/res-hdpi/images/erasing_text.png b/res-hdpi/images/erasing_text.png index 684fc7c6c..0982544d2 100644 Binary files a/res-hdpi/images/erasing_text.png and b/res-hdpi/images/erasing_text.png differ diff --git a/res-hdpi/images/error_text.png b/res-hdpi/images/error_text.png index 00c485d70..3a06f6eb1 100644 Binary files a/res-hdpi/images/error_text.png and b/res-hdpi/images/error_text.png differ diff --git a/res-hdpi/images/installing_security_text.png b/res-hdpi/images/installing_security_text.png index dadcfc32b..b1acd2336 100644 Binary files a/res-hdpi/images/installing_security_text.png and b/res-hdpi/images/installing_security_text.png differ diff --git a/res-hdpi/images/installing_text.png b/res-hdpi/images/installing_text.png index abe73b4b9..f0f5d8b6c 100644 Binary files a/res-hdpi/images/installing_text.png and b/res-hdpi/images/installing_text.png differ diff --git a/res-hdpi/images/no_command_text.png b/res-hdpi/images/no_command_text.png index 958e10613..def503678 100644 Binary files a/res-hdpi/images/no_command_text.png and b/res-hdpi/images/no_command_text.png differ diff --git a/res-mdpi/images/erasing_text.png b/res-mdpi/images/erasing_text.png index 10e317829..82b4461ba 100644 Binary files a/res-mdpi/images/erasing_text.png and b/res-mdpi/images/erasing_text.png differ diff --git a/res-mdpi/images/error_text.png b/res-mdpi/images/error_text.png index 0022d10c1..adb45131f 100644 Binary files a/res-mdpi/images/error_text.png and b/res-mdpi/images/error_text.png differ diff --git a/res-mdpi/images/installing_security_text.png b/res-mdpi/images/installing_security_text.png index 7a4cd414b..54e556448 100644 Binary files a/res-mdpi/images/installing_security_text.png and b/res-mdpi/images/installing_security_text.png differ diff --git a/res-mdpi/images/installing_text.png b/res-mdpi/images/installing_text.png index ee95e569c..d42331820 100644 Binary files a/res-mdpi/images/installing_text.png and b/res-mdpi/images/installing_text.png differ diff --git a/res-mdpi/images/no_command_text.png b/res-mdpi/images/no_command_text.png index af7660908..cd77ff457 100644 Binary files a/res-mdpi/images/no_command_text.png and b/res-mdpi/images/no_command_text.png differ diff --git a/res-xhdpi/images/erasing_text.png b/res-xhdpi/images/erasing_text.png index 91cc35871..333edbe27 100644 Binary files a/res-xhdpi/images/erasing_text.png and b/res-xhdpi/images/erasing_text.png differ diff --git a/res-xhdpi/images/error_text.png b/res-xhdpi/images/error_text.png index 772b139e6..e26258438 100644 Binary files a/res-xhdpi/images/error_text.png and b/res-xhdpi/images/error_text.png differ diff --git a/res-xhdpi/images/installing_security_text.png b/res-xhdpi/images/installing_security_text.png index a7113a04a..e0f0f3ea7 100644 Binary files a/res-xhdpi/images/installing_security_text.png and b/res-xhdpi/images/installing_security_text.png differ diff --git a/res-xhdpi/images/installing_text.png b/res-xhdpi/images/installing_text.png index 566eb0658..a7e67f512 100644 Binary files a/res-xhdpi/images/installing_text.png and b/res-xhdpi/images/installing_text.png differ diff --git a/res-xhdpi/images/no_command_text.png b/res-xhdpi/images/no_command_text.png index b8da125cb..13aef7b71 100644 Binary files a/res-xhdpi/images/no_command_text.png and b/res-xhdpi/images/no_command_text.png differ diff --git a/res-xxhdpi/images/erasing_text.png b/res-xxhdpi/images/erasing_text.png index 86693f435..80e7c475e 100644 Binary files a/res-xxhdpi/images/erasing_text.png and b/res-xxhdpi/images/erasing_text.png differ diff --git a/res-xxhdpi/images/error_text.png b/res-xxhdpi/images/error_text.png index 9c4bcab95..32a1965b8 100644 Binary files a/res-xxhdpi/images/error_text.png and b/res-xxhdpi/images/error_text.png differ diff --git a/res-xxhdpi/images/installing_security_text.png b/res-xxhdpi/images/installing_security_text.png index f5ec698f8..c53c9ac21 100644 Binary files a/res-xxhdpi/images/installing_security_text.png and b/res-xxhdpi/images/installing_security_text.png differ diff --git a/res-xxhdpi/images/installing_text.png b/res-xxhdpi/images/installing_text.png index 100a5b303..38b18d20d 100644 Binary files a/res-xxhdpi/images/installing_text.png and b/res-xxhdpi/images/installing_text.png differ diff --git a/res-xxhdpi/images/no_command_text.png b/res-xxhdpi/images/no_command_text.png index 590030c8b..a0666d8dc 100644 Binary files a/res-xxhdpi/images/no_command_text.png and b/res-xxhdpi/images/no_command_text.png differ diff --git a/res-xxxhdpi/images/erasing_text.png b/res-xxxhdpi/images/erasing_text.png index 4cf5d76e8..4f7b37b51 100644 Binary files a/res-xxxhdpi/images/erasing_text.png and b/res-xxxhdpi/images/erasing_text.png differ diff --git a/res-xxxhdpi/images/error_text.png b/res-xxxhdpi/images/error_text.png index 8dd6f1236..052bf2142 100644 Binary files a/res-xxxhdpi/images/error_text.png and b/res-xxxhdpi/images/error_text.png differ diff --git a/res-xxxhdpi/images/installing_security_text.png b/res-xxxhdpi/images/installing_security_text.png index fa06f3147..a9e739b17 100644 Binary files a/res-xxxhdpi/images/installing_security_text.png and b/res-xxxhdpi/images/installing_security_text.png differ diff --git a/res-xxxhdpi/images/installing_text.png b/res-xxxhdpi/images/installing_text.png index d0f930160..2d1948677 100644 Binary files a/res-xxxhdpi/images/installing_text.png and b/res-xxxhdpi/images/installing_text.png differ diff --git a/res-xxxhdpi/images/no_command_text.png b/res-xxxhdpi/images/no_command_text.png index 233aec468..ee0c23865 100644 Binary files a/res-xxxhdpi/images/no_command_text.png and b/res-xxxhdpi/images/no_command_text.png differ diff --git a/tests/unit/locale_test.cpp b/tests/unit/locale_test.cpp index f73235005..cdaba0e8b 100644 --- a/tests/unit/locale_test.cpp +++ b/tests/unit/locale_test.cpp @@ -19,14 +19,15 @@ #include "minui/minui.h" TEST(LocaleTest, Misc) { - EXPECT_TRUE(matches_locale("zh_CN", "zh_CN_#Hans")); - EXPECT_TRUE(matches_locale("zh", "zh_CN_#Hans")); - EXPECT_FALSE(matches_locale("zh_HK", "zh_CN_#Hans")); - EXPECT_TRUE(matches_locale("en_GB", "en_GB")); - EXPECT_TRUE(matches_locale("en", "en_GB")); - EXPECT_FALSE(matches_locale("en_GB", "en")); - EXPECT_FALSE(matches_locale("en_GB", "en_US")); - EXPECT_FALSE(matches_locale("en_US", "")); - // Empty locale prefix in the PNG file will match the input locale. - EXPECT_TRUE(matches_locale("", "en_US")); + EXPECT_TRUE(matches_locale("zh-CN", "zh-Hans-CN")); + EXPECT_TRUE(matches_locale("zh", "zh-Hans-CN")); + EXPECT_FALSE(matches_locale("zh-HK", "zh-Hans-CN")); + EXPECT_TRUE(matches_locale("en-GB", "en-GB")); + EXPECT_TRUE(matches_locale("en", "en-GB")); + EXPECT_FALSE(matches_locale("en-GB", "en")); + EXPECT_FALSE(matches_locale("en-GB", "en-US")); + EXPECT_FALSE(matches_locale("en-US", "")); + // Empty locale prefix in the PNG file will match the input locale. + EXPECT_TRUE(matches_locale("", "en-US")); + EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA")); } -- cgit v1.2.3