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

Commit c14dd78a authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix incorrect initial locale negotiation.

It turned out that calling ResourceManager.setDefaultLocalesLocked
and ResourcesManager.applyConfigurationToResourcesLocked
can be called before the locale negotiation is ready.

To fix this issue, move ResourcesManager setup flow after creating
application context.

This also introduces RuntimeException for notifying developers the
initialize order.

Bug: 27567902
Change-Id: Iab7ea384b039fb649fb52d06d45b2bfae21f9a8a
parent aac5bf1c
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -5077,26 +5077,6 @@ public final class ActivityThread {
         */
        TimeZone.setDefault(null);

        synchronized (mResourcesManager) {
            /*
             * Initialize the default locales in this process for the reasons we set the time zone.
             *
             * We do this through ResourcesManager, since we need to do locale negotiation.
             */
            mResourcesManager.setDefaultLocalesLocked(data.config.getLocales());

            /*
             * Update the system configuration since its preloaded and might not
             * reflect configuration changes. The configuration object passed
             * in AppBindData can be safely assumed to be up to date
             */
            mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo);
            mCurDefaultDisplayDpi = data.config.densityDpi;

            // This calls mResourcesManager so keep it within the synchronized block.
            applyCompatConfiguration(mCurDefaultDisplayDpi);
        }

        data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo);

        /**
@@ -5221,6 +5201,26 @@ public final class ActivityThread {
        }

        final ContextImpl appContext = ContextImpl.createAppContext(this, data.info);
        synchronized (mResourcesManager) {
            /*
             * Initialize the default locales in this process for the reasons we set the time zone.
             *
             * We do this through ResourcesManager, since we need to do locale negotiation.
             */
            mResourcesManager.setDefaultLocalesLocked(data.config.getLocales());

            /*
             * Update the system configuration since its preloaded and might not
             * reflect configuration changes. The configuration object passed
             * in AppBindData can be safely assumed to be up to date
             */
            mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo);
            mCurDefaultDisplayDpi = data.config.densityDpi;

            // This calls mResourcesManager so keep it within the synchronized block.
            applyCompatConfiguration(mCurDefaultDisplayDpi);
        }

        if (!Process.isIsolated() && !"android".equals(appContext.getPackageName())) {
            // This cache location probably points at credential-encrypted
            // storage which may not be accessible yet; assign it anyway instead
+7 −4
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class ResourcesManager {
                }
            };

    private String[] mSystemLocales = {};
    private String[] mSystemLocales = null;
    private final HashSet<String> mNonSystemLocales = new HashSet<>();
    private boolean mHasNonSystemLocales = false;

@@ -431,7 +431,7 @@ public class ResourcesManager {
        final boolean findSystemLocales;
        final boolean hasNonSystemLocales;
        synchronized (this) {
            findSystemLocales = (mSystemLocales.length == 0);
            findSystemLocales = (mSystemLocales == null || mSystemLocales.length == 0);
            hasNonSystemLocales = mHasNonSystemLocales;

            if (DEBUG) {
@@ -483,7 +483,7 @@ public class ResourcesManager {
                LocaleList.isPseudoLocalesOnly(nonSystemLocales);

        synchronized (this) {
            if (mSystemLocales.length == 0) {
            if (mSystemLocales == null || mSystemLocales.length == 0) {
                mSystemLocales = systemLocales;
            }
            mNonSystemLocales.addAll(Arrays.asList(nonSystemLocales));
@@ -552,6 +552,9 @@ public class ResourcesManager {
    }

    /* package */ void setDefaultLocalesLocked(@NonNull LocaleList locales) {
        if (mSystemLocales == null) {
            throw new RuntimeException("ResourcesManager is not ready to negotiate locales.");
        }
        final int bestLocale;
        if (mHasNonSystemLocales) {
            bestLocale = locales.getFirstMatchIndexWithEnglishSupported(mNonSystemLocales);