Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f0945e9 authored by Raph Levien's avatar Raph Levien
Browse files

Update mResolvedLocale more aggressively

A client that mutates the locale of the Configuration being updated
can cause failure of the test that mResolvedLocale needs to be
recomputed. This patch stashes the previous locale list privately
so that updates can be detected even in this case.

Bug: 25993843
Change-Id: I1ea17dffd722177fb5b65ee77b9f5ce9a943f15b
parent 770e437d
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -161,7 +161,11 @@ public class Resources {
    final DisplayMetrics mMetrics = new DisplayMetrics();

    private final Configuration mConfiguration = new Configuration();

    // Invariant: mResolvedLocale is the resolved locale of mLocalesForResolved
    private LocaleList mLocalesForResolved = null;
    private Locale mResolvedLocale = null;

    private PluralRules mPluralRule;

    private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
@@ -1950,8 +1954,7 @@ public class Resources {
            final int configChanges = calcConfigChanges(config);

            LocaleList locales = mConfiguration.getLocales();
            final boolean setLocalesToDefault = locales.isEmpty();
            if (setLocalesToDefault) {
            if (locales.isEmpty()) {
                locales = LocaleList.getDefault();
                mConfiguration.setLocales(locales);
            }
@@ -1980,8 +1983,7 @@ public class Resources {
                keyboardHidden = mConfiguration.keyboardHidden;
            }

            if (setLocalesToDefault || mResolvedLocale == null
                    || (configChanges & Configuration.NATIVE_CONFIG_LOCALE) != 0) {
            if (locales != mLocalesForResolved) {
                if (locales.size() == 1) {
                    // This is an optimization to avoid the JNI call(s) when the result of
                    // getFirstMatchWithEnglishSupported() does not depend on the supported locales.
@@ -1997,6 +1999,7 @@ public class Resources {
                    }
                    mResolvedLocale = locales.getFirstMatchWithEnglishSupported(supportedLocales);
                }
                mLocalesForResolved = locales;
            }
            mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
                    adjustLanguageTag(mResolvedLocale.toLanguageTag()),