Loading core/java/android/content/om/OverlayManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -78,7 +78,8 @@ public class OverlayManager { /** * Applications can use OverlayManager to create overlays to overlay on itself resources. The * overlay target is itself and the work range is only in caller application. * overlay target is itself, or the Android package, and the work range is only in caller * application. * * <p>In {@link android.content.Context#getSystemService(String)}, it crashes because of {@link * java.lang.NullPointerException} if the parameter is OverlayManager. if the self-targeting is Loading Loading @@ -401,7 +402,7 @@ public class OverlayManager { } /** * Get the related information of overlays for {@code targetPackageName}. * Get the related information of self-targeting overlays for {@code targetPackageName}. * * @param targetPackageName the target package name * @return a list of overlay information Loading core/java/android/content/om/OverlayManagerTransaction.java +14 −1 Original line number Diff line number Diff line Loading @@ -209,6 +209,7 @@ public final class OverlayManagerTransaction implements Parcelable { */ public static final class Builder { private final List<Request> mRequests = new ArrayList<>(); private boolean mSelfTargeting = false; /** * Request that an overlay package be enabled and change its loading Loading Loading @@ -245,6 +246,18 @@ public final class OverlayManagerTransaction implements Parcelable { return this; } /** * Request that an overlay package be self-targeting. Self-targeting overlays enable * applications to overlay on itself resources. The overlay target is itself, or the Android * package, and the work range is only in caller application. * @param selfTargeting whether the overlay is self-targeting, the default is false. * @hide */ public Builder setSelfTargeting(boolean selfTargeting) { mSelfTargeting = selfTargeting; return this; } /** * Registers the fabricated overlay with the overlay manager so it can be enabled and * disabled for any user. Loading Loading @@ -286,7 +299,7 @@ public final class OverlayManagerTransaction implements Parcelable { */ @NonNull public OverlayManagerTransaction build() { return new OverlayManagerTransaction(mRequests, false /* selfTargeting */); return new OverlayManagerTransaction(mRequests, mSelfTargeting); } } Loading core/java/android/content/res/AssetManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,10 @@ public final class AssetManager implements AutoCloseable { private static final String TAG = "AssetManager"; private static final boolean DEBUG_REFS = false; private static final String FRAMEWORK_APK_PATH = getFrameworkApkPath(); /** * @hide */ public static final String FRAMEWORK_APK_PATH = getFrameworkApkPath(); private static final String FRAMEWORK_APK_PATH_DEVICE = "/system/framework/framework-res.apk"; private static final String FRAMEWORK_APK_PATH_RAVENWOOD = "ravenwood-data/framework-res.apk"; Loading core/java/android/content/res/loader/ResourcesProvider.java +0 −2 Original line number Diff line number Diff line Loading @@ -90,8 +90,6 @@ public class ResourcesProvider implements AutoCloseable, Closeable { throws IOException { Objects.requireNonNull(overlayInfo); Preconditions.checkArgument(overlayInfo.isFabricated(), "Not accepted overlay"); Preconditions.checkStringNotEmpty( overlayInfo.getTargetOverlayableName(), "Without overlayable name"); final String overlayName = OverlayManagerImpl.checkOverlayNameValid(overlayInfo.getOverlayName()); final String path = Loading core/java/android/widget/RemoteViews.java +64 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.appwidget.flags.Flags.FLAG_DRAW_DATA_PARCEL; import static android.appwidget.flags.Flags.FLAG_REMOTE_VIEWS_PROTO; import static android.appwidget.flags.Flags.drawDataParcel; import static android.appwidget.flags.Flags.remoteAdapterConversion; import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8; import static android.util.proto.ProtoInputStream.NO_MORE_FIELDS; import static android.view.inputmethod.Flags.FLAG_HOME_SCREEN_HANDWRITING_DELEGATOR; Loading Loading @@ -54,6 +55,10 @@ import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentSender; import android.content.ServiceConnection; import android.content.om.FabricatedOverlay; import android.content.om.OverlayInfo; import android.content.om.OverlayManager; import android.content.om.OverlayManagerTransaction; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.ColorStateList; Loading Loading @@ -8547,8 +8552,6 @@ public class RemoteViews implements Parcelable, Filter { /** * Object allowing the modification of a context to overload the system's dynamic colors. * * Only colors from {@link android.R.color#system_accent1_0} to * {@link android.R.color#system_neutral2_1000} can be overloaded. * @hide */ public static final class ColorResources { Loading @@ -8559,6 +8562,9 @@ public class RemoteViews implements Parcelable, Filter { // Size, in bytes, of an entry in the array of colors in an ARSC file. private static final int ARSC_ENTRY_SIZE = 16; private static final String OVERLAY_NAME = "remote_views_color_resources"; private static final String OVERLAY_TARGET_PACKAGE_NAME = "android"; private final ResourcesLoader mLoader; private final SparseIntArray mColorMapping; Loading Loading @@ -8629,7 +8635,11 @@ public class RemoteViews implements Parcelable, Filter { } /** * Adds a resource loader for theme colors to the given context. * Adds a resource loader for theme colors to the given context. The loader is created * based on resource files created at build time. * * <p>Only colors from {@link android.R.color#system_accent1_0} to * {@link android.R.color#system_error_1000} can be overloaded.</p> * * @param context Context of the view hosting the widget. * @param colorMapping Mapping of resources to color values. Loading Loading @@ -8667,6 +8677,57 @@ public class RemoteViews implements Parcelable, Filter { } return null; } /** * Adds a resource loader for theme colors to the given context. The loader is created * using fabricated runtime resource overlay (FRRO). * * <p>The created class can overlay any color resources, private or public, at runtime.</p> * * @param context Context of the view hosting the widget. * @param colorMapping Mapping of resources to color values. * * @hide */ @Nullable public static ColorResources createWithOverlay(Context context, SparseIntArray colorMapping) { try { String owningPackage = context.getPackageName(); FabricatedOverlay overlay = new FabricatedOverlay.Builder(owningPackage, OVERLAY_NAME, OVERLAY_TARGET_PACKAGE_NAME).build(); for (int i = 0; i < colorMapping.size(); i++) { overlay.setResourceValue( context.getResources().getResourceName(colorMapping.keyAt(i)), TYPE_INT_COLOR_ARGB8, colorMapping.valueAt(i), null); } OverlayManager overlayManager = context.getSystemService(OverlayManager.class); OverlayManagerTransaction.Builder transaction = new OverlayManagerTransaction.Builder() .registerFabricatedOverlay(overlay) .setSelfTargeting(true); overlayManager.commit(transaction.build()); OverlayInfo overlayInfo = overlayManager.getOverlayInfosForTarget(OVERLAY_TARGET_PACKAGE_NAME) .stream() .filter(info -> TextUtils.equals(info.overlayName, OVERLAY_NAME) && TextUtils.equals(info.packageName, owningPackage)) .findFirst() .orElse(null); if (overlayInfo == null) { Log.e(LOG_TAG, "Failed to get overlay info ", new Throwable()); return null; } ResourcesLoader colorsLoader = new ResourcesLoader(); colorsLoader.addProvider(ResourcesProvider.loadOverlay(overlayInfo)); return new ColorResources(colorsLoader, colorMapping.clone()); } catch (Exception e) { Log.e(LOG_TAG, "Failed to add theme color overlay into loader", e); } return null; } } /** Loading Loading
core/java/android/content/om/OverlayManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -78,7 +78,8 @@ public class OverlayManager { /** * Applications can use OverlayManager to create overlays to overlay on itself resources. The * overlay target is itself and the work range is only in caller application. * overlay target is itself, or the Android package, and the work range is only in caller * application. * * <p>In {@link android.content.Context#getSystemService(String)}, it crashes because of {@link * java.lang.NullPointerException} if the parameter is OverlayManager. if the self-targeting is Loading Loading @@ -401,7 +402,7 @@ public class OverlayManager { } /** * Get the related information of overlays for {@code targetPackageName}. * Get the related information of self-targeting overlays for {@code targetPackageName}. * * @param targetPackageName the target package name * @return a list of overlay information Loading
core/java/android/content/om/OverlayManagerTransaction.java +14 −1 Original line number Diff line number Diff line Loading @@ -209,6 +209,7 @@ public final class OverlayManagerTransaction implements Parcelable { */ public static final class Builder { private final List<Request> mRequests = new ArrayList<>(); private boolean mSelfTargeting = false; /** * Request that an overlay package be enabled and change its loading Loading Loading @@ -245,6 +246,18 @@ public final class OverlayManagerTransaction implements Parcelable { return this; } /** * Request that an overlay package be self-targeting. Self-targeting overlays enable * applications to overlay on itself resources. The overlay target is itself, or the Android * package, and the work range is only in caller application. * @param selfTargeting whether the overlay is self-targeting, the default is false. * @hide */ public Builder setSelfTargeting(boolean selfTargeting) { mSelfTargeting = selfTargeting; return this; } /** * Registers the fabricated overlay with the overlay manager so it can be enabled and * disabled for any user. Loading Loading @@ -286,7 +299,7 @@ public final class OverlayManagerTransaction implements Parcelable { */ @NonNull public OverlayManagerTransaction build() { return new OverlayManagerTransaction(mRequests, false /* selfTargeting */); return new OverlayManagerTransaction(mRequests, mSelfTargeting); } } Loading
core/java/android/content/res/AssetManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,10 @@ public final class AssetManager implements AutoCloseable { private static final String TAG = "AssetManager"; private static final boolean DEBUG_REFS = false; private static final String FRAMEWORK_APK_PATH = getFrameworkApkPath(); /** * @hide */ public static final String FRAMEWORK_APK_PATH = getFrameworkApkPath(); private static final String FRAMEWORK_APK_PATH_DEVICE = "/system/framework/framework-res.apk"; private static final String FRAMEWORK_APK_PATH_RAVENWOOD = "ravenwood-data/framework-res.apk"; Loading
core/java/android/content/res/loader/ResourcesProvider.java +0 −2 Original line number Diff line number Diff line Loading @@ -90,8 +90,6 @@ public class ResourcesProvider implements AutoCloseable, Closeable { throws IOException { Objects.requireNonNull(overlayInfo); Preconditions.checkArgument(overlayInfo.isFabricated(), "Not accepted overlay"); Preconditions.checkStringNotEmpty( overlayInfo.getTargetOverlayableName(), "Without overlayable name"); final String overlayName = OverlayManagerImpl.checkOverlayNameValid(overlayInfo.getOverlayName()); final String path = Loading
core/java/android/widget/RemoteViews.java +64 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.appwidget.flags.Flags.FLAG_DRAW_DATA_PARCEL; import static android.appwidget.flags.Flags.FLAG_REMOTE_VIEWS_PROTO; import static android.appwidget.flags.Flags.drawDataParcel; import static android.appwidget.flags.Flags.remoteAdapterConversion; import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8; import static android.util.proto.ProtoInputStream.NO_MORE_FIELDS; import static android.view.inputmethod.Flags.FLAG_HOME_SCREEN_HANDWRITING_DELEGATOR; Loading Loading @@ -54,6 +55,10 @@ import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentSender; import android.content.ServiceConnection; import android.content.om.FabricatedOverlay; import android.content.om.OverlayInfo; import android.content.om.OverlayManager; import android.content.om.OverlayManagerTransaction; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.ColorStateList; Loading Loading @@ -8547,8 +8552,6 @@ public class RemoteViews implements Parcelable, Filter { /** * Object allowing the modification of a context to overload the system's dynamic colors. * * Only colors from {@link android.R.color#system_accent1_0} to * {@link android.R.color#system_neutral2_1000} can be overloaded. * @hide */ public static final class ColorResources { Loading @@ -8559,6 +8562,9 @@ public class RemoteViews implements Parcelable, Filter { // Size, in bytes, of an entry in the array of colors in an ARSC file. private static final int ARSC_ENTRY_SIZE = 16; private static final String OVERLAY_NAME = "remote_views_color_resources"; private static final String OVERLAY_TARGET_PACKAGE_NAME = "android"; private final ResourcesLoader mLoader; private final SparseIntArray mColorMapping; Loading Loading @@ -8629,7 +8635,11 @@ public class RemoteViews implements Parcelable, Filter { } /** * Adds a resource loader for theme colors to the given context. * Adds a resource loader for theme colors to the given context. The loader is created * based on resource files created at build time. * * <p>Only colors from {@link android.R.color#system_accent1_0} to * {@link android.R.color#system_error_1000} can be overloaded.</p> * * @param context Context of the view hosting the widget. * @param colorMapping Mapping of resources to color values. Loading Loading @@ -8667,6 +8677,57 @@ public class RemoteViews implements Parcelable, Filter { } return null; } /** * Adds a resource loader for theme colors to the given context. The loader is created * using fabricated runtime resource overlay (FRRO). * * <p>The created class can overlay any color resources, private or public, at runtime.</p> * * @param context Context of the view hosting the widget. * @param colorMapping Mapping of resources to color values. * * @hide */ @Nullable public static ColorResources createWithOverlay(Context context, SparseIntArray colorMapping) { try { String owningPackage = context.getPackageName(); FabricatedOverlay overlay = new FabricatedOverlay.Builder(owningPackage, OVERLAY_NAME, OVERLAY_TARGET_PACKAGE_NAME).build(); for (int i = 0; i < colorMapping.size(); i++) { overlay.setResourceValue( context.getResources().getResourceName(colorMapping.keyAt(i)), TYPE_INT_COLOR_ARGB8, colorMapping.valueAt(i), null); } OverlayManager overlayManager = context.getSystemService(OverlayManager.class); OverlayManagerTransaction.Builder transaction = new OverlayManagerTransaction.Builder() .registerFabricatedOverlay(overlay) .setSelfTargeting(true); overlayManager.commit(transaction.build()); OverlayInfo overlayInfo = overlayManager.getOverlayInfosForTarget(OVERLAY_TARGET_PACKAGE_NAME) .stream() .filter(info -> TextUtils.equals(info.overlayName, OVERLAY_NAME) && TextUtils.equals(info.packageName, owningPackage)) .findFirst() .orElse(null); if (overlayInfo == null) { Log.e(LOG_TAG, "Failed to get overlay info ", new Throwable()); return null; } ResourcesLoader colorsLoader = new ResourcesLoader(); colorsLoader.addProvider(ResourcesProvider.loadOverlay(overlayInfo)); return new ColorResources(colorsLoader, colorMapping.clone()); } catch (Exception e) { Log.e(LOG_TAG, "Failed to add theme color overlay into loader", e); } return null; } } /** Loading