aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2017-03-28 14:42:53 -0500
committerGerrit Code Review2017-03-28 14:42:54 -0500
commit713d915636d64d42bf94e3cf93e3c469201129d6 (patch)
tree762e0afe7b612674b2d83c964c89b63ead3c8794
parent34df98ee6dfaec9b95c2f5d3e6f64c0daacc1958 (diff)
parent2078b22e4145fef2648cc714eae6588353940c4b (diff)
downloadplatform-bootable-recovery-713d915636d64d42bf94e3cf93e3c469201129d6.tar.gz
platform-bootable-recovery-713d915636d64d42bf94e3cf93e3c469201129d6.tar.xz
platform-bootable-recovery-713d915636d64d42bf94e3cf93e3c469201129d6.zip
Merge "Add the missing sr-Latn into png files and rename the png locale header"
-rw-r--r--minui/Android.mk10
-rw-r--r--minui/include/minui/minui.h3
-rw-r--r--minui/resources.cpp33
-rw-r--r--recovery.cpp2
-rw-r--r--res-hdpi/images/erasing_text.pngbin50680 -> 50184 bytes
-rw-r--r--res-hdpi/images/error_text.pngbin36036 -> 35856 bytes
-rw-r--r--res-hdpi/images/installing_security_text.pngbin113819 -> 113078 bytes
-rw-r--r--res-hdpi/images/installing_text.pngbin104768 -> 104002 bytes
-rw-r--r--res-hdpi/images/no_command_text.pngbin62037 -> 61417 bytes
-rw-r--r--res-mdpi/images/erasing_text.pngbin29898 -> 29660 bytes
-rw-r--r--res-mdpi/images/error_text.pngbin21147 -> 21123 bytes
-rw-r--r--res-mdpi/images/installing_security_text.pngbin70010 -> 69603 bytes
-rw-r--r--res-mdpi/images/installing_text.pngbin61701 -> 61281 bytes
-rw-r--r--res-mdpi/images/no_command_text.pngbin34683 -> 34366 bytes
-rw-r--r--res-xhdpi/images/erasing_text.pngbin73361 -> 73097 bytes
-rw-r--r--res-xhdpi/images/error_text.pngbin52019 -> 52180 bytes
-rw-r--r--res-xhdpi/images/installing_security_text.pngbin196871 -> 197146 bytes
-rw-r--r--res-xhdpi/images/installing_text.pngbin175570 -> 175660 bytes
-rw-r--r--res-xhdpi/images/no_command_text.pngbin86622 -> 86619 bytes
-rw-r--r--res-xxhdpi/images/erasing_text.pngbin121608 -> 121637 bytes
-rw-r--r--res-xxhdpi/images/error_text.pngbin84727 -> 84961 bytes
-rw-r--r--res-xxhdpi/images/installing_security_text.pngbin447158 -> 447228 bytes
-rw-r--r--res-xxhdpi/images/installing_text.pngbin415889 -> 416000 bytes
-rw-r--r--res-xxhdpi/images/no_command_text.pngbin243028 -> 243226 bytes
-rw-r--r--res-xxxhdpi/images/erasing_text.pngbin263768 -> 263646 bytes
-rw-r--r--res-xxxhdpi/images/error_text.pngbin176936 -> 178458 bytes
-rw-r--r--res-xxxhdpi/images/installing_security_text.pngbin610107 -> 610223 bytes
-rw-r--r--res-xxxhdpi/images/installing_text.pngbin567834 -> 567987 bytes
-rw-r--r--res-xxxhdpi/images/no_command_text.pngbin331159 -> 331473 bytes
-rw-r--r--tests/unit/locale_test.cpp21
30 files changed, 45 insertions, 24 deletions
diff --git a/minui/Android.mk b/minui/Android.mk
index 281f6491..4dfc65f8 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -28,7 +28,10 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
28 libdrm \ 28 libdrm \
29 libsync_recovery 29 libsync_recovery
30 30
31LOCAL_STATIC_LIBRARIES := libpng 31LOCAL_STATIC_LIBRARIES := \
32 libpng \
33 libbase
34
32LOCAL_CFLAGS := -Werror 35LOCAL_CFLAGS := -Werror
33LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 36LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
34LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 37LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
@@ -61,7 +64,10 @@ include $(BUILD_STATIC_LIBRARY)
61include $(CLEAR_VARS) 64include $(CLEAR_VARS)
62LOCAL_MODULE := libminui 65LOCAL_MODULE := libminui
63LOCAL_WHOLE_STATIC_LIBRARIES += libminui 66LOCAL_WHOLE_STATIC_LIBRARIES += libminui
64LOCAL_SHARED_LIBRARIES := libpng 67LOCAL_SHARED_LIBRARIES := \
68 libpng \
69 libbase
70
65LOCAL_CFLAGS := -Werror 71LOCAL_CFLAGS := -Werror
66LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 72LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
67LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 73LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index a1749dfe..78dd4cb9 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -20,6 +20,7 @@
20#include <sys/types.h> 20#include <sys/types.h>
21 21
22#include <functional> 22#include <functional>
23#include <string>
23 24
24// 25//
25// Graphics. 26// Graphics.
@@ -93,7 +94,7 @@ int ev_get_epollfd();
93// Resources 94// Resources
94// 95//
95 96
96bool matches_locale(const char* prefix, const char* locale); 97bool matches_locale(const std::string& prefix, const std::string& locale);
97 98
98// res_create_*_surface() functions return 0 if no error, else 99// res_create_*_surface() functions return 0 if no error, else
99// negative. 100// negative.
diff --git a/minui/resources.cpp b/minui/resources.cpp
index c0f9c5c8..86c731b0 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -25,8 +25,11 @@
25#include <sys/types.h> 25#include <sys/types.h>
26#include <unistd.h> 26#include <unistd.h>
27 27
28#include <regex>
29#include <string>
28#include <vector> 30#include <vector>
29 31
32#include <android-base/strings.h>
30#include <png.h> 33#include <png.h>
31 34
32#include "minui/minui.h" 35#include "minui/minui.h"
@@ -371,16 +374,26 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
371 374
372// This function tests if a locale string stored in PNG (prefix) matches 375// This function tests if a locale string stored in PNG (prefix) matches
373// the locale string provided by the system (locale). 376// the locale string provided by the system (locale).
374bool matches_locale(const char* prefix, const char* locale) { 377bool matches_locale(const std::string& prefix, const std::string& locale) {
375 if (locale == nullptr) { 378 // According to the BCP 47 format, A locale string may consists of:
376 return false; 379 // language-{extlang}-{script}-{region}-{variant}
377 } 380 // The locale headers in PNG mostly consist of language-{region} except for sr-Latn, and some
378 381 // android's system locale can have the format language-{script}-{region}.
379 // Return true if the whole string of prefix matches the top part of 382
380 // locale. For instance, prefix == "en" matches locale == "en_US"; 383 // Return true if the whole string of prefix matches the top part of locale. Otherwise try to
381 // and prefix == "zh_CN" matches locale == "zh_CN_#Hans". 384 // match the locale string without the {script} section.
382 385 // For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale
383 return (strncmp(prefix, locale, strlen(prefix)) == 0); 386 // == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN".
387 if (android::base::StartsWith(locale, prefix.c_str())) {
388 return true;
389 }
390
391 size_t separator = prefix.find('-');
392 if (separator == std::string::npos) {
393 return false;
394 }
395 std::regex loc_regex(prefix.substr(0, separator) + "-[A-Za-z]*" + prefix.substr(separator));
396 return std::regex_match(locale, loc_regex);
384} 397}
385 398
386int res_create_localized_alpha_surface(const char* name, 399int res_create_localized_alpha_surface(const char* name,
diff --git a/recovery.cpp b/recovery.cpp
index c2262161..b24efa96 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -122,7 +122,7 @@ static const int BATTERY_READ_TIMEOUT_IN_SEC = 10;
122static const int BATTERY_OK_PERCENTAGE = 20; 122static const int BATTERY_OK_PERCENTAGE = 20;
123static const int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15; 123static const int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
124static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe"; 124static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";
125static constexpr const char* DEFAULT_LOCALE = "en_US"; 125static constexpr const char* DEFAULT_LOCALE = "en-US";
126 126
127static std::string locale; 127static std::string locale;
128static bool has_cache = false; 128static bool has_cache = false;
diff --git a/res-hdpi/images/erasing_text.png b/res-hdpi/images/erasing_text.png
index 684fc7c6..0982544d 100644
--- a/res-hdpi/images/erasing_text.png
+++ b/res-hdpi/images/erasing_text.png
Binary files differ
diff --git a/res-hdpi/images/error_text.png b/res-hdpi/images/error_text.png
index 00c485d7..3a06f6eb 100644
--- a/res-hdpi/images/error_text.png
+++ b/res-hdpi/images/error_text.png
Binary files differ
diff --git a/res-hdpi/images/installing_security_text.png b/res-hdpi/images/installing_security_text.png
index dadcfc32..b1acd233 100644
--- a/res-hdpi/images/installing_security_text.png
+++ b/res-hdpi/images/installing_security_text.png
Binary files differ
diff --git a/res-hdpi/images/installing_text.png b/res-hdpi/images/installing_text.png
index abe73b4b..f0f5d8b6 100644
--- a/res-hdpi/images/installing_text.png
+++ b/res-hdpi/images/installing_text.png
Binary files differ
diff --git a/res-hdpi/images/no_command_text.png b/res-hdpi/images/no_command_text.png
index 958e1061..def50367 100644
--- a/res-hdpi/images/no_command_text.png
+++ b/res-hdpi/images/no_command_text.png
Binary files differ
diff --git a/res-mdpi/images/erasing_text.png b/res-mdpi/images/erasing_text.png
index 10e31782..82b4461b 100644
--- a/res-mdpi/images/erasing_text.png
+++ b/res-mdpi/images/erasing_text.png
Binary files differ
diff --git a/res-mdpi/images/error_text.png b/res-mdpi/images/error_text.png
index 0022d10c..adb45131 100644
--- a/res-mdpi/images/error_text.png
+++ b/res-mdpi/images/error_text.png
Binary files differ
diff --git a/res-mdpi/images/installing_security_text.png b/res-mdpi/images/installing_security_text.png
index 7a4cd414..54e55644 100644
--- a/res-mdpi/images/installing_security_text.png
+++ b/res-mdpi/images/installing_security_text.png
Binary files differ
diff --git a/res-mdpi/images/installing_text.png b/res-mdpi/images/installing_text.png
index ee95e569..d4233182 100644
--- a/res-mdpi/images/installing_text.png
+++ b/res-mdpi/images/installing_text.png
Binary files differ
diff --git a/res-mdpi/images/no_command_text.png b/res-mdpi/images/no_command_text.png
index af766090..cd77ff45 100644
--- a/res-mdpi/images/no_command_text.png
+++ b/res-mdpi/images/no_command_text.png
Binary files differ
diff --git a/res-xhdpi/images/erasing_text.png b/res-xhdpi/images/erasing_text.png
index 91cc3587..333edbe2 100644
--- a/res-xhdpi/images/erasing_text.png
+++ b/res-xhdpi/images/erasing_text.png
Binary files differ
diff --git a/res-xhdpi/images/error_text.png b/res-xhdpi/images/error_text.png
index 772b139e..e2625843 100644
--- a/res-xhdpi/images/error_text.png
+++ b/res-xhdpi/images/error_text.png
Binary files differ
diff --git a/res-xhdpi/images/installing_security_text.png b/res-xhdpi/images/installing_security_text.png
index a7113a04..e0f0f3ea 100644
--- a/res-xhdpi/images/installing_security_text.png
+++ b/res-xhdpi/images/installing_security_text.png
Binary files differ
diff --git a/res-xhdpi/images/installing_text.png b/res-xhdpi/images/installing_text.png
index 566eb065..a7e67f51 100644
--- a/res-xhdpi/images/installing_text.png
+++ b/res-xhdpi/images/installing_text.png
Binary files differ
diff --git a/res-xhdpi/images/no_command_text.png b/res-xhdpi/images/no_command_text.png
index b8da125c..13aef7b7 100644
--- a/res-xhdpi/images/no_command_text.png
+++ b/res-xhdpi/images/no_command_text.png
Binary files differ
diff --git a/res-xxhdpi/images/erasing_text.png b/res-xxhdpi/images/erasing_text.png
index 86693f43..80e7c475 100644
--- a/res-xxhdpi/images/erasing_text.png
+++ b/res-xxhdpi/images/erasing_text.png
Binary files differ
diff --git a/res-xxhdpi/images/error_text.png b/res-xxhdpi/images/error_text.png
index 9c4bcab9..32a1965b 100644
--- a/res-xxhdpi/images/error_text.png
+++ b/res-xxhdpi/images/error_text.png
Binary files differ
diff --git a/res-xxhdpi/images/installing_security_text.png b/res-xxhdpi/images/installing_security_text.png
index f5ec698f..c53c9ac2 100644
--- a/res-xxhdpi/images/installing_security_text.png
+++ b/res-xxhdpi/images/installing_security_text.png
Binary files differ
diff --git a/res-xxhdpi/images/installing_text.png b/res-xxhdpi/images/installing_text.png
index 100a5b30..38b18d20 100644
--- a/res-xxhdpi/images/installing_text.png
+++ b/res-xxhdpi/images/installing_text.png
Binary files differ
diff --git a/res-xxhdpi/images/no_command_text.png b/res-xxhdpi/images/no_command_text.png
index 590030c8..a0666d8d 100644
--- a/res-xxhdpi/images/no_command_text.png
+++ b/res-xxhdpi/images/no_command_text.png
Binary files differ
diff --git a/res-xxxhdpi/images/erasing_text.png b/res-xxxhdpi/images/erasing_text.png
index 4cf5d76e..4f7b37b5 100644
--- a/res-xxxhdpi/images/erasing_text.png
+++ b/res-xxxhdpi/images/erasing_text.png
Binary files differ
diff --git a/res-xxxhdpi/images/error_text.png b/res-xxxhdpi/images/error_text.png
index 8dd6f123..052bf214 100644
--- a/res-xxxhdpi/images/error_text.png
+++ b/res-xxxhdpi/images/error_text.png
Binary files differ
diff --git a/res-xxxhdpi/images/installing_security_text.png b/res-xxxhdpi/images/installing_security_text.png
index fa06f314..a9e739b1 100644
--- a/res-xxxhdpi/images/installing_security_text.png
+++ b/res-xxxhdpi/images/installing_security_text.png
Binary files differ
diff --git a/res-xxxhdpi/images/installing_text.png b/res-xxxhdpi/images/installing_text.png
index d0f93016..2d194867 100644
--- a/res-xxxhdpi/images/installing_text.png
+++ b/res-xxxhdpi/images/installing_text.png
Binary files differ
diff --git a/res-xxxhdpi/images/no_command_text.png b/res-xxxhdpi/images/no_command_text.png
index 233aec46..ee0c2386 100644
--- a/res-xxxhdpi/images/no_command_text.png
+++ b/res-xxxhdpi/images/no_command_text.png
Binary files differ
diff --git a/tests/unit/locale_test.cpp b/tests/unit/locale_test.cpp
index f7323500..cdaba0e8 100644
--- a/tests/unit/locale_test.cpp
+++ b/tests/unit/locale_test.cpp
@@ -19,14 +19,15 @@
19#include "minui/minui.h" 19#include "minui/minui.h"
20 20
21TEST(LocaleTest, Misc) { 21TEST(LocaleTest, Misc) {
22 EXPECT_TRUE(matches_locale("zh_CN", "zh_CN_#Hans")); 22 EXPECT_TRUE(matches_locale("zh-CN", "zh-Hans-CN"));
23 EXPECT_TRUE(matches_locale("zh", "zh_CN_#Hans")); 23 EXPECT_TRUE(matches_locale("zh", "zh-Hans-CN"));
24 EXPECT_FALSE(matches_locale("zh_HK", "zh_CN_#Hans")); 24 EXPECT_FALSE(matches_locale("zh-HK", "zh-Hans-CN"));
25 EXPECT_TRUE(matches_locale("en_GB", "en_GB")); 25 EXPECT_TRUE(matches_locale("en-GB", "en-GB"));
26 EXPECT_TRUE(matches_locale("en", "en_GB")); 26 EXPECT_TRUE(matches_locale("en", "en-GB"));
27 EXPECT_FALSE(matches_locale("en_GB", "en")); 27 EXPECT_FALSE(matches_locale("en-GB", "en"));
28 EXPECT_FALSE(matches_locale("en_GB", "en_US")); 28 EXPECT_FALSE(matches_locale("en-GB", "en-US"));
29 EXPECT_FALSE(matches_locale("en_US", "")); 29 EXPECT_FALSE(matches_locale("en-US", ""));
30 // Empty locale prefix in the PNG file will match the input locale. 30 // Empty locale prefix in the PNG file will match the input locale.
31 EXPECT_TRUE(matches_locale("", "en_US")); 31 EXPECT_TRUE(matches_locale("", "en-US"));
32 EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA"));
32} 33}