Loading core/java/android/content/res/Resources.java +2 −2 Original line number Diff line number Diff line Loading @@ -1978,7 +1978,7 @@ public class Resources { || (configChanges & Configuration.NATIVE_CONFIG_LOCALE) != 0) { if (locales.size() == 1) { // This is an optimization to avoid the JNI call(s) when the result of // getFirstMatch() does not depend on the supported locales. // getFirstMatchWithEnglishSupported() does not depend on the supported locales. mResolvedLocale = locales.getPrimary(); } else { String[] supportedLocales = mAssets.getNonSystemLocales(); Loading @@ -1989,7 +1989,7 @@ public class Resources { // their own. supportedLocales = mAssets.getLocales(); } mResolvedLocale = locales.getFirstMatch(supportedLocales); mResolvedLocale = locales.getFirstMatchWithEnglishSupported(supportedLocales); } } mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc, Loading core/java/android/util/LocaleList.java +33 −10 Original line number Diff line number Diff line Loading @@ -246,14 +246,9 @@ public final class LocaleList implements Parcelable { return supportedScr.equals(desiredScr) ? 1 : 0; } /** * Returns the first match in the locale list given an unordered array of supported locales * in BCP47 format. * * If the locale list is empty, null would be returned. */ @Nullable public Locale getFirstMatch(String[] supportedLocales) { private static final Locale EN_LATN = Locale.forLanguageTag("en-Latn"); private Locale computeFirstMatch(String[] supportedLocales, boolean assumeEnglishIsSupported) { if (mList.length == 1) { // just one locale, perhaps the most common scenario return mList[0]; } Loading @@ -261,8 +256,16 @@ public final class LocaleList implements Parcelable { return null; } int bestIndex = Integer.MAX_VALUE; for (String tag : supportedLocales) { final Locale supportedLocale = Locale.forLanguageTag(tag); final int numSupportedLocales = supportedLocales.length + (assumeEnglishIsSupported ? 1 : 0); for (int i = 0; i < numSupportedLocales; i++) { final Locale supportedLocale; if (assumeEnglishIsSupported) { // Try English first, so we can return early if it's in the LocaleList supportedLocale = (i == 0) ? EN_LATN : Locale.forLanguageTag(supportedLocales[i-1]); } else { supportedLocale = Locale.forLanguageTag(supportedLocales[i]); } // We expect the average length of locale lists used for locale resolution to be // smaller than three, so it's OK to do this as an O(mn) algorithm. for (int idx = 0; idx < mList.length; idx++) { Loading @@ -283,6 +286,26 @@ public final class LocaleList implements Parcelable { } } /** * Returns the first match in the locale list given an unordered array of supported locales * in BCP47 format. * * If the locale list is empty, null would be returned. */ @Nullable public Locale getFirstMatch(String[] supportedLocales) { return computeFirstMatch(supportedLocales, false /* assume English is not supported */); } /** * Same as getFirstMatch(), but with English assumed to be supported, even if it's not. * {@hide} */ @Nullable public Locale getFirstMatchWithEnglishSupported(String[] supportedLocales) { return computeFirstMatch(supportedLocales, true /* assume English is supported */); } /** * Returns true if the array of locale tags only contains empty locales and pseudolocales. * Assumes that there is no repetition in the input. Loading core/tests/coretests/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ LOCAL_SRC_FILES := \ $(call all-java-files-under, EnabledTestApp/src) LOCAL_DX_FLAGS := --core-library LOCAL_AAPT_FLAGS = -0 dat -0 gld LOCAL_AAPT_FLAGS = -0 dat -0 gld -c fa LOCAL_STATIC_JAVA_LIBRARIES := \ core-tests-support \ android-common \ Loading core/tests/coretests/res/values-fa/strings.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="dummy_string">رشتهٔ الکی</string> </resources> core/tests/coretests/res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -139,4 +139,7 @@ <!-- RestrictionsManagerTest --> <string name="restrictionManager_title">Title</string> <string name="restrictionManager_desc">Description</string> <!-- ResourcesLocaleResolutionTest --> <string name="dummy_string">dummy string</string> </resources> Loading
core/java/android/content/res/Resources.java +2 −2 Original line number Diff line number Diff line Loading @@ -1978,7 +1978,7 @@ public class Resources { || (configChanges & Configuration.NATIVE_CONFIG_LOCALE) != 0) { if (locales.size() == 1) { // This is an optimization to avoid the JNI call(s) when the result of // getFirstMatch() does not depend on the supported locales. // getFirstMatchWithEnglishSupported() does not depend on the supported locales. mResolvedLocale = locales.getPrimary(); } else { String[] supportedLocales = mAssets.getNonSystemLocales(); Loading @@ -1989,7 +1989,7 @@ public class Resources { // their own. supportedLocales = mAssets.getLocales(); } mResolvedLocale = locales.getFirstMatch(supportedLocales); mResolvedLocale = locales.getFirstMatchWithEnglishSupported(supportedLocales); } } mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc, Loading
core/java/android/util/LocaleList.java +33 −10 Original line number Diff line number Diff line Loading @@ -246,14 +246,9 @@ public final class LocaleList implements Parcelable { return supportedScr.equals(desiredScr) ? 1 : 0; } /** * Returns the first match in the locale list given an unordered array of supported locales * in BCP47 format. * * If the locale list is empty, null would be returned. */ @Nullable public Locale getFirstMatch(String[] supportedLocales) { private static final Locale EN_LATN = Locale.forLanguageTag("en-Latn"); private Locale computeFirstMatch(String[] supportedLocales, boolean assumeEnglishIsSupported) { if (mList.length == 1) { // just one locale, perhaps the most common scenario return mList[0]; } Loading @@ -261,8 +256,16 @@ public final class LocaleList implements Parcelable { return null; } int bestIndex = Integer.MAX_VALUE; for (String tag : supportedLocales) { final Locale supportedLocale = Locale.forLanguageTag(tag); final int numSupportedLocales = supportedLocales.length + (assumeEnglishIsSupported ? 1 : 0); for (int i = 0; i < numSupportedLocales; i++) { final Locale supportedLocale; if (assumeEnglishIsSupported) { // Try English first, so we can return early if it's in the LocaleList supportedLocale = (i == 0) ? EN_LATN : Locale.forLanguageTag(supportedLocales[i-1]); } else { supportedLocale = Locale.forLanguageTag(supportedLocales[i]); } // We expect the average length of locale lists used for locale resolution to be // smaller than three, so it's OK to do this as an O(mn) algorithm. for (int idx = 0; idx < mList.length; idx++) { Loading @@ -283,6 +286,26 @@ public final class LocaleList implements Parcelable { } } /** * Returns the first match in the locale list given an unordered array of supported locales * in BCP47 format. * * If the locale list is empty, null would be returned. */ @Nullable public Locale getFirstMatch(String[] supportedLocales) { return computeFirstMatch(supportedLocales, false /* assume English is not supported */); } /** * Same as getFirstMatch(), but with English assumed to be supported, even if it's not. * {@hide} */ @Nullable public Locale getFirstMatchWithEnglishSupported(String[] supportedLocales) { return computeFirstMatch(supportedLocales, true /* assume English is supported */); } /** * Returns true if the array of locale tags only contains empty locales and pseudolocales. * Assumes that there is no repetition in the input. Loading
core/tests/coretests/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ LOCAL_SRC_FILES := \ $(call all-java-files-under, EnabledTestApp/src) LOCAL_DX_FLAGS := --core-library LOCAL_AAPT_FLAGS = -0 dat -0 gld LOCAL_AAPT_FLAGS = -0 dat -0 gld -c fa LOCAL_STATIC_JAVA_LIBRARIES := \ core-tests-support \ android-common \ Loading
core/tests/coretests/res/values-fa/strings.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="dummy_string">رشتهٔ الکی</string> </resources>
core/tests/coretests/res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -139,4 +139,7 @@ <!-- RestrictionsManagerTest --> <string name="restrictionManager_title">Title</string> <string name="restrictionManager_desc">Description</string> <!-- ResourcesLocaleResolutionTest --> <string name="dummy_string">dummy string</string> </resources>