DevicePolicyManager.AddUserRestriction(ComponentName, String) Method

Definition

Called by a profile owner, device owner or a holder of any permission that is associated with a user restriction to set a user restriction specified by the key.

[Android.Runtime.Register("addUserRestriction", "(Landroid/content/ComponentName;Ljava/lang/String;)V", "GetAddUserRestriction_Landroid_content_ComponentName_Ljava_lang_String_Handler")]
public virtual void AddUserRestriction (Android.Content.ComponentName admin, string? key);
[<Android.Runtime.Register("addUserRestriction", "(Landroid/content/ComponentName;Ljava/lang/String;)V", "GetAddUserRestriction_Landroid_content_ComponentName_Ljava_lang_String_Handler")>]
abstract member AddUserRestriction : Android.Content.ComponentName * string -> unit
override this.AddUserRestriction : Android.Content.ComponentName * string -> unit

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with.

key
String

The key of the restriction.

Attributes

Remarks

Called by a profile owner, device owner or a holder of any permission that is associated with a user restriction to set a user restriction specified by the key.

The calling device admin must be a profile owner, device owner or holder of any permission that is associated with a user restriction; if it is not, a security exception will be thrown.

The profile owner of an organization-owned managed profile may invoke this method on the DevicePolicyManager instance it obtained from #getParentProfileInstance(ComponentName), for enforcing device-wide restrictions.

See the constants in android.os.UserManager for the list of restrictions that can be enforced device-wide. These constants will also state in their documentation which permission is required to manage the restriction using this API.

For callers targeting Android android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE or above, calling this API will result in applying the restriction locally on the calling user, or locally on the parent profile if called from the DevicePolicyManager instance obtained from #getParentProfileInstance(ComponentName). To set a restriction globally, call #addUserRestrictionGlobally instead.

Starting from Build.VERSION_CODES#UPSIDE_DOWN_CAKE, after the user restriction policy has been set, PolicyUpdateReceiver#onPolicySetResult(Context, String, Bundle, TargetUser, PolicyUpdateResult) will notify the admin on whether the policy was successfully set or not. This callback will contain: <ul> <li> The policy identifier returned from DevicePolicyIdentifiers#getIdentifierForUserRestriction(String)<li> The TargetUser that this policy relates to <li> The PolicyUpdateResult, which will be PolicyUpdateResult#RESULT_POLICY_SET if the policy was successfully set or the reason the policy failed to be set (e.g. PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY) </ul> If there has been a change to the policy, PolicyUpdateReceiver#onPolicyChanged(Context, String, Bundle, TargetUser, PolicyUpdateResult) will notify the admin of this change. This callback will contain the same parameters as PolicyUpdateReceiver#onPolicySetResult and the PolicyUpdateResult will contain the reason why the policy changed.

Java documentation for android.app.admin.DevicePolicyManager.addUserRestriction(android.content.ComponentName, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to