Compartilhar via


PackageManager.AddWhitelistedRestrictedPermission Method

Definition

Adds a whitelisted restricted permission for an app.

[Android.Runtime.Register("addWhitelistedRestrictedPermission", "(Ljava/lang/String;Ljava/lang/String;I)Z", "GetAddWhitelistedRestrictedPermission_Ljava_lang_String_Ljava_lang_String_IHandler", ApiSince=29)]
[Android.Runtime.RequiresPermission("android.permission.WHITELIST_RESTRICTED_PERMISSIONS")]
public virtual bool AddWhitelistedRestrictedPermission (string packageName, string permName, Android.Content.PM.FlagPermission whitelistFlags);
[<Android.Runtime.Register("addWhitelistedRestrictedPermission", "(Ljava/lang/String;Ljava/lang/String;I)Z", "GetAddWhitelistedRestrictedPermission_Ljava_lang_String_Ljava_lang_String_IHandler", ApiSince=29)>]
[<Android.Runtime.RequiresPermission("android.permission.WHITELIST_RESTRICTED_PERMISSIONS")>]
abstract member AddWhitelistedRestrictedPermission : string * string * Android.Content.PM.FlagPermission -> bool
override this.AddWhitelistedRestrictedPermission : string * string * Android.Content.PM.FlagPermission -> bool

Parameters

packageName
String

The app for which to get whitelisted permissions.

permName
String

The whitelisted permission to add.

whitelistFlags
FlagPermission

The whitelists to which to add. Passing multiple flags updates all specified whitelists.

Returns

Whether the permission was added to the whitelist.

Attributes

Remarks

Adds a whitelisted restricted permission for an app.

Permissions can be hard restricted which means that the app cannot hold them or soft restricted where the app can hold the permission but in a weaker form. Whether a permission is PermissionInfo#FLAG_HARD_RESTRICTED hard restricted or PermissionInfo#FLAG_SOFT_RESTRICTED soft restricted depends on the permission declaration. Whitelisting a hard restricted permission allows for the to hold that permission and whitelisting a soft restricted permission allows the app to hold the permission in its full, unrestricted form.

<ol>There are four whitelists:

<li>one for cases where the system permission policy whitelists a permission This list corresponds to the #FLAG_PERMISSION_WHITELIST_SYSTEM flag. Can only be modified by pre-installed holders of a dedicated permission.

<li>one for cases where the system whitelists the permission when upgrading from an OS version in which the permission was not restricted to an OS version in which the permission is restricted. This list corresponds to the #FLAG_PERMISSION_WHITELIST_UPGRADE flag. Can be modified by pre-installed holders of a dedicated permission. The installer on record can only remove permissions from this whitelist.

<li>one for cases where the installer of the package whitelists a permission. This list corresponds to the #FLAG_PERMISSION_WHITELIST_INSTALLER flag. Can be modified by pre-installed holders of a dedicated permission or the installer on record. </ol>

You need to specify the whitelists for which to set the whitelisted permissions which will clear the previous whitelisted permissions and replace them with the provided ones.

<strong>Note: </strong>In retrospect it would have been preferred to use more inclusive terminology when naming this API. Similar APIs added will refrain from using the term "whitelist".

Java documentation for android.content.pm.PackageManager.addWhitelistedRestrictedPermission(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