PolicyUpdateReceiver


public abstract class PolicyUpdateReceiver
extends BroadcastReceiver

java.lang.Object
   ↳ android.content.BroadcastReceiver
     ↳ android.app.admin.PolicyUpdateReceiver


Base class for implementing a policy update receiver. This class provides a convenience for interpreting the raw intent actions (ACTION_DEVICE_POLICY_SET_RESULT and ACTION_DEVICE_POLICY_CHANGED) that are sent by the system.

The callback methods happen on the main thread of the process. Thus, long-running operations must be done on another thread.

When publishing your PolicyUpdateReceiver subclass as a receiver, it must require the Manifest.permission.BIND_DEVICE_ADMIN permission.

Admins can implement DeviceAdminService to ensure they receive all policy updates (for policies they have set) via onPolicyChanged(Context, String, Bundle, TargetUser, PolicyUpdateResult) by constantly being bound to by the system. For more information see DeviceAdminService.

Summary

Constants

String ACTION_DEVICE_POLICY_CHANGED

Action for a broadcast sent to admins to communicate back a change in a policy they have previously set.

String ACTION_DEVICE_POLICY_SET_RESULT

Action for a broadcast sent to admins to communicate back the result of setting a policy in DevicePolicyManager.

String EXTRA_ACCOUNT_TYPE

A string extra holding the account type this policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

String EXTRA_INTENT_FILTER

An IntentFilter extra holding the intent filter the policy relates to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

String EXTRA_PACKAGE_NAME

A string extra holding the package name the policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

String EXTRA_PERMISSION_NAME

A string extra holding the permission name the policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

Public constructors

PolicyUpdateReceiver()

Public methods

void onPolicyChanged(Context context, String policyIdentifier, Bundle additionalPolicyParams, TargetUser targetUser, PolicyUpdateResult policyUpdateResult)

Callback triggered when a policy previously set by the admin has changed.

void onPolicySetResult(Context context, String policyIdentifier, Bundle additionalPolicyParams, TargetUser targetUser, PolicyUpdateResult policyUpdateResult)

Callback triggered after an admin has set a policy using one of the APIs in DevicePolicyManager to notify the admin whether it has been successful or not.

Inherited methods

Constants

ACTION_DEVICE_POLICY_CHANGED

Added in API level 34
public static final String ACTION_DEVICE_POLICY_CHANGED

Action for a broadcast sent to admins to communicate back a change in a policy they have previously set.

Admins wishing to receive these updates should include this action in the intent filter for their receiver in the manifest, the receiver must be protected by Manifest.permission.BIND_DEVICE_ADMIN to ensure that only the system can send updates.

Admins shouldn't implement BroadcastReceiver.onReceive(Context, Intent) and should instead implement onPolicyChanged(Context, String, Bundle, TargetUser, PolicyUpdateResult).

Constant Value: "android.app.admin.action.DEVICE_POLICY_CHANGED"

ACTION_DEVICE_POLICY_SET_RESULT

Added in API level 34
public static final String ACTION_DEVICE_POLICY_SET_RESULT

Action for a broadcast sent to admins to communicate back the result of setting a policy in DevicePolicyManager.

Admins wishing to receive these updates (via onPolicySetResult(Context, String, Bundle, TargetUser, PolicyUpdateResult)) should include this action in the intent filter for their receiver in the manifest, the receiver must be protected by Manifest.permission.BIND_DEVICE_ADMIN to ensure that only the system can send updates.

Admins shouldn't implement BroadcastReceiver.onReceive(Context, Intent) and should instead implement onPolicySetResult(Context, String, Bundle, TargetUser, PolicyUpdateResult).

Constant Value: "android.app.admin.action.DEVICE_POLICY_SET_RESULT"

EXTRA_ACCOUNT_TYPE

Added in API level 34
public static final String EXTRA_ACCOUNT_TYPE

A string extra holding the account type this policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

