diff options
| author | 2024-01-25 23:04:43 +0000 | |
|---|---|---|
| committer | 2024-02-02 03:35:36 +0000 | |
| commit | bfcc40b388ec7900ce97116f575ab6ee9150faa3 (patch) | |
| tree | d3c5b96f7fd32a75a0b71a426d35beb060de4c3b | |
| parent | a4865c336c73f36a9f088fc7807d09587bfea20f (diff) | |
Resources.registerResourcePaths() API and flag.
This API is designed to load the resources and of a shared library
while app is running. It will add these resources to all existing
and future contexts.
Bug: b/306202569
Test: Verified affected tests pass.
Change-Id: I5b86a65907ee0a85c6aa9018f38c25fb472e3f54
| -rw-r--r-- | core/api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/content/res/Resources.java | 20 | ||||
| -rw-r--r-- | core/java/android/content/res/flags.aconfig | 9 |
3 files changed, 30 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index e957676507b7..aa5d30888d36 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -13837,6 +13837,7 @@ package android.content.res { method public android.content.res.AssetFileDescriptor openRawResourceFd(@RawRes int) throws android.content.res.Resources.NotFoundException; method public void parseBundleExtra(String, android.util.AttributeSet, android.os.Bundle) throws org.xmlpull.v1.XmlPullParserException; method public void parseBundleExtras(android.content.res.XmlResourceParser, android.os.Bundle) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method @FlaggedApi("android.content.res.register_resource_paths") public static void registerResourcePaths(@NonNull String, @NonNull android.content.pm.ApplicationInfo); method public void removeLoaders(@NonNull android.content.res.loader.ResourcesLoader...); method @Deprecated public void updateConfiguration(android.content.res.Configuration, android.util.DisplayMetrics); field @AnyRes public static final int ID_NULL = 0; // 0x0 diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 1b37092f77b6..36719805b9c3 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -29,6 +29,7 @@ import android.annotation.ColorRes; import android.annotation.DimenRes; import android.annotation.Discouraged; import android.annotation.DrawableRes; +import android.annotation.FlaggedApi; import android.annotation.FontRes; import android.annotation.FractionRes; import android.annotation.IntegerRes; @@ -46,6 +47,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo.Config; +import android.content.pm.ApplicationInfo; import android.content.res.loader.ResourcesLoader; import android.graphics.Movie; import android.graphics.Typeface; @@ -2825,4 +2827,22 @@ public class Resources { } } } + + /** + * Register the resources paths of a package (e.g. a shared library). This will collect the + * package resources' paths from its ApplicationInfo and add them to all existing and future + * contexts while the application is running. + * A second call with the same uniqueId is a no-op. + * The paths are not persisted during application restarts. The application is responsible for + * calling the API again if this happens. + * + * @param uniqueId The unique id for the ApplicationInfo object, to detect and ignore repeated + * API calls. + * @param appInfo The ApplicationInfo that contains resources paths of the package. + */ + @FlaggedApi(android.content.res.Flags.FLAG_REGISTER_RESOURCE_PATHS) + public static void registerResourcePaths(@NonNull String uniqueId, + @NonNull ApplicationInfo appInfo) { + throw new UnsupportedOperationException("The implementation has not been done yet."); + } } diff --git a/core/java/android/content/res/flags.aconfig b/core/java/android/content/res/flags.aconfig index db81e847d6bd..f660770d2fc8 100644 --- a/core/java/android/content/res/flags.aconfig +++ b/core/java/android/content/res/flags.aconfig @@ -40,3 +40,12 @@ flag { description: "Feature flag for creating an frro from a 9-patch" bug: "309232726" } + +flag { + name: "register_resource_paths" + namespace: "resource_manager" + description: "Feature flag for register resource paths for shared library" + bug: "306202569" + # This flag is read in ResourcesImpl at boot time. + is_fixed_read_only: true +} |