Skip to content

Most visited

Recently visited

navigation

UpdateManager

UpdateManager

public class UpdateManager
extends Object

java.lang.Object
   ↳ com.google.android.things.update.UpdateManager


The UpdateManager allows an application or service to control how updates are automatically applied to the device. Updating a device involves performing the following operations:

  1. Checking for an available software update
  2. Downloading and applying an update
  3. Rebooting the device into the new software version

The UpdateManager defines a set of Policies that are used to determine which of these steps are taken automatically, and which need to be initiated by the device's application software.

When creating a policy using the UpdatePolicy.Builder, a deadline value also needs to be specified using setApplyDeadline(long, TimeUnit). When using a policy other than POLICY_APPLY_AND_REBOOT, this deadline governs how long the UpdateManager will wait for before it will automatically apply the update (if not already applied) and then reboot into the updated software. Depending on the needs of the application, examples values are: 1 day, 1 week, 30 days.

This provides a safety net so that developers can be certain that updates will eventually be applied, even if the device is using a policy that restricts automatically applying an update, rebooting the device, or both.

The current policy that's in use is returned as part of the UpdateManagerStatus that is returned by getStatus()

The UpdateManager supports a series of different usage scenarios. To automatically apply updates and reboot as they come available, use POLICY_APPLY_AND_REBOOT:


     new UpdateManager().setPolicy(
         new UpdatePolicy.Builder()
             .setPolicy(POLICY_APPLY_AND_REBOOT)
             .setUpdateDeadline(1, TimeUnit.DAYS)
             .build());

 

For a device that should not reboot at an arbitrary time use POLICY_APPLY_ONLY and then schedule the reboot at a time that is more convenient for the device:


     UpdateManager mUpdateManager = new UpdateManager();

     mUpdateManager.setPolicy(
         new UpdatePolicy.Builder()
             .setPolicy(POLICY_APPLY_ONLY)
             .setUpdateDeadline(2, TimeUnit.DAYS)
             .build());

     mUpdateManager.addStatusListener( updateManagerStatus -> {
         if (updateManagerStatus.currentState == UpdateManagerStatus.STATE_UPDATED_NEEDS_REBOOT) {
             scheduleRebootAtMidnight();
         }
     });

 

For devices that may only be updated by the direct action of a person or remote management system, an UpdatePolicy can be constructed with POLICY_CHECKS_ONLY and a very long deadline (years). When doing so, the application MUST use performUpdateNow(int) with POLICY_APPLY_ONLY or POLICY_APPLY_AND_REBOOT to trigger an update to be acted on.

Summary

Constants

int POLICY_APPLY_AND_REBOOT

Use with setPolicy(int) and performUpdateNow(int) to download and apply updates, followed by an automatic reboot of the device.

int POLICY_APPLY_ONLY

Use with setPolicy(int) and performUpdateNow(int) to download and apply updates.

int POLICY_CHECKS_ONLY

Use with setPolicy(int) and performUpdateNow(int) to check for software updates.

Public constructors

UpdateManager()

Public methods

void addStatusListener(StatusListener listener)

Register a StatusListener with the UpdateManager.

UpdateManagerStatus getStatus()

Return the latest UpdateManagerStatus.

boolean performUpdateNow(int policy)

Immediately check for an available software update, and act on that update per the given policy.

void removeStatusListener(StatusListener listener)

Unregister a StatusListener from the UpdateManager.

void setPolicy(UpdatePolicy policy)

Set the UpdatePolicy that the UpdateManager is to use.

Inherited methods

From class java.lang.Object

Constants

POLICY_APPLY_AND_REBOOT

int POLICY_APPLY_AND_REBOOT

Use with setPolicy(int) and performUpdateNow(int) to download and apply updates, followed by an automatic reboot of the device.

See also:

Constant Value: 1 (0x00000001)

POLICY_APPLY_ONLY

int POLICY_APPLY_ONLY

Use with setPolicy(int) and performUpdateNow(int) to download and apply updates. The device is ready to be rebooted using reboot() when onStatusUpdate(UpdateManagerStatus) is called with a status of STATE_UPDATED_NEEDS_REBOOT.

See also:

Constant Value: 2 (0x00000002)

POLICY_CHECKS_ONLY

int POLICY_CHECKS_ONLY

Use with setPolicy(int) and performUpdateNow(int) to check for software updates. A software update is available when onStatusUpdate(UpdateManagerStatus) is called with a status of STATE_UPDATE_AVAILABLE.

See also:

Constant Value: 3 (0x00000003)

Public constructors

UpdateManager

UpdateManager ()

Public methods

addStatusListener

void addStatusListener (StatusListener listener)

Register a StatusListener with the UpdateManager.

Parameters
listener StatusListener: The listener to call with progress updates.

getStatus

UpdateManagerStatus getStatus ()

Return the latest UpdateManagerStatus.

Returns
UpdateManagerStatus The latest UpdateManagerStatus.
Throws
IllegalStateException if the UpdateManager service is not ready

performUpdateNow

boolean performUpdateNow (int policy)

Immediately check for an available software update, and act on that update per the given policy.

Calls to this method override the policy set via setPolicy(UpdatePolicy).

If this is called while an update (or check) is already in progress, this will return false to indicate that the request to perform and update was not acted on.

Parameters
policy int: The policy to use for the operation
Returns
boolean True if the update check has been successfully started.
Throws
IllegalArgumentException if an invalid value is specified for policy
IllegalStateException if the UpdateManager service is not ready

removeStatusListener

void removeStatusListener (StatusListener listener)

Unregister a StatusListener from the UpdateManager.

Parameters
listener StatusListener: The listener to unregister.

setPolicy

void setPolicy (UpdatePolicy policy)

Set the UpdatePolicy that the UpdateManager is to use.

Parameters
policy UpdatePolicy: The UpdatePolicy to follow.
Throws
IllegalStateException if the UpdateManager service is not ready.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)