Added in API level 23

SystemUpdatePolicy


class SystemUpdatePolicy : Parcelable
kotlin.Any
   ↳ android.app.admin.SystemUpdatePolicy

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(). 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:

<code>
  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);
  </code>

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

An exception class that represents various validation errors thrown from SystemUpdatePolicy#setFreezePeriods and DevicePolicyManager#setSystemUpdatePolicy

Constants
static Int

Installs system updates (without user interaction) as soon as they become available.

static Int

Installs system updates (without user interaction) during a daily maintenance window.

static Int

Postpones the installation of system updates for 30 days.

Inherited constants
Public methods
static SystemUpdatePolicy!

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

static SystemUpdatePolicy!

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

MutableList<FreezePeriod!>!

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

Int

Get the end of the maintenance window.

Int

Get the start of the maintenance window.

Int

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

SystemUpdatePolicy!

Configure a list of freeze periods on top of the current policy.

String

Unit
writeToParcel(dest: Parcel, flags: Int)

Properties
static Parcelable.Creator<SystemUpdatePolicy!>

Constants

TYPE_INSTALL_AUTOMATIC

Added in API level 23
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

Added in API level 23
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().

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

Added in API level 23
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

Added in API level 23
static fun createAutomaticInstallPolicy(): SystemUpdatePolicy!

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

createPostponeInstallPolicy

Added in API level 23
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.

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

See Also

createWindowedInstallPolicy

Added in API level 23
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 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.

describeContents

Added in API level 23
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

getFreezePeriods

Added in API level 28
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

Added in API level 23
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

Added in API level 23
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

Added in API level 23
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

Added in API level 28
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 will be thrown.

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

  • When a freeze period is defined, February 29th is disregarded so even though a freeze period can be specified to start or end on February 29th, it will be treated as if the period started or ended on February 28th.
  • When applying freeze period behavior to the device, a system clock of February 29th is treated as if it were February 28th
  • When calculating the number of days of a freeze period or separation between two freeze periods, February 29th is also ignored and not counted as one day.
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

Added in API level 23
fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 23
fun writeToParcel(
    dest: Parcel,
    flags: Int
): Unit
Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 23
static val CREATOR: Parcelable.Creator<SystemUpdatePolicy!>