diff options
author | Narayan Kamath <narayan@google.com> | 2014-07-22 11:18:17 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-07-17 22:39:21 +0000 |
commit | 93faaed9056491c551ef7046e9e1de7d6397e95c (patch) | |
tree | 50fc6c35ccb09ea1738d52dd5a49fe785ecd96b3 | |
parent | 9bd4aafc2a096376defa10bf75f96f8d72a5d134 (diff) | |
parent | 37b4053b8f92a1f2a8afeb8d5184dc9b7c35b47b (diff) | |
download | telephony-l-preview.tar.gz |
Merge "Don't restrict locale handling to two letter locales."android-l-preview_r2l-preview
-rw-r--r-- | src/java/com/android/internal/telephony/MccTable.java | 40 | ||||
-rw-r--r-- | src/java/com/android/internal/telephony/PhoneBase.java | 12 |
2 files changed, 22 insertions, 30 deletions
diff --git a/src/java/com/android/internal/telephony/MccTable.java b/src/java/com/android/internal/telephony/MccTable.java index a0c83499f8..d4f2e89acb 100644 --- a/src/java/com/android/internal/telephony/MccTable.java +++ b/src/java/com/android/internal/telephony/MccTable.java @@ -235,9 +235,8 @@ public final class MccTable * @param country Two character country code desired * * @return Locale or null if no appropriate value - * {@hide} */ - public static Locale getLocaleForLanguageCountry(Context context, String language, String country) { + private static Locale getLocaleForLanguageCountry(Context context, String language, String country) { String l = SystemProperties.get("persist.sys.language"); String c = SystemProperties.get("persist.sys.country"); @@ -245,53 +244,50 @@ public final class MccTable Slog.d(LOG_TAG, "getLocaleForLanguageCountry: skipping no language"); return null; // no match possible } - language = language.toLowerCase(Locale.ROOT); if (null == country) { country = ""; } - country = country.toUpperCase(Locale.ROOT); - - Locale locale; boolean alwaysPersist = false; if (Build.IS_DEBUGGABLE) { alwaysPersist = SystemProperties.getBoolean("persist.always.persist.locale", false); } if (alwaysPersist || ((null == l || 0 == l.length()) && (null == c || 0 == c.length()))) { + final Locale target = new Locale(language, country); try { // try to find a good match String[] locales = context.getAssets().getLocales(); final int N = locales.length; - String bestMatch = null; + Locale bestMatch = null; for(int i = 0; i < N; i++) { // only match full (lang + country) locales - if (locales[i]!=null && locales[i].length() >= 5 && - locales[i].substring(0,2).equals(language)) { - if (locales[i].substring(3,5).equals(country)) { - bestMatch = locales[i]; - break; - } else if (null == bestMatch) { - bestMatch = locales[i]; + if (locales[i] != null && locales[i].length() >= 5) { + final Locale locale = Locale.forLanguageTag(locales[i]); + + if (locale.getLanguage().equals(target.getLanguage())) { + if (locale.getCountry().equals(target.getCountry())) { + bestMatch = locale; + break; + } else if (bestMatch == null) { + bestMatch = locale; + } } } } if (null != bestMatch) { - locale = new Locale(bestMatch.substring(0,2), - bestMatch.substring(3,5)); - Slog.d(LOG_TAG, "getLocaleForLanguageCountry: got match"); + Slog.d(LOG_TAG, "getLocaleForLanguageCountry: got match: " + + bestMatch.toLanguageTag()); + return bestMatch; } else { - locale = null; Slog.d(LOG_TAG, "getLocaleForLanguageCountry: skip no match"); } } catch (Exception e) { - locale = null; Slog.d(LOG_TAG, "getLocaleForLanguageCountry: exception", e); } } else { - locale = null; Slog.d(LOG_TAG, "getLocaleForLanguageCountry: skipping already persisted"); } - Slog.d(LOG_TAG, "getLocaleForLanguageCountry: X locale=" + locale); - return locale; + + return null; } /** diff --git a/src/java/com/android/internal/telephony/PhoneBase.java b/src/java/com/android/internal/telephony/PhoneBase.java index 95dc59fa71..bee4e60e84 100644 --- a/src/java/com/android/internal/telephony/PhoneBase.java +++ b/src/java/com/android/internal/telephony/PhoneBase.java @@ -53,6 +53,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.concurrent.atomic.AtomicReference; @@ -704,14 +705,9 @@ public abstract class PhoneBase extends Handler implements Phone { for (int i = 0; i < carrierLocales.length; i+=3) { String c = carrierLocales[i].toString(); if (carrier.equals(c)) { - String l = carrierLocales[i+1].toString(); - - String language = l.substring(0, 2); - String country = ""; - if (l.length() >=5) { - country = l.substring(3, 5); - } - MccTable.setSystemLocale(mContext, language, country); + final Locale l = Locale.forLanguageTag(carrierLocales[i + 1].toString().replace('_', '-')); + final String country = l.getCountry(); + MccTable.setSystemLocale(mContext, l.getLanguage(), country); if (!country.isEmpty()) { try { |