diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2016-02-01 13:49:52 -0800 |
---|---|---|
committer | Roozbeh Pournader <roozbeh@google.com> | 2016-02-01 14:56:52 -0800 |
commit | 27953c349fa1c46698f57ae5f26339560c21adac (patch) | |
tree | e6be55731d70f74688c8ba84c91fd31d7901cc0b /libs/androidfw/LocaleData.cpp | |
parent | c92035b1aa2b064d97377795553c11261f7e7cce (diff) |
Make default resources a better match for en-US requests
When locale fallback landed, resources which specified an 'English'
locale started to be considered a better match for en-US, even though
traditionally, apps tend to ship US English resources under their
default locale.
This fixes that, and makes en-US requests match default locales.
Bug: 26756573
Bug: 26789680
Bug: 26803868
Change-Id: I460c276bfc6ddba0439dcdf87497a0aece0fa05d
Diffstat (limited to 'libs/androidfw/LocaleData.cpp')
-rw-r--r-- | libs/androidfw/LocaleData.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libs/androidfw/LocaleData.cpp b/libs/androidfw/LocaleData.cpp index c0c3ab883a42..038ef5839fe2 100644 --- a/libs/androidfw/LocaleData.cpp +++ b/libs/androidfw/LocaleData.cpp @@ -70,13 +70,17 @@ uint32_t findParent(uint32_t packed_locale, const char* script) { // // Returns the number of ancestors written in the output, which is always // at least one. +// +// (If 'out' is nullptr, we do everything the same way but we simply don't write +// any results in 'out'.) size_t findAncestors(uint32_t* out, ssize_t* stop_list_index, uint32_t packed_locale, const char* script, const uint32_t* stop_list, size_t stop_set_length) { uint32_t ancestor = packed_locale; size_t count = 0; do { - out[count++] = ancestor; + if (out != nullptr) out[count] = ancestor; + count++; for (size_t i = 0; i < stop_set_length; i++) { if (stop_list[i] == ancestor) { *stop_list_index = (ssize_t) i; @@ -93,10 +97,9 @@ size_t findDistance(uint32_t supported, const char* script, const uint32_t* request_ancestors, size_t request_ancestors_count) { - uint32_t supported_ancestors[MAX_PARENT_DEPTH+1]; ssize_t request_ancestors_index; const size_t supported_ancestor_count = findAncestors( - supported_ancestors, &request_ancestors_index, + nullptr, &request_ancestors_index, supported, script, request_ancestors, request_ancestors_count); // Since both locales share the same root, there will always be a shared @@ -198,4 +201,19 @@ void localeDataComputeScript(char out[4], const char* language, const char* regi } } +const uint32_t ENGLISH_STOP_LIST[2] = { + 0x656E0000lu, // en + 0x656E8400lu, // en-001 +}; +const char ENGLISH_CHARS[2] = {'e', 'n'}; +const char LATIN_CHARS[4] = {'L', 'a', 't', 'n'}; + +bool localeDataIsCloseToUsEnglish(const char* region) { + const uint32_t locale = packLocale(ENGLISH_CHARS, region); + ssize_t stop_list_index; + findAncestors(nullptr, &stop_list_index, locale, LATIN_CHARS, ENGLISH_STOP_LIST, 2); + // A locale is like US English if we see "en" before "en-001" in its ancestor list. + return stop_list_index == 0; // 'en' is first in ENGLISH_STOP_LIST +} + } // namespace android |