Added in API level 34

FabricatedOverlay

open class FabricatedOverlay
kotlin.Any
   ↳ 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 android.content.om.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.

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

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

<code>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")
  </code>

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

Summary

Public constructors
FabricatedOverlay(overlayName: String, targetPackage: String)

Create a fabricated overlay to overlay on the specified package.

Public methods
open OverlayIdentifier

Retrieves the identifier for this fabricated overlay.

open Unit
setResourceValue(resourceName: String, dataType: Int, value: Int, configuration: String?)

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

open Unit
setResourceValue(resourceName: String, dataType: Int, value: String, configuration: String?)

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

open Unit
setResourceValue(resourceName: String, value: ParcelFileDescriptor, configuration: String?)

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

open Unit
setTargetOverlayable(targetOverlayable: String?)

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

Public constructors

FabricatedOverlay

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

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
open fun getIdentifier(): OverlayIdentifier

Retrieves the identifier for this fabricated overlay.

Return
OverlayIdentifier the overlay identifier This value cannot be null.

setResourceValue

Added in API level 34
open fun setResourceValue(
    resourceName: String,
    dataType: Int,
    value: Int,
    configuration: String?
): Unit

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.
Return
Unit This value cannot be null.

setResourceValue

Added in API level 34
open fun setResourceValue(
    resourceName: String,
    dataType: Int,
    value: String,
    configuration: String?
): Unit

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 android.util.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.
Return
Unit This value cannot be null.

setResourceValue

Added in API level 34
open fun setResourceValue(
    resourceName: String,
    value: ParcelFileDescriptor,
    configuration: String?
): Unit

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.
Return
Unit This value cannot be null.

setTargetOverlayable

Added in API level 34
open fun setTargetOverlayable(targetOverlayable: String?): Unit

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.