summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager.cpp
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2016-06-13 18:10:49 -0700
committerRoozbeh Pournader <roozbeh@google.com>2016-06-15 11:45:58 -0700
commit7e5f96f1a37e51164a594930ecc862a94cc8c231 (patch)
treec7ec1ba4e88cef333d0cb7786be6c245ca2de22a /libs/androidfw/AssetManager.cpp
parent16075e160b82398d0daa71dc531f7b78ed37c5cf (diff)
Move matching Tagalog and Filipino to ResourceTypes.cpp
Previously, if a mix of "fil" and "tl" resources existed in Resources (from mixing resources from libraries for example), only resources from one or the other would be chosen, resulting in default resources getting surprisingly used. Now, we resolve the equivalent languages at a per-resource levels (breaking ties for the identical code). Also, previously if both "tl" and "fil" resources were present in assets, getLocales() could return a list with duplicate locales. This change removes Filipino duplicates in the return value of AssetManager::getLocales(). Finally, there was a bug in the replacement of "tl" with "fil" that considered any locale starting with the letter "tl" to be Tagalog. This failed in case of various languages, including Klingon ("tlh") and Tlingit ("tli"). It's now fixed. Bug: 29073000 Change-Id: I0e8b9ae337ced2e640a2575897948c4c5ca307d3
Diffstat (limited to 'libs/androidfw/AssetManager.cpp')
-rw-r--r--libs/androidfw/AssetManager.cpp58
1 files changed, 1 insertions, 57 deletions
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index f50cff4387d2..641a7ffc2a78 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -355,14 +355,6 @@ void AssetManager::setLocale(const char* locale)
}
-static const char kFilPrefix[] = "fil";
-static const char kTlPrefix[] = "tl";
-
-// The sizes of the prefixes, excluding the 0 suffix.
-// char.
-static const int kFilPrefixLen = sizeof(kFilPrefix) - 1;
-static const int kTlPrefixLen = sizeof(kTlPrefix) - 1;
-
void AssetManager::setLocaleLocked(const char* locale)
{
if (mLocale != NULL) {
@@ -372,44 +364,6 @@ void AssetManager::setLocaleLocked(const char* locale)
delete[] mLocale;
}
- // If we're attempting to set a locale that starts with "fil",
- // we should convert it to "tl" for backwards compatibility since
- // we've been using "tl" instead of "fil" prior to L.
- //
- // If the resource table already has entries for "fil", we use that
- // instead of attempting a fallback.
- if (strncmp(locale, kFilPrefix, kFilPrefixLen) == 0) {
- Vector<String8> locales;
- ResTable* res = mResources;
- if (res != NULL) {
- res->getLocales(&locales);
- }
- const size_t localesSize = locales.size();
- bool hasFil = false;
- for (size_t i = 0; i < localesSize; ++i) {
- if (locales[i].find(kFilPrefix) == 0) {
- hasFil = true;
- break;
- }
- }
-
-
- if (!hasFil) {
- const size_t newLocaleLen = strlen(locale);
- // This isn't a bug. We really do want mLocale to be 1 byte
- // shorter than locale, because we're replacing "fil-" with
- // "tl-".
- mLocale = new char[newLocaleLen];
- // Copy over "tl".
- memcpy(mLocale, kTlPrefix, kTlPrefixLen);
- // Copy the rest of |locale|, including the terminating '\0'.
- memcpy(mLocale + kTlPrefixLen, locale + kFilPrefixLen,
- newLocaleLen - kFilPrefixLen + 1);
- updateResourceParamsLocked();
- return;
- }
- }
-
mLocale = strdupNew(locale);
updateResourceParamsLocked();
}
@@ -816,17 +770,7 @@ void AssetManager::getLocales(Vector<String8>* locales, bool includeSystemLocale
{
ResTable* res = mResources;
if (res != NULL) {
- res->getLocales(locales, includeSystemLocales);
- }
-
- const size_t numLocales = locales->size();
- for (size_t i = 0; i < numLocales; ++i) {
- const String8& localeStr = locales->itemAt(i);
- if (localeStr.find(kTlPrefix) == 0) {
- String8 replaced("fil");
- replaced += (localeStr.string() + kTlPrefixLen);
- locales->editItemAt(i) = replaced;
- }
+ res->getLocales(locales, includeSystemLocales, true /* mergeEquivalentLangs */);
}
}