DevicePolicyManager.SetPermissionGrantState Method

Definition

Sets the grant state of a runtime permission for a specific application.

[Android.Runtime.Register("setPermissionGrantState", "(Landroid/content/ComponentName;Ljava/lang/String;Ljava/lang/String;I)Z", "GetSetPermissionGrantState_Landroid_content_ComponentName_Ljava_lang_String_Ljava_lang_String_IHandler", ApiSince=23)]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_RUNTIME_PERMISSIONS")]
public virtual bool SetPermissionGrantState (Android.Content.ComponentName? admin, string packageName, string permission, Android.App.Admin.PermissionGrantState grantState);
[<Android.Runtime.Register("setPermissionGrantState", "(Landroid/content/ComponentName;Ljava/lang/String;Ljava/lang/String;I)Z", "GetSetPermissionGrantState_Landroid_content_ComponentName_Ljava_lang_String_Ljava_lang_String_IHandler", ApiSince=23)>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_RUNTIME_PERMISSIONS")>]
abstract member SetPermissionGrantState : Android.Content.ComponentName * string * string * Android.App.Admin.PermissionGrantState -> bool
override this.SetPermissionGrantState : Android.Content.ComponentName * string * string * Android.App.Admin.PermissionGrantState -> bool

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with. Null if the caller is not a device admin.

packageName
String

The application to grant or revoke a permission to.

permission
String

The permission to grant or revoke.

grantState
PermissionGrantState

The permission grant state which is one of #PERMISSION_GRANT_STATE_DENIED, #PERMISSION_GRANT_STATE_DEFAULT, #PERMISSION_GRANT_STATE_GRANTED,

Returns

whether the permission was successfully granted or revoked.

Attributes

Remarks

Sets the grant state of a runtime permission for a specific application. The state can be #PERMISSION_GRANT_STATE_DEFAULT default in which a user can manage it through the UI, #PERMISSION_GRANT_STATE_DENIED denied, in which the permission is denied and the user cannot manage it through the UI, and #PERMISSION_GRANT_STATE_GRANTED granted in which the permission is granted and the user cannot manage it through the UI. This method can only be called by a profile owner, device owner, or a delegate given the #DELEGATION_PERMISSION_GRANT scope via #setDelegatedScopes. <p/> Note that user cannot manage other permissions in the affected group through the UI either and their granted state will be kept as the current value. Thus, it's recommended that you set the grant state of all the permissions in the affected group. <p/> Setting the grant state to #PERMISSION_GRANT_STATE_DEFAULT default does not revoke the permission. It retains the previous grant, if any. <p/> Device admins with a targetSdkVersion &lt; android.os.Build.VERSION_CODES#Q cannot grant and revoke permissions for applications built with a targetSdkVersion &lt; android.os.Build.VERSION_CODES#M. <p/> Admins with a targetSdkVersion &ge; android.os.Build.VERSION_CODES#Q can grant and revoke permissions of all apps. Similar to the user revoking a permission from a application built with a targetSdkVersion &lt; android.os.Build.VERSION_CODES#M the app-op matching the permission is set to android.app.AppOpsManager#MODE_IGNORED, but the permission stays granted.

NOTE: On devices running android.os.Build.VERSION_CODES#S and above, control over the following, sensors-related, permissions is restricted: <ul> <li>Manifest.permission.ACCESS_FINE_LOCATION</li> <li>Manifest.permission.ACCESS_BACKGROUND_LOCATION</li> <li>Manifest.permission.ACCESS_COARSE_LOCATION</li> <li>Manifest.permission.CAMERA</li> <li>Manifest.permission.RECORD_AUDIO</li> <li>Manifest.permission.RECORD_BACKGROUND_AUDIO</li> <li>Manifest.permission.ACTIVITY_RECOGNITION</li> <li>Manifest.permission.BODY_SENSORS</li> </ul>

A profile owner may not grant these permissions (i.e. call this method with any of the permissions listed above and grantState of #PERMISSION_GRANT_STATE_GRANTED), but may deny them.

A device owner, by default, may continue granting these permissions. However, for increased user control, the admin may opt out of controlling grants for these permissions by including #EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT in the provisioning parameters. In that case the device owner's control will be limited do denying these permissions.

NOTE: On devices running android.os.Build.VERSION_CODES#S and above, control over the following permissions are restricted for managed profile owners: <ul> <li>Manifest.permission.READ_SMS</li> </ul>

A managed profile owner may not grant these permissions (i.e. call this method with any of the permissions listed above and grantState of #PERMISSION_GRANT_STATE_GRANTED), but may deny them.

Attempts by the admin to grant these permissions, when the admin is restricted from doing so, will be silently ignored (no exception will be thrown).

Control over the following permissions are restricted for managed profile owners: <ul> <li>Manifest.permission.READ_SMS</li> </ul>

A managed profile owner may not grant these permissions (i.e. call this method with any of the permissions listed above and grantState of #PERMISSION_GRANT_STATE_GRANTED), but may deny them.

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

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