UpdateInfoManager


class UpdateInfoManager


Manages the persistent storage of security update information.

This class acts as the local database for the UpdateInfoService. It is responsible for:

  1. Storing the list of available UpdateInfo objects (persisted in SharedPreferences).

  2. Storing metadata about the update checks (e.g., getLastCheckTimeMillis).

  3. Cleaning up outdated updates by comparing them against the device's current state.

Typical usage involves an update client (like GOTA (Google Over-The-Air) or Play Store) registering new updates via registerUpdate when they are discovered, and the UpdateInfoService querying getAllUpdates to return them to consumers. An update client that checks more than one component also records the time of each check with setLastCheckTimeMillis(component, timestampMillis), so that consumers can tell which components were checked.

Summary

Public constructors

UpdateInfoManager(
    context: Context,
    customSecurityState: SecurityPatchState?
)

Public functions

Long

Retrieves the timestamp of the last successful update check.

Long

Returns the last successful check time recorded for component, in milliseconds since the epoch.

Unit

Registers information about an available update for the specified component.

Unit
setLastCheckTimeMillis(timestampMillis: Long)

Updates the provider-wide timestamp of the last successful update check.

Unit
setLastCheckTimeMillis(
    @SecurityPatchState.Component component: String,
    timestampMillis: Long
)

Updates or clears the time of the last successful update check for component.

Unit

Unregisters information about an available update for the specified component.

Public constructors

UpdateInfoManager

Added in 1.0.0
UpdateInfoManager(
    context: Context,
    customSecurityState: SecurityPatchState? = null
)

Public functions

getLastCheckTimeMillis

Added in 1.0.0
fun getLastCheckTimeMillis(): Long

Retrieves the timestamp of the last successful update check.

This metadata is stored separately from the update list. The value represents "Wall Clock Time" to ensure it remains meaningful across device reboots.

The result is the latest of the provider-wide check time and any check times recorded for individual components with setLastCheckTimeMillis(component, timestampMillis). If no component check time has been recorded, it is the provider-wide check time.

Returns
Long

The time of the last check in milliseconds since the epoch (System.currentTimeMillis), or 0 if no check has ever occurred.

getLastCheckTimeMillis

Added in 1.1.0-alpha01
fun getLastCheckTimeMillis(@SecurityPatchState.Component component: String): Long

Returns the last successful check time recorded for component, in milliseconds since the epoch.

Only times recorded with setLastCheckTimeMillis(component, timestampMillis) are returned. The provider-wide check time and the check times of registered updates are not used.

Parameters
@SecurityPatchState.Component component: String

component identifier, such as SecurityPatchState.COMPONENT_SYSTEM or SecurityPatchState.COMPONENT_SYSTEM_MODULES

Value is one of the following:

  • SYSTEM
  • SYSTEM_MODULES
  • KERNEL
  • VENDOR

Returns
Long

last check time recorded for component in milliseconds since the epoch (System.currentTimeMillis), or 0 if none has been recorded

registerUpdate

Added in 1.0.0
fun registerUpdate(updateInfo: UpdateInfo): Unit

Registers information about an available update for the specified component.

Parameters
updateInfo: UpdateInfo

Update information structure.

setLastCheckTimeMillis

Added in 1.0.0
fun setLastCheckTimeMillis(timestampMillis: Long): Unit

Updates the provider-wide timestamp of the last successful update check.

Usage Note for Hosts: The UpdateInfoService base class automatically calls this method after a successful network fetch triggered by a client request. Host applications should only call this method manually if they are performing out-of-band synchronizations (e.g., via a background JobService or WorkManager).

A host that checks more than one component should instead record each check with setLastCheckTimeMillis(component, timestampMillis), so that clients can tell which component was checked. getLastCheckTimeMillis() takes those per-component times into account.

Parameters
timestampMillis: Long

The current time in milliseconds (System.currentTimeMillis).

setLastCheckTimeMillis

Added in 1.1.0-alpha01
fun setLastCheckTimeMillis(
    @SecurityPatchState.Component component: String,
    timestampMillis: Long
): Unit

Updates or clears the time of the last successful update check for component.

A host that checks more than one component should call this after every successful check of component, including checks that find no update, so that a check of one component is not mistaken for a check of another. registerUpdate and unregisterUpdate do not record a check time for the component.

Passing 0 removes the recorded check time for component, so that it is omitted from androidx.security.state.UpdateCheckResult.componentLastCheckTimesMillis.

Parameters
@SecurityPatchState.Component component: String

component identifier, such as SecurityPatchState.COMPONENT_SYSTEM or SecurityPatchState.COMPONENT_SYSTEM_MODULES

Value is one of the following:

  • SYSTEM
  • SYSTEM_MODULES
  • KERNEL
  • VENDOR

timestampMillis: Long

wall-clock time of the check in milliseconds (System.currentTimeMillis), or 0 to clear the recorded time for component

Throws
IllegalArgumentException

if component is empty or timestampMillis is negative

unregisterUpdate

Added in 1.0.0
fun unregisterUpdate(updateInfo: UpdateInfo): Unit

Unregisters information about an available update for the specified component.

Parameters
updateInfo: UpdateInfo

Update information structure.