Loading core/java/android/app/ApplicationPackageManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -2157,6 +2157,11 @@ public class ApplicationPackageManager extends PackageManager { app.resourceDirs, app.overlayPaths, app.sharedLibraryFiles, mContext.mPackageInfo, configuration); if (r != null) { if (android.content.res.Flags.defaultLocale() && r.getConfiguration().getLocales().size() > 1) { LocaleConfig lc = new LocaleConfig(app, r); r.setLocaleConfig(lc); } return r; } throw new NameNotFoundException("Unable to open " + app.publicSourceDir); Loading core/java/android/app/ContextImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -3672,7 +3672,7 @@ class ContextImpl extends Context { if (android.content.res.Flags.defaultLocale() && r.getConfiguration().getLocales().size() > 1) { LocaleConfig lc = LocaleConfig.fromContextIgnoringOverride(this); mResourcesManager.setLocaleConfig(lc); mResources.setLocaleConfig(lc); } } updateResourceOverlayConstraints(); Loading core/java/android/app/LocaleConfig.java +65 −49 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; Loading @@ -35,6 +36,7 @@ import android.util.Slog; import android.util.Xml; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -144,23 +146,25 @@ public class LocaleConfig implements Parcelable { } } Resources res = context.getResources(); int resId = context.getApplicationInfo().getLocaleConfigRes(); if (resId == 0) { mStatus = STATUS_NOT_SPECIFIED; return; } try (XmlResourceParser parser = res.getXml(resId)) { parseLocaleConfig(parser, res); } catch (Resources.NotFoundException e) { Slog.w(TAG, "The resource file pointed to by the given resource ID isn't found."); mStatus = STATUS_NOT_SPECIFIED; } catch (XmlPullParserException | IOException e) { Slog.w(TAG, "Failed to parse XML configuration from " + res.getResourceEntryName(resId), e); mStatus = STATUS_PARSING_FAILED; parseLocaleConfig(context.getApplicationInfo().getLocaleConfigRes(), res); } /** * Constructs a LocaleConfig from an ApplicationInfo and a Resources object. The resources * object must belong to the same app that the ApplicationInfo came from. The resources object * must also be constructed enough to be able to read xml files from the app. * * It must also be noted that this does not take into account any overrides. * * @hide */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) @RavenwoodThrow(blockedBy = LocaleManager.class) public LocaleConfig(@NonNull ApplicationInfo appInfo, @NonNull Resources res) { parseLocaleConfig(appInfo.getLocaleConfigRes(), res); } /** * Return the LocaleConfig with any sequence of locales combined into a {@link LocaleList}. * Loading Loading @@ -196,8 +200,12 @@ public class LocaleConfig implements Parcelable { /** * Parse the XML content and get the locales supported by the application */ private void parseLocaleConfig(XmlResourceParser parser, Resources res) throws IOException, XmlPullParserException { private void parseLocaleConfig(int resourceId, Resources res) { if (resourceId == 0) { mStatus = STATUS_NOT_SPECIFIED; return; } try (XmlResourceParser parser = res.getXml(resourceId)) { XmlUtils.beginDocument(parser, TAG_LOCALE_CONFIG); int outerDepth = parser.getDepth(); AttributeSet attrs = Xml.asAttributeSet(parser); Loading Loading @@ -236,6 +244,14 @@ public class LocaleConfig implements Parcelable { mStatus = STATUS_PARSING_FAILED; } } } catch (Resources.NotFoundException e) { Slog.w(TAG, "The resource file pointed to by the given resource ID isn't found."); mStatus = STATUS_NOT_SPECIFIED; } catch (XmlPullParserException | IOException e) { Slog.w(TAG, "Failed to parse XML configuration from " + res.getResourceEntryName(resourceId), e); mStatus = STATUS_PARSING_FAILED; } } /** Loading core/java/android/app/ResourcesManager.java +0 −23 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.content.res.ResourcesKey; import android.content.res.loader.ResourcesLoader; import android.hardware.display.DisplayManagerGlobal; import android.os.IBinder; import android.os.LocaleList; import android.os.Process; import android.os.Trace; import android.ravenwood.annotation.RavenwoodKeepWholeClass; Loading Loading @@ -136,11 +135,6 @@ public class ResourcesManager { private final ArrayList<WeakReference<Resources>> mAllResourceReferences = new ArrayList<>(); private final ReferenceQueue<Resources> mAllResourceReferencesQueue = new ReferenceQueue<>(); /** * The localeConfig of the app. */ private LocaleConfig mLocaleConfig = new LocaleConfig(LocaleList.getEmptyLocaleList()); private final ArrayMap<String, SharedLibraryAssets> mSharedLibAssetsMap = new ArrayMap<>(); Loading Loading @@ -1919,23 +1913,6 @@ public class ResourcesManager { } } /** * Returns the LocaleConfig current set */ public LocaleConfig getLocaleConfig() { return mLocaleConfig; } /** * Sets the LocaleConfig of the app */ public void setLocaleConfig(LocaleConfig localeConfig) { if ((localeConfig != null) && (localeConfig.getSupportedLocales() != null) && !localeConfig.getSupportedLocales().isEmpty()) { mLocaleConfig = localeConfig; } } private class UpdateHandler implements Resources.UpdateCallbacks { /** Loading core/java/android/content/res/Resources.java +15 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.annotation.XmlRes; import android.app.Application; import android.app.LocaleConfig; import android.app.ResourcesManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; Loading Loading @@ -374,6 +375,12 @@ public class Resources { if (impl == mResourcesImpl) { return; } // This can be done as part of constructing the Resources object in which case the impl may // not be set yet. However, if there is an impl it is possible the locale config has already // been set on it and we need to make sure it is carried over to the new impl. if (mResourcesImpl != null) { impl.setLocaleConfig(mResourcesImpl.getLocaleConfig()); } mBaseApkAssetsSize = ArrayUtils.size(impl.getAssets().getApkAssets()); mResourcesImpl = impl; Loading @@ -391,6 +398,14 @@ public class Resources { } } /** * Sets the locale config that should be used for resource resolution. * @hide */ public void setLocaleConfig(@NonNull LocaleConfig localeConfig) { mResourcesImpl.setLocaleConfig(localeConfig); } /** @hide */ public void setCallbacks(UpdateCallbacks callbacks) { if (mCallbacks != null) { Loading Loading
core/java/android/app/ApplicationPackageManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -2157,6 +2157,11 @@ public class ApplicationPackageManager extends PackageManager { app.resourceDirs, app.overlayPaths, app.sharedLibraryFiles, mContext.mPackageInfo, configuration); if (r != null) { if (android.content.res.Flags.defaultLocale() && r.getConfiguration().getLocales().size() > 1) { LocaleConfig lc = new LocaleConfig(app, r); r.setLocaleConfig(lc); } return r; } throw new NameNotFoundException("Unable to open " + app.publicSourceDir); Loading
core/java/android/app/ContextImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -3672,7 +3672,7 @@ class ContextImpl extends Context { if (android.content.res.Flags.defaultLocale() && r.getConfiguration().getLocales().size() > 1) { LocaleConfig lc = LocaleConfig.fromContextIgnoringOverride(this); mResourcesManager.setLocaleConfig(lc); mResources.setLocaleConfig(lc); } } updateResourceOverlayConstraints(); Loading
core/java/android/app/LocaleConfig.java +65 −49 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; Loading @@ -35,6 +36,7 @@ import android.util.Slog; import android.util.Xml; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -144,23 +146,25 @@ public class LocaleConfig implements Parcelable { } } Resources res = context.getResources(); int resId = context.getApplicationInfo().getLocaleConfigRes(); if (resId == 0) { mStatus = STATUS_NOT_SPECIFIED; return; } try (XmlResourceParser parser = res.getXml(resId)) { parseLocaleConfig(parser, res); } catch (Resources.NotFoundException e) { Slog.w(TAG, "The resource file pointed to by the given resource ID isn't found."); mStatus = STATUS_NOT_SPECIFIED; } catch (XmlPullParserException | IOException e) { Slog.w(TAG, "Failed to parse XML configuration from " + res.getResourceEntryName(resId), e); mStatus = STATUS_PARSING_FAILED; parseLocaleConfig(context.getApplicationInfo().getLocaleConfigRes(), res); } /** * Constructs a LocaleConfig from an ApplicationInfo and a Resources object. The resources * object must belong to the same app that the ApplicationInfo came from. The resources object * must also be constructed enough to be able to read xml files from the app. * * It must also be noted that this does not take into account any overrides. * * @hide */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) @RavenwoodThrow(blockedBy = LocaleManager.class) public LocaleConfig(@NonNull ApplicationInfo appInfo, @NonNull Resources res) { parseLocaleConfig(appInfo.getLocaleConfigRes(), res); } /** * Return the LocaleConfig with any sequence of locales combined into a {@link LocaleList}. * Loading Loading @@ -196,8 +200,12 @@ public class LocaleConfig implements Parcelable { /** * Parse the XML content and get the locales supported by the application */ private void parseLocaleConfig(XmlResourceParser parser, Resources res) throws IOException, XmlPullParserException { private void parseLocaleConfig(int resourceId, Resources res) { if (resourceId == 0) { mStatus = STATUS_NOT_SPECIFIED; return; } try (XmlResourceParser parser = res.getXml(resourceId)) { XmlUtils.beginDocument(parser, TAG_LOCALE_CONFIG); int outerDepth = parser.getDepth(); AttributeSet attrs = Xml.asAttributeSet(parser); Loading Loading @@ -236,6 +244,14 @@ public class LocaleConfig implements Parcelable { mStatus = STATUS_PARSING_FAILED; } } } catch (Resources.NotFoundException e) { Slog.w(TAG, "The resource file pointed to by the given resource ID isn't found."); mStatus = STATUS_NOT_SPECIFIED; } catch (XmlPullParserException | IOException e) { Slog.w(TAG, "Failed to parse XML configuration from " + res.getResourceEntryName(resourceId), e); mStatus = STATUS_PARSING_FAILED; } } /** Loading
core/java/android/app/ResourcesManager.java +0 −23 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.content.res.ResourcesKey; import android.content.res.loader.ResourcesLoader; import android.hardware.display.DisplayManagerGlobal; import android.os.IBinder; import android.os.LocaleList; import android.os.Process; import android.os.Trace; import android.ravenwood.annotation.RavenwoodKeepWholeClass; Loading Loading @@ -136,11 +135,6 @@ public class ResourcesManager { private final ArrayList<WeakReference<Resources>> mAllResourceReferences = new ArrayList<>(); private final ReferenceQueue<Resources> mAllResourceReferencesQueue = new ReferenceQueue<>(); /** * The localeConfig of the app. */ private LocaleConfig mLocaleConfig = new LocaleConfig(LocaleList.getEmptyLocaleList()); private final ArrayMap<String, SharedLibraryAssets> mSharedLibAssetsMap = new ArrayMap<>(); Loading Loading @@ -1919,23 +1913,6 @@ public class ResourcesManager { } } /** * Returns the LocaleConfig current set */ public LocaleConfig getLocaleConfig() { return mLocaleConfig; } /** * Sets the LocaleConfig of the app */ public void setLocaleConfig(LocaleConfig localeConfig) { if ((localeConfig != null) && (localeConfig.getSupportedLocales() != null) && !localeConfig.getSupportedLocales().isEmpty()) { mLocaleConfig = localeConfig; } } private class UpdateHandler implements Resources.UpdateCallbacks { /** Loading
core/java/android/content/res/Resources.java +15 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.annotation.XmlRes; import android.app.Application; import android.app.LocaleConfig; import android.app.ResourcesManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; Loading Loading @@ -374,6 +375,12 @@ public class Resources { if (impl == mResourcesImpl) { return; } // This can be done as part of constructing the Resources object in which case the impl may // not be set yet. However, if there is an impl it is possible the locale config has already // been set on it and we need to make sure it is carried over to the new impl. if (mResourcesImpl != null) { impl.setLocaleConfig(mResourcesImpl.getLocaleConfig()); } mBaseApkAssetsSize = ArrayUtils.size(impl.getAssets().getApkAssets()); mResourcesImpl = impl; Loading @@ -391,6 +398,14 @@ public class Resources { } } /** * Sets the locale config that should be used for resource resolution. * @hide */ public void setLocaleConfig(@NonNull LocaleConfig localeConfig) { mResourcesImpl.setLocaleConfig(localeConfig); } /** @hide */ public void setCallbacks(UpdateCallbacks callbacks) { if (mCallbacks != null) { Loading