AconfigPackageCompat


interface AconfigPackageCompat


An Aconfig Package containing the enabled state of its flags.

Note: This class is intended only to be used by generated code. To determine if a given flag is enabled in app or library code, the generated Android flag accessor methods should be used.

This class is used to read the flags from an Aconfig Package. Each instance of this class will cache information related to one package. To read flags from a different package, a new instance of this class should be created using AconfigPackageCompat.load.

Summary

Public companion functions

AconfigPackageCompat
load(packageName: String)

Loads an Aconfig Package from Aconfig Storage.

Public functions

Boolean
getBooleanFlagValue(flagName: String, defaultValue: Boolean)

Retrieves the value of a boolean flag.

Public companion functions

load

fun load(packageName: String): AconfigPackageCompat

Loads an Aconfig Package from Aconfig Storage.

This method attempts to load the specified Aconfig package.

Note: This method differs from the platform implementation in that is guaranteed to return an empty package if the packageName is not found in the container, rather than throwing an exception.

Platform-specific behavior:

  • Prior to API level 36, this method always returns an empty package

Parameters
packageName: String

The name of the Aconfig package to load.

Returns
AconfigPackageCompat

An instance of AconfigPackageCompat, which may be empty if the package is not found in the container.

Throws
android.os.flagging.AconfigStorageReadException

if there is an error reading from Aconfig Storage, such as if the storage system is not found or there is an error reading the storage file. The specific error code can be obtained using AconfigStorageReadException.getErrorCode.

Public functions

getBooleanFlagValue

fun getBooleanFlagValue(flagName: String, defaultValue: Boolean): Boolean

Retrieves the value of a boolean flag.

This method retrieves the value of the specified flag. If the flag exists within the loaded Aconfig Package, its value is returned. Otherwise, the provided defaultValue is returned.

Platform-specific behavior:

  • Prior to API level 36, this method always returns defaultValue

Parameters
flagName: String

The name of the flag (excluding any package name prefix).

defaultValue: Boolean

The value to return if the flag is not found.

Returns
Boolean

The boolean value of the flag, or defaultValue if the flag is not found.