Stay organized with collections Save and categorize content based on your preferences.

public abstract class PolicyUpdatesReceiver
extends BroadcastReceiver



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 PolicyUpdatesReceiver 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, PolicyUpdateReason) 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_PACKAGE_NAME

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

String EXTRA_PERMISSION_NAME

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

int POLICY_SET_RESULT_FAILURE

Result code passed in to onPolicySetResult(Context, String, Bundle, TargetUser, int, PolicyUpdateReason) to indicate that the policy has NOT been set, a PolicyUpdateReason will be passed in to onPolicySetResult(Context, String, Bundle, TargetUser, int, PolicyUpdateReason) to indicate the reason.

int POLICY_SET_RESULT_SUCCESS

Result code passed in to onPolicySetResult(Context, String, Bundle, TargetUser, int, PolicyUpdateReason) to indicate that the policy has been set successfully.

Public constructors

PolicyUpdatesReceiver()

Public methods

void onPolicyChanged(Context context, String policyKey, Bundle additionalPolicyParams, TargetUser targetUser, PolicyUpdateReason reason)

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

void onPolicySetResult(Context context, String policyKey, Bundle additionalPolicyParams, TargetUser targetUser, int result, PolicyUpdateReason reason)

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

From class android.content.BroadcastReceiver

final void abortBroadcast()

Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast.

final void clearAbortBroadcast()

Clears the flag indicating that this receiver should abort the current broadcast.

final boolean getAbortBroadcast()

Returns the flag indicating whether or not this receiver should abort the current broadcast.

final boolean getDebugUnregister()

Return the last value given to setDebugUnregister(boolean).

final int getResultCode()

Retrieve the current result code, as set by the previous receiver.

final String getResultData()

Retrieve the current result data, as set by the previous receiver.

final Bundle getResultExtras(boolean makeMap)

Retrieve the current result extra data, as set by the previous receiver.

final BroadcastReceiver.PendingResult goAsync()

This can be called by an application in onReceive(Context, Intent) to allow it to keep the broadcast active after returning from that function.

final boolean isInitialStickyBroadcast()

Returns true if the receiver is currently processing the initial value of a sticky broadcast -- that is, the value that was last broadcast and is currently held in the sticky cache, so this is not directly the result of a broadcast right now.

final boolean isOrderedBroadcast()

Returns true if the receiver is currently processing an ordered broadcast.

abstract void onReceive(Context context, Intent intent)

This method is called when the BroadcastReceiver is receiving an Intent broadcast.

IBinder peekService(Context myContext, Intent service)

Provide a binder to an already-bound service.

final void setDebugUnregister(boolean debug)

Control inclusion of debugging help for mismatched calls to Context.registerReceiver().

final void setOrderedHint(boolean isOrdered)

For internal use, sets the hint about whether this BroadcastReceiver is running in ordered mode.

final void setResult(int code, String data, Bundle extras)

Change all of the result data returned from this broadcasts; only works with broadcasts sent through Context.sendOrderedBroadcast.

final void setResultCode(int code)

Change the current result code of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast.

final void setResultData(String data)

Change the current result data of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast.

final void setResultExtras(Bundle extras)

Change the current result extras of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast.

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

ACTION_DEVICE_POLICY_SET_RESULT

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, int, PolicyUpdateReason)) 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, int, PolicyUpdateReason).

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

POLICY_SET_RESULT_FAILURE

public static final int POLICY_SET_RESULT_FAILURE

Result code passed in to onPolicySetResult(Context, String, Bundle, TargetUser, int, PolicyUpdateReason) to indicate that the policy has NOT been set, a PolicyUpdateReason will be passed in to onPolicySetResult(Context, String, Bundle, TargetUser, int, PolicyUpdateReason) to indicate the reason.

Constant Value: -1 (0xffffffff)

Public constructors

PolicyUpdatesReceiver

public PolicyUpdatesReceiver ()

Public methods

onPolicyChanged

public void onPolicyChanged (Context context, 
                String policyKey, 
                Bundle additionalPolicyParams, 
                TargetUser targetUser, 
                PolicyUpdateReason reason)

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

Admins wishing to receive this callback should include PolicyUpdatesReceiver#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.
policyKey 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. PolicyUpdatesReceiver#EXTRA_PACKAGE_NAME and PolicyUpdatesReceiver#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.
reason PolicyUpdateReason: Indicates the reason the policy value has changed. This value cannot be null.

onPolicySetResult

public void onPolicySetResult (Context context, 
                String policyKey, 
                Bundle additionalPolicyParams, 
                TargetUser targetUser, 
                int result, 
                PolicyUpdateReason reason)

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 PolicyUpdatesReceiver#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.
policyKey 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. PolicyUpdatesReceiver#EXTRA_PACKAGE_NAME and PolicyUpdatesReceiver#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.
result int: Indicates whether the policy has been set successfully, (see PolicyUpdatesReceiver#POLICY_SET_RESULT_SUCCESS and PolicyUpdatesReceiver#POLICY_SET_RESULT_FAILURE). Value is either 0 or a combination of POLICY_SET_RESULT_SUCCESS, and POLICY_SET_RESULT_FAILURE
reason PolicyUpdateReason: Indicates the reason the policy failed to apply, null if the policy was applied successfully.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2023-02-08 UTC.