Constant Value: "android.app.admin.extra.ACCOUNT_TYPE"

EXTRA_INTENT_FILTER

Added in API level 34
public static final String EXTRA_INTENT_FILTER

An IntentFilter extra holding the intent filter the policy relates to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

Constant Value: "android.app.admin.extra.INTENT_FILTER"

EXTRA_PACKAGE_NAME

Added in API level 34
public static final String EXTRA_PACKAGE_NAME

A string extra holding the package name the policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

Constant Value: "android.app.admin.extra.PACKAGE_NAME"

EXTRA_PERMISSION_NAME

Added in API level 34
public static final String EXTRA_PERMISSION_NAME

A string extra holding the permission name the policy applies to, (see PolicyUpdateReceiver#onPolicyChanged and PolicyUpdateReceiver#onPolicySetResult)

Constant Value: "android.app.admin.extra.PERMISSION_NAME"

Public constructors

PolicyUpdateReceiver

public PolicyUpdateReceiver ()

Public methods

onPolicyChanged

Added in API level 34
public void onPolicyChanged (Context context, 
                String policyIdentifier, 
                Bundle additionalPolicyParams, 
                TargetUser targetUser, 
                PolicyUpdateResult policyUpdateResult)

Callback triggered when a policy previously set by the admin has changed.

Admins wishing to receive this callback should include PolicyUpdateReceiver#ACTION_DEVICE_POLICY_CHANGED in the intent filter for their receiver in the manifest, the receiver must be protected by Manifest.permission.BIND_DEVICE_ADMIN to ensure that only the system can send updates.

Parameters
context Context: the running context as per BroadcastReceiver.onReceive(Context, Intent) This value cannot be null.

policyIdentifier String: Key to identify which policy this callback relates to. This value cannot be null.

additionalPolicyParams Bundle: Bundle containing additional params that may be required to identify some of the policy (e.g. PolicyUpdateReceiver#EXTRA_PACKAGE_NAME and PolicyUpdateReceiver#EXTRA_PERMISSION_NAME). Each policy will document the required additional params if needed. This value cannot be null.

targetUser TargetUser: The TargetUser which this policy relates to. This value cannot be null.

policyUpdateResult PolicyUpdateResult: Indicates the reason the policy value has changed (e.g. PolicyUpdateResult#RESULT_POLICY_SET if the policy has changed to the value set by the admin, PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY if the policy has changed because another admin has set a conflicting policy, etc) This value cannot be null.

onPolicySetResult

Added in API level 34
public void onPolicySetResult (Context context, 
                String policyIdentifier, 
                Bundle additionalPolicyParams, 
                TargetUser targetUser, 
                PolicyUpdateResult policyUpdateResult)

Callback triggered after an admin has set a policy using one of the APIs in DevicePolicyManager to notify the admin whether it has been successful or not.

Admins wishing to receive this callback should include PolicyUpdateReceiver#ACTION_DEVICE_POLICY_SET_RESULT in the intent filter for their receiver in the manifest, the receiver must be protected by Manifest.permission.BIND_DEVICE_ADMIN to ensure that only the system can send updates.

Parameters
context Context: the running context as per BroadcastReceiver.onReceive(Context, Intent) This value cannot be null.

policyIdentifier String: Key to identify which policy this callback relates to. This value cannot be null.

additionalPolicyParams Bundle: Bundle containing additional params that may be required to identify some of the policy (e.g. PolicyUpdateReceiver#EXTRA_PACKAGE_NAME and PolicyUpdateReceiver#EXTRA_PERMISSION_NAME). Each policy will document the required additional params if needed. This value cannot be null.

targetUser TargetUser: The TargetUser which this policy relates to. This value cannot be null.

policyUpdateResult PolicyUpdateResult: Indicates whether the policy has been set successfully (PolicyUpdateResult#RESULT_POLICY_SET) or the reason it failed to apply (e.g. PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, etc). This value cannot be null.