diff options
| author | Ryan Mitchell <rtmitchell@google.com> | 2020-01-08 16:29:11 -0800 |
|---|---|---|
| committer | Ryan Mitchell <rtmitchell@google.com> | 2020-01-28 15:35:14 -0800 |
| commit | 4579c0aea24d74e0bb262b9019ab14a1fc96c1bb (patch) | |
| tree | 6ec9871314af18661da59e8a23bdadfa7a74a546 /core/java/android/app/ContextImpl.java | |
| parent | 12ce8338cc178e7683386c026709a74f2733abb7 (diff) | |
Refactor ResourcesLoader APIs
This changes refactors the ResourcesLoader APIs.
The main changes are:
Rather than pairing a ResourcesLoader with a ResourcesProvider, a
ResourcesProvider is paired with an AssetsProvider which is only
responsible for overriding the values of file-base resources and
assets. An AssetsProvider can be shared between multiple
ResourcesProviders.
ResourcesLoader now holds a list of ResourcesProviders.
ResourcesLoaders are part of ResourcesKeys and requests for resources
with the same loaders will use the same underlying ResourcesImpl. This
allows the loader specific code in RM to be cleaned up.
ResourcesLoaders and Resources objects use callbacks to notify RM
of changes to the Resources instance that may require a new
ResourcesImpl.
When a context is created from another context, the new context will
include the loaders of the original context. Change to list of either
context's loaders will not change the loaders of the other context,
but changes to the providers a loaders uses will update all Resources
objects that use that loader.
Activity resources will include the loaders of the application context
at the time of the Activity's creation.
Bug: 147359613
Test: atest ResourceLoaderTests
Change-Id: I2957c803d3f0c1280abfd3c723d76b18df2c3789
Diffstat (limited to 'core/java/android/app/ContextImpl.java')
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index b7555ee1c04e..136c84eaf543 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -46,6 +46,7 @@ import android.content.res.CompatResources; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; import android.content.res.Resources; +import android.content.res.loader.ResourcesLoader; import android.database.DatabaseErrorHandler; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; @@ -100,6 +101,7 @@ import java.lang.annotation.RetentionPolicy; import java.nio.ByteOrder; import java.nio.file.Path; import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; @@ -2217,7 +2219,8 @@ class ContextImpl extends Context { } private static Resources createResources(IBinder activityToken, LoadedApk pi, String splitName, - int displayId, Configuration overrideConfig, CompatibilityInfo compatInfo) { + int displayId, Configuration overrideConfig, CompatibilityInfo compatInfo, + List<ResourcesLoader> resourcesLoader) { final String[] splitResDirs; final ClassLoader classLoader; try { @@ -2234,7 +2237,8 @@ class ContextImpl extends Context { displayId, overrideConfig, compatInfo, - classLoader); + classLoader, + resourcesLoader); } @Override @@ -2249,7 +2253,7 @@ class ContextImpl extends Context { final int displayId = getDisplayId(); c.setResources(createResources(mToken, pi, null, displayId, null, - getDisplayAdjustments(displayId).getCompatibilityInfo())); + getDisplayAdjustments(displayId).getCompatibilityInfo(), null)); if (c.mResources != null) { return c; } @@ -2284,7 +2288,7 @@ class ContextImpl extends Context { final int displayId = getDisplayId(); c.setResources(createResources(mToken, pi, null, displayId, null, - getDisplayAdjustments(displayId).getCompatibilityInfo())); + getDisplayAdjustments(displayId).getCompatibilityInfo(), null)); if (c.mResources != null) { return c; } @@ -2328,7 +2332,8 @@ class ContextImpl extends Context { displayId, null, mPackageInfo.getCompatibilityInfo(), - classLoader)); + classLoader, + mResources.getLoaders())); return context; } @@ -2342,8 +2347,10 @@ class ContextImpl extends Context { mSplitName, mToken, mUser, mFlags, mClassLoader, null); final int displayId = getDisplayId(); + context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId, - overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo())); + overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo(), + mResources.getLoaders())); return context; } @@ -2357,8 +2364,10 @@ class ContextImpl extends Context { mSplitName, mToken, mUser, mFlags, mClassLoader, null); final int displayId = display.getDisplayId(); + context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId, - null, getDisplayAdjustments(displayId).getCompatibilityInfo())); + null, getDisplayAdjustments(displayId).getCompatibilityInfo(), + mResources.getLoaders())); context.mDisplay = display; return context; } @@ -2564,7 +2573,7 @@ class ContextImpl extends Context { ContextImpl context = new ContextImpl(null, systemContext.mMainThread, packageInfo, null, null, null, null, 0, null, null); context.setResources(createResources(null, packageInfo, null, displayId, null, - packageInfo.getCompatibilityInfo())); + packageInfo.getCompatibilityInfo(), null)); context.updateDisplay(displayId); context.mIsSystemOrSystemUiContext = true; return context; @@ -2637,7 +2646,8 @@ class ContextImpl extends Context { displayId, overrideConfiguration, compatInfo, - classLoader)); + classLoader, + packageInfo.getApplication().getResources().getLoaders())); context.mDisplay = resourcesManager.getAdjustedDisplay(displayId, context.getResources()); return context; |
