SystemUpdatePolicy  |  API reference  |  Android Developers (original) (raw)


class SystemUpdatePolicy : Parcelable

Determines when over-the-air system updates are installed on a device. Only a device policy controller (DPC) running in device owner mode or in profile owner mode for an organization-owned device can set an update policy for the device by calling the DevicePolicyManager method [setSystemUpdatePolicy()](/reference/kotlin/android/app/admin/DevicePolicyManager#setSystemUpdatePolicy%28android.content.ComponentName,%20android.app.admin.SystemUpdatePolicy%29). An update policy affects the pending system update (if there is one) and any future updates for the device.

If a policy is set on a device, the system doesn't notify the user about updates.

Example

The example below shows how a DPC might set a maintenance window for system updates:

private final MAINTENANCE_WINDOW_START = 1380; // 11pm private final MAINTENANCE_WINDOW_END = 120; // 2am

// ...

// Create the system update policy SystemUpdatePolicy policy = SystemUpdatePolicy.createWindowedInstallPolicy( MAINTENANCE_WINDOW_START, MAINTENANCE_WINDOW_END);

// Get a DevicePolicyManager instance to set the policy on the device DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName adminComponent = getComponentName(context); dpm.setSystemUpdatePolicy(adminComponent, policy);

Developer guide

To learn more, read Manage system updates.

Note: Google Play system updates (also called Mainline updates) are automatically downloaded but require a device reboot to be installed. Refer to the mainline section in Manage system updates for further details.

Summary

Nested classes
ValidationFailedException An exception class that represents various validation errors thrown from SystemUpdatePolicy.setFreezePeriods and DevicePolicyManager.setSystemUpdatePolicy
Constants
static Int TYPE_INSTALL_AUTOMATIC Installs system updates (without user interaction) as soon as they become available.
static Int TYPE_INSTALL_WINDOWED Installs system updates (without user interaction) during a daily maintenance window.
static Int TYPE_POSTPONE Postpones the installation of system updates for 30 days.
Inherited constants
From class Parcelable Int CONTENTS_FILE_DESCRIPTOR Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor. Int PARCELABLE_WRITE_RETURN_VALUE Flag for use with writeToParcel: the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout Parcelable)". Some implementations may want to release resources at this point.
Public methods
static SystemUpdatePolicy! createAutomaticInstallPolicy() Create a policy object and set it to install update automatically as soon as one is available.
static SystemUpdatePolicy! createPostponeInstallPolicy() Create a policy object and set it to block installation for a maximum period of 30 days.
static SystemUpdatePolicy! createWindowedInstallPolicy(startTime: Int, endTime: Int) Create a policy object and set it to: new system update will only be installed automatically when the system clock is inside a daily maintenance window.
Int describeContents()
MutableList<FreezePeriod!>! getFreezePeriods() Returns the list of freeze periods previously set on this system update policy object.
Int getInstallWindowEnd() Get the end of the maintenance window.
Int getInstallWindowStart() Get the start of the maintenance window.
Int getPolicyType() Returns the type of system update policy, or -1 if no policy has been set.
SystemUpdatePolicy! setFreezePeriods(freezePeriods: MutableList<FreezePeriod!>!) Configure a list of freeze periods on top of the current policy.
String toString()
Unit writeToParcel(dest: Parcel, flags: Int)
Properties
static Parcelable.Creator<SystemUpdatePolicy!> CREATOR

Constants

TYPE_INSTALL_AUTOMATIC

static val TYPE_INSTALL_AUTOMATIC: Int

Installs system updates (without user interaction) as soon as they become available. Setting this policy type immediately installs any pending updates that might be postponed or waiting for a maintenance window.

Value: 1

TYPE_INSTALL_WINDOWED

static val TYPE_INSTALL_WINDOWED: Int

