diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index dbc6c841b7d59..9cee815516706 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -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 diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java index 54d813dee6d71..1a31332ba5160 100644 --- a/core/java/android/app/ResourcesManager.java +++ b/core/java/android/app/ResourcesManager.java @@ -66,7 +66,7 @@ public class ResourcesManager { } }; - private String[] mSystemLocales = {}; + private String[] mSystemLocales = null; private final HashSet 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); @@ -649,4 +652,4 @@ public class ResourcesManager { return changes != 0; } -} \ No newline at end of file +}