FabricatedOverlay


public class FabricatedOverlay
extends Object

java.lang.Object
   ↳ android.content.om.FabricatedOverlay


FabricatedOverlay describes the content of Fabricated Runtime Resource Overlay (FRRO) that is used to overlay the app's resources. The app should register the FabricatedOverlay instance in an OverlayManagerTransaction by calling OverlayManagerTransaction.registerFabricatedOverlay(android.content.om.FabricatedOverlay). The FRRO is created once the transaction is committed successfully.

The app creates a FabricatedOverlay to describe the how to overlay string, integer, and file type resources. Before creating any frro, please define a target overlayable in res/values/overlayable.xml that describes what kind of resources can be overlaid, what kind of roles or applications can overlay the resources. Here is an example.

<overlayable name="SignatureOverlayable" actor="overlay://theme">
     <!-- The app with the same signature can overlay the below resources -->
     <policy type="signature">
         <item type="color" name="mycolor" />
         <item type="string" name="mystring" />
     </policy>
 </overlayable>
 

The overlay must assign the target overlayable name just like the above example by calling setTargetOverlayable(java.lang.String). Here is an example:

FabricatedOverlay fabricatedOverlay = new FabricatedOverlay("overlay_name",
                                                             context.getPackageName());
 fabricatedOverlay.setTargetOverlayable("SignatureOverlayable")
 fabricatedOverlay.setResourceValue("mycolor", TypedValue.TYPE_INT_COLOR_ARGB8, Color.White)
 fabricatedOverlay.setResourceValue("mystring", TypedValue.TYPE_STRING, "Hello")
 

The app can create any FabricatedOverlay instance by calling the following APIs.

Summary

Public constructors

FabricatedOverlay(String overlayName, String targetPackage)

Create a fabricated overlay to overlay on the specified package.

Public methods

OverlayIdentifier getIdentifier()

Retrieves the identifier for this fabricated overlay.

void setNinePatchResourceValue(String resourceName, ParcelFileDescriptor value, String configuration)

Sets the resource value in the fabricated overlay from a nine patch.

void setResourceValue(String resourceName, AssetFileDescriptor value, String configuration)

Sets the resource value in the fabricated overlay for the file descriptor type with the configuration.

void setResourceValue(String resourceName, int dataType, int value, String configuration)

Sets the resource value in the fabricated overlay for the integer-like types with the configuration.

void setResourceValue(String resourceName, ParcelFileDescriptor value, String configuration)

Sets the resource value in the fabricated overlay for the file descriptor type with the configuration.

void setResourceValue(String resourceName, int dataType, String value, String configuration)

Sets the resource value in the fabricated overlay for the string-like type with the configuration.

void setTargetOverlayable(String targetOverlayable)

Set the target overlayable name of the overlay The target package defines may define several overlayables.

Inherited methods

Public constructors

FabricatedOverlay

Added in API level 34
public FabricatedOverlay (String overlayName, 
                String targetPackage)

Create a fabricated overlay to overlay on the specified package.

Parameters
overlayName String: a name used to uniquely identify the fabricated overlay owned by the caller itself. This value cannot be null.

targetPackage String: the name of the package to be overlaid This value cannot be null.

Public methods

getIdentifier

Added in API level 34
public OverlayIdentifier getIdentifier ()

Retrieves the identifier for this fabricated overlay.

Returns
OverlayIdentifier the overlay identifier This value cannot be null.

setNinePatchResourceValue

Added in API level 35
public void setNinePatchResourceValue (String resourceName, 
                ParcelFileDescriptor value, 
                String configuration)

Sets the resource value in the fabricated overlay from a nine patch.

Parameters
resourceName String: name of the target resource to overlay (in the form [package]:type/entry) This value cannot be null.

value ParcelFileDescriptor: the file descriptor whose contents are the value of the frro This value cannot be null.

configuration String: The string representation of the config this overlay is enabled for This value may be null.

Returns
void This value cannot be null.

setResourceValue

Added in API level 35
public void setResourceValue (String resourceName, 
                AssetFileDescriptor value, 
                String configuration)

Sets the resource value in the fabricated overlay for the file descriptor type with the configuration.

Parameters
resourceName String: name of the target resource to overlay (in the form [package]:type/entry) This value cannot be null.

value AssetFileDescriptor: the file descriptor whose contents are the value of the frro This value cannot be null.

configuration String: The string representation of the config this overlay is enabled for This value may be null.

Returns
void This value cannot be null.

setResourceValue

Added in API level 34
public void setResourceValue (String resourceName, 
                int dataType, 
                int value, 
                String configuration)

Sets the resource value in the fabricated overlay for the integer-like types with the configuration.

Parameters
resourceName String: name of the target resource to overlay (in the form [package]:type/entry) This value cannot be null.

dataType int: the data type of the new value Value is between TypedValue.TYPE_FIRST_INT and TypedValue.TYPE_LAST_INT inclusive

value int: the integer representing the new value

configuration String: The string representation of the config this overlay is enabled for This value may be null.

Returns
void This value cannot be null.

setResourceValue

Added in API level 34
public void setResourceValue (String resourceName, 
                ParcelFileDescriptor value, 
                String configuration)

Sets the resource value in the fabricated overlay for the file descriptor type with the configuration.

Parameters
resourceName String: name of the target resource to overlay (in the form [package]:type/entry) This value cannot be null.

value ParcelFileDescriptor: the file descriptor whose contents are the value of the frro This value cannot be null.

configuration String: The string representation of the config this overlay is enabled for This value may be null.

Returns
void This value cannot be null.

setResourceValue

Added in API level 34
public void setResourceValue (String resourceName, 
                int dataType, 
                String value, 
                String configuration)

Sets the resource value in the fabricated overlay for the string-like type with the configuration.

Parameters
resourceName String: name of the target resource to overlay (in the form [package]:type/entry) This value cannot be null.

dataType int: the data type of the new value Value is TypedValue.TYPE_STRING

value String: the string representing the new value This value cannot be null.

configuration String: The string representation of the config this overlay is enabled for This value may be null.

Returns
void This value cannot be null.

setTargetOverlayable

Added in API level 34
public void setTargetOverlayable (String targetOverlayable)

Set the target overlayable name of the overlay The target package defines may define several overlayables. The FabricatedOverlay should specify which overlayable to be overlaid.

Parameters
targetOverlayable String: the overlayable name defined in target package. This value may be null.