From 8bca69858aefd2326b1bb7ead75796778ed54e93 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 18 Nov 2015 17:41:24 -0800 Subject: [PATCH] Support LocaleLists in ActivityManagerService. Also add a placeholder method for locale negotiation to LocaleList, to be filled later. There is no change in behavior expected by this CL yet. But once we support setting the first locale to something the system doesn't support, and implement the locale negotiation, this will cause the system locale to be set to the first supported locale, instead of just the default from Settings. Change-Id: Iec983a5707daffb5bf54eac79ff0856a96631960 --- api/current.txt | 1 + api/system-current.txt | 1 + core/java/android/util/LocaleList.java | 7 +++++++ .../com/android/server/am/ActivityManagerService.java | 17 ++++++++++++----- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/api/current.txt b/api/current.txt index 1a7139c08cd8..807a38ed71f5 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34407,6 +34407,7 @@ package android.util { ctor public LocaleList(java.util.Locale[]); method public static android.util.LocaleList forLanguageTags(java.lang.String); method public java.util.Locale get(int); + method public java.util.Locale getBestMatch(java.lang.String[]); method public static android.util.LocaleList getDefault(); method public static android.util.LocaleList getEmptyLocaleList(); method public java.util.Locale getPrimary(); diff --git a/api/system-current.txt b/api/system-current.txt index f27844101473..004e340b068e 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -36728,6 +36728,7 @@ package android.util { ctor public LocaleList(java.util.Locale[]); method public static android.util.LocaleList forLanguageTags(java.lang.String); method public java.util.Locale get(int); + method public java.util.Locale getBestMatch(java.lang.String[]); method public static android.util.LocaleList getDefault(); method public static android.util.LocaleList getEmptyLocaleList(); method public java.util.Locale getPrimary(); diff --git a/core/java/android/util/LocaleList.java b/core/java/android/util/LocaleList.java index 0d5c135044dd..c1d23bb9d7e7 100644 --- a/core/java/android/util/LocaleList.java +++ b/core/java/android/util/LocaleList.java @@ -49,6 +49,7 @@ public final class LocaleList { return location < mList.length ? mList[location] : null; } + @Nullable public Locale getPrimary() { return mList.length == 0 ? null : get(0); } @@ -179,6 +180,12 @@ public final class LocaleList { } } + @Nullable + public Locale getBestMatch(String[] locales) { + // TODO: Fix this to actually do locale negotiation and choose the best match + return getPrimary(); + } + private final static Object sLock = new Object(); @GuardedBy("sLock") diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 6e6bfb791ae7..935578e36bd1 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -226,6 +226,7 @@ import android.text.format.DateUtils; import android.text.format.Time; import android.util.AtomicFile; import android.util.EventLog; +import android.util.LocaleList; import android.util.Log; import android.util.Pair; import android.util.PrintWriterPrinter; @@ -2385,7 +2386,7 @@ public final class ActivityManagerService extends ActivityManagerNative mTrackingAssociations = "1".equals(SystemProperties.get("debug.track-associations")); mConfiguration.setToDefaults(); - mConfiguration.setLocale(Locale.getDefault()); + mConfiguration.setLocales(LocaleList.getDefault()); mConfigurationSeq = mConfiguration.seq = 1; mProcessCpuTracker.init(); @@ -17641,6 +17642,9 @@ public final class ActivityManagerService extends ActivityManagerNative UserHandle.USER_NULL); } + // To cache the list of supported system locales + private String[] mSupportedSystemLocales = null; + /** * Do either or both things: (1) change the current configuration, and (2) * make sure the given activity is running with the (now) current @@ -17664,11 +17668,14 @@ public final class ActivityManagerService extends ActivityManagerNative EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes); - if (!initLocale && values.locale != null && values.userSetLocale) { - final String languageTag = values.locale.toLanguageTag(); - SystemProperties.set("persist.sys.locale", languageTag); + if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { + if (mSupportedSystemLocales == null) { + mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); + } + final Locale locale = values.getLocales().getBestMatch(mSupportedSystemLocales); + SystemProperties.set("persist.sys.locale", locale.toLanguageTag()); mHandler.sendMessage(mHandler.obtainMessage(SEND_LOCALE_TO_MOUNT_DAEMON_MSG, - values.locale)); + locale)); } mConfigurationSeq++; -- 2.11.0