Installs system updates (without user interaction) during a daily maintenance window. Set the start and end of the daily maintenance window, as minutes of the day, when creating a new TYPE_INSTALL_WINDOWED policy. See [createWindowedInstallPolicy()](#createWindowedInstallPolicy%28kotlin.Int,%20kotlin.Int%29).

No connectivity, not enough disk space, or a low battery are typical reasons Android might not install a system update in the daily maintenance window. After 30 days trying to install an update in the maintenance window (regardless of policy changes in this period), the system prompts the device user to install the update.

Value: 2

TYPE_POSTPONE

static val TYPE_POSTPONE: Int

Postpones the installation of system updates for 30 days. After the 30-day period has ended, the system prompts the device user to install the update.

The system limits each update to one 30-day postponement. The period begins when the system first postpones the update and setting new TYPE_POSTPONE policies won’t extend the period. If, after 30 days the update isn't installed (through policy changes), the system prompts the user to install the update.

Note: Device manufacturers or carriers might choose to exempt important security updates from a postponement policy. Exempted updates notify the device user when they become available.

Value: 3

Public methods

createAutomaticInstallPolicy

static fun createAutomaticInstallPolicy(): SystemUpdatePolicy!

Create a policy object and set it to install update automatically as soon as one is available.

createPostponeInstallPolicy

static fun createPostponeInstallPolicy(): SystemUpdatePolicy!

Create a policy object and set it to block installation for a maximum period of 30 days. To learn more about this policy's behavior, see [TYPE_POSTPONE](#TYPE%5FPOSTPONE:kotlin.Int).

Note: security updates (e.g. monthly security patches) will not be affected by this policy.

createWindowedInstallPolicy

static fun createWindowedInstallPolicy(
    startTime: Int,
    endTime: Int
): SystemUpdatePolicy!

Create a policy object and set it to: new system update will only be installed automatically when the system clock is inside a daily maintenance window. If the start and end times are the same, the window is considered to include the whole 24 hours. That is, updates can install at any time. If start time is later than end time, the window is considered spanning midnight (i.e. the end time denotes a time on the next day). The maintenance window will last for 30 days for any given update, after which the window will no longer be effective and the pending update will be made available for manual installation as if no system update policy were set on the device. See [TYPE_INSTALL_WINDOWED](#TYPE%5FINSTALL%5FWINDOWED:kotlin.Int) for the details of this policy's behavior.

Parameters
startTime Int: the start of the maintenance window, measured as the number of minutes from midnight in the device's local time. Must be in the range of [0, 1440).
endTime Int: the end of the maintenance window, measured as the number of minutes from midnight in the device's local time. Must be in the range of [0, 1440).
Return
SystemUpdatePolicy! The configured policy.
Exceptions
java.lang.IllegalArgumentException If the startTime or endTime isn't in the accepted range.

getFreezePeriods

fun getFreezePeriods(): MutableList<FreezePeriod!>!

Returns the list of freeze periods previously set on this system update policy object.

Return
MutableList<FreezePeriod!>! the list of freeze periods, or an empty list if none was set.

getInstallWindowEnd

fun getInstallWindowEnd(): Int

Get the end of the maintenance window.

Return
Int the end of the maintenance window measured as the number of minutes from midnight, or -1 if the policy does not have a maintenance window.

getInstallWindowStart

fun getInstallWindowStart(): Int

Get the start of the maintenance window.

Return
Int the start of the maintenance window measured as the number of minutes from midnight, or -1 if the policy does not have a maintenance window.

getPolicyType

fun getPolicyType(): Int

Returns the type of system update policy, or -1 if no policy has been set.

Return
Int The policy type or -1 if the type isn't set. Value is android.app.admin.SystemUpdatePolicy#TYPE_INSTALL_AUTOMATIC, android.app.admin.SystemUpdatePolicy#TYPE_INSTALL_WINDOWED, or android.app.admin.SystemUpdatePolicy#TYPE_POSTPONE

setFreezePeriods

fun setFreezePeriods(freezePeriods: MutableList<FreezePeriod!>!): SystemUpdatePolicy!

Configure a list of freeze periods on top of the current policy. When the device's clock is within any of the freeze periods, all incoming system updates including security patches will be blocked and cannot be installed. When the device is outside the freeze periods, the normal policy behavior will apply.

Each individual freeze period is allowed to be at most 90 days long, and adjacent freeze periods need to be at least 60 days apart. Also, the list of freeze periods should not contain duplicates or overlap with each other. If any of these conditions is not met, a [ValidationFailedException](/reference/kotlin/android/app/admin/SystemUpdatePolicy.ValidationFailedException) will be thrown.

Handling of leap year: we ignore leap years in freeze period calculations, in particular,

Parameters
freezePeriods MutableList<FreezePeriod!>!: the list of freeze periods
Return
SystemUpdatePolicy! this instance
Exceptions
android.app.admin.SystemUpdatePolicy.ValidationFailedException if the supplied freeze periods do not meet the requirement set above

toString

fun toString(): String

Return
String a string representation of the object.

Properties