AconfigPackageCompat


public 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 methods

abstract boolean
getBooleanFlagValue(@NonNull String flagName, boolean defaultValue)

Retrieves the value of a boolean flag.

default static final @NonNull AconfigPackageCompat
load(@NonNull String packageName)

Loads an Aconfig Package from Aconfig Storage.

Public methods

getBooleanFlagValue

abstract boolean getBooleanFlagValue(@NonNull String flagName, boolean defaultValue)

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
@NonNull String flagName

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

boolean defaultValue

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.

load

default static final @NonNull AconfigPackageCompat load(@NonNull String packageName)

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
@NonNull String packageName

The name of the Aconfig package to load.

Returns
@NonNull 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.