Summary: [Methods](https://developer.android.com/reference/com/google/android/things/update/UpdateManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/com/google/android/things/update/UpdateManager#inhmethods) \| [\[Expand All\]](https://developer.android.com/reference/com/google/android/things/update/UpdateManager#)

# UpdateManager


`
public


class
UpdateManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | com.google.android.things.update.UpdateManager |

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy.Builder`, a deadline value also
needs to be specified using `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy.Builder#setApplyDeadline(long, java.util.concurrent.TimeUnit)`. When
using a policy other than `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#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 `https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus` that
is returned by `https://developer.android.com/reference/com/google/android/things/update/UpdateManager#getStatus()`

The UpdateManager supports a series of different usage scenarios. To automatically apply
updates and reboot as they come available, use `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_AND_REBOOT`:

```scdoc
     UpdateManager.getInstance().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 `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_ONLY` and then schedule the reboot at a time that is more convenient
for the device:

```ecl
     UpdateManager mUpdateManager = UpdateManager.getInstance();

     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 `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy` can be constructed with `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_CHECKS_ONLY`
and a very long deadline (years). When doing so, the application MUST use `https://developer.android.com/reference/com/google/android/things/update/UpdateManager#performUpdateNow(int)` with `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_ONLY` or `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_AND_REBOOT` to trigger an update to be acted on.

<br />

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#addStatusListener(com.google.android.things.update.StatusListener)(https://developer.android.com/reference/com/google/android/things/update/StatusListener listener) ` Register a `https://developer.android.com/reference/com/google/android/things/update/StatusListener` with the UpdateManager. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#getChannel()() ` Return the update channel that the device is using for update checks. |
| ` static https://developer.android.com/reference/com/google/android/things/update/UpdateManager` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#getInstance()() ` Returns the `https://developer.android.com/reference/com/google/android/things/update/UpdateManager` instance for this application. |
| ` https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#getStatus()() ` Return the latest `https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus`. |
| ` boolean` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#performUpdateNow(int)(int policy) ` Immediately check for an available software update, and act on that update per the given policy. |
| ` void` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#removeStatusListener(com.google.android.things.update.StatusListener)(https://developer.android.com/reference/com/google/android/things/update/StatusListener listener) ` Unregister a `https://developer.android.com/reference/com/google/android/things/update/StatusListener` from the UpdateManager. |
| ` void` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#setChannel(java.lang.String)(https://developer.android.com/reference/java/lang/String channel) ` Set the update channel that the device should be on. |
| ` void` | ` https://developer.android.com/reference/com/google/android/things/update/UpdateManager#setPolicy(com.google.android.things.update.UpdatePolicy)(https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy policy) ` Set the `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy` that the UpdateManager is to use. |

| ### Inherited methods |
|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/update/UpdateManager#)From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long, int)(long millis, int nanos) ` Causes the current thread to wait until another thread invokes the `https://developer.android.com/reference/java/lang/Object.html#notify()` method or the `https://developer.android.com/reference/java/lang/Object.html#notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long millis) ` Causes the current thread to wait until either another thread invokes the `https://developer.android.com/reference/java/lang/Object.html#notify()` method or the `https://developer.android.com/reference/java/lang/Object.html#notifyAll()` method for this object, or a specified amount of time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until another thread invokes the `https://developer.android.com/reference/java/lang/Object.html#notify()` method or the `https://developer.android.com/reference/java/lang/Object.html#notifyAll()` method for this object. | ||

## Public methods

### addStatusListener

```
void addStatusListener (StatusListener listener)
```

Register a `https://developer.android.com/reference/com/google/android/things/update/StatusListener` with the UpdateManager.

<br />

| Parameters ||
|---|---|
| `listener` | `StatusListener`: The listener to call with progress updates. <br /> |

### getChannel

```
String getChannel ()
```

Return the update channel that the device is using for update checks. e.g "stable-channel",
"beta-channel", etc.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The current update channel. <br /> |

### getInstance

```
UpdateManager getInstance ()
```

Returns the `https://developer.android.com/reference/com/google/android/things/update/UpdateManager` instance for this application.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/com/google/android/things/update/UpdateManager` | The UpdateManager instance. <br /> |

### getStatus

```
UpdateManagerStatus getStatus ()
```

Return the latest `https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus` | The latest `https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/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 `https://developer.android.com/reference/com/google/android/things/update/UpdateManager#setPolicy(com.google.android.things.update.UpdatePolicy)`.

- using `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_CHECKS_ONLY` will only perform an update check.
- using `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_ONLY`, if an update is found, it will be downloaded and applied.
- using `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy#POLICY_APPLY_AND_REBOOT`, if an update is found, it will be downloaded and applied, and then the device will be automatically rebooted.

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.

<br />

<br />

| Parameters ||
|---|---|
| `policy` | `int`: The policy to use for the operation <br /> |

| Returns ||
|---|---|
| `boolean` | True if the update check has been successfully started. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if an invalid value is specified for `policy` |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the UpdateManager service is not ready |

### removeStatusListener

```
void removeStatusListener (StatusListener listener)
```

Unregister a `https://developer.android.com/reference/com/google/android/things/update/StatusListener` from the UpdateManager.

<br />

| Parameters ||
|---|---|
| `listener` | `StatusListener`: The listener to unregister. <br /> |

### setChannel

```
void setChannel (String channel)
```

Set the update channel that the device should be on.

NOTE: When changing channel, the device automatically factory resets as part of the next
update (the update to the version from the new channel).

<br />

<br />

| Parameters ||
|---|---|
| `channel` | `String`: The new update channel. <br /> |

### setPolicy

```
void setPolicy (UpdatePolicy policy)
```

Set the `https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy` that the UpdateManager is to use.

<br />

| Parameters ||
|---|---|
| `policy` | `UpdatePolicy`: The UpdatePolicy to follow. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the UpdateManager service is not ready. |

-

  ## Interfaces

  - [StatusListener](https://developer.android.com/reference/com/google/android/things/update/StatusListener)
-

  ## Classes

  - [PendingUpdateInfo](https://developer.android.com/reference/com/google/android/things/update/PendingUpdateInfo)
  - [UpdateManager](https://developer.android.com/reference/com/google/android/things/update/UpdateManager)
  - [UpdateManagerStatus](https://developer.android.com/reference/com/google/android/things/update/UpdateManagerStatus)
  - [UpdatePolicy](https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy)
  - [UpdatePolicy.Builder](https://developer.android.com/reference/com/google/android/things/update/UpdatePolicy.Builder)
  - [VersionInfo](https://developer.android.com/reference/com/google/android/things/update/VersionInfo)