public final class PermissionsState extends Object
There are two types of permissions: install (granted at installation) and runtime (granted at runtime). Install permissions are granted to all device users while runtime permissions are granted explicitly to specific users.
The permissions are kept on a per device user basis. For example, an application may have some runtime permissions granted under the device owner but not granted under the secondary user.
This class is also responsible for keeping track of the Linux gids per user for a package or a shared user. The gids are computed as a set of the gids for all granted permissions' gids on a per user basis.
Modifier and Type | Class and Description |
---|---|
static class |
PermissionsState.PermissionState |
Modifier and Type | Field and Description |
---|---|
static int |
PERMISSION_OPERATION_FAILURE
The permission operation failed.
|
static int |
PERMISSION_OPERATION_SUCCESS
The permission operation succeeded and no gids changed.
|
static int |
PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
The permission operation succeeded and gids changed.
|
Constructor and Description |
---|
PermissionsState() |
PermissionsState(PermissionsState prototype) |
Modifier and Type | Method and Description |
---|---|
int[] |
computeGids(int userId)
Compute the Linux gids for a given device user from the permissions
granted to this user.
|
int[] |
computeGids(int[] userIds)
Compute the Linux gids for all device users from the permissions
granted to these users.
|
void |
copyFrom(PermissionsState other)
Initialized this instance from another one.
|
PermissionsState.PermissionState |
getInstallPermissionState(String name)
Gets the state for an install permission or null if no such.
|
List<PermissionsState.PermissionState> |
getInstallPermissionStates()
Gets all install permission states.
|
int |
getPermissionFlags(String name,
int userId)
Gets the flags for a permission regardless if it is install or
runtime permission.
|
Set<String> |
getPermissions(int userId)
Gets all permissions for a given device user id regardless if they
are install time or runtime permissions.
|
PermissionsState.PermissionState |
getRuntimePermissionState(String name,
int userId)
Gets the state for a runtime permission or null if no such.
|
List<PermissionsState.PermissionState> |
getRuntimePermissionStates(int userId)
Gets all runtime permission states.
|
int |
grantInstallPermission(com.android.server.pm.BasePermission permission)
Grant an install permission.
|
int |
grantRuntimePermission(com.android.server.pm.BasePermission permission,
int userId)
Grant a runtime permission for a given device user.
|
boolean |
hasInstallPermission(String name)
Gets whether this state has a given install permission.
|
boolean |
hasPermission(String name,
int userId)
Gets whether the state has a given permission for the specified
user, regardless if this is an install or a runtime permission.
|
boolean |
hasRequestedPermission(ArraySet<String> names)
Returns whether the state has any known request for the given permission name,
whether or not it has been granted.
|
boolean |
hasRuntimePermission(String name,
int userId)
Gets whether this state has a given runtime permission for a
given device user id.
|
boolean |
isPermissionReviewRequired(int userId) |
void |
reset()
Resets the internal state of this object.
|
int |
revokeInstallPermission(com.android.server.pm.BasePermission permission)
Revoke an install permission.
|
int |
revokeRuntimePermission(com.android.server.pm.BasePermission permission,
int userId)
Revoke a runtime permission for a given device user.
|
void |
setGlobalGids(int[] globalGids)
Sets the global gids, applicable to all users.
|
boolean |
updatePermissionFlags(com.android.server.pm.BasePermission permission,
int userId,
int flagMask,
int flagValues)
Update the flags associated with a given permission.
|
boolean |
updatePermissionFlagsForAllPermissions(int userId,
int flagMask,
int flagValues) |
public static final int PERMISSION_OPERATION_FAILURE
public static final int PERMISSION_OPERATION_SUCCESS
public static final int PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
public PermissionsState()
public PermissionsState(PermissionsState prototype)
public void setGlobalGids(int[] globalGids)
globalGids
- The global gids.public void copyFrom(PermissionsState other)
other
- The other instance.public boolean isPermissionReviewRequired(int userId)
public int grantInstallPermission(com.android.server.pm.BasePermission permission)
permission
- The permission to grant.PERMISSION_OPERATION_SUCCESS
,
or PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
, or PERMISSION_OPERATION_FAILURE
.public int revokeInstallPermission(com.android.server.pm.BasePermission permission)
permission
- The permission to revoke.PERMISSION_OPERATION_SUCCESS
,
or PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
, or PERMISSION_OPERATION_FAILURE
.public int grantRuntimePermission(com.android.server.pm.BasePermission permission, int userId)
permission
- The permission to grant.userId
- The device user id.PERMISSION_OPERATION_SUCCESS
,
or PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
, or PERMISSION_OPERATION_FAILURE
.public int revokeRuntimePermission(com.android.server.pm.BasePermission permission, int userId)
permission
- The permission to revoke.userId
- The device user id.PERMISSION_OPERATION_SUCCESS
,
or PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
, or PERMISSION_OPERATION_FAILURE
.public boolean hasRuntimePermission(String name, int userId)
name
- The permission name.userId
- The device user id.public boolean hasInstallPermission(String name)
name
- The permission name.public boolean hasPermission(String name, int userId)
name
- The permission name.userId
- The device user id.public boolean hasRequestedPermission(ArraySet<String> names)
public Set<String> getPermissions(int userId)
userId
- The device user id.public PermissionsState.PermissionState getInstallPermissionState(String name)
name
- The permission name.public PermissionsState.PermissionState getRuntimePermissionState(String name, int userId)
name
- The permission name.userId
- The device user id.public List<PermissionsState.PermissionState> getInstallPermissionStates()
public List<PermissionsState.PermissionState> getRuntimePermissionStates(int userId)
public int getPermissionFlags(String name, int userId)
name
- The permission name.public boolean updatePermissionFlags(com.android.server.pm.BasePermission permission, int userId, int flagMask, int flagValues)
permission
- The permission whose flags to update.userId
- The user for which to update.flagMask
- Mask for which flags to change.flagValues
- New values for the mask flags.public boolean updatePermissionFlagsForAllPermissions(int userId, int flagMask, int flagValues)
public int[] computeGids(int userId)
userId
- The device user id.public int[] computeGids(int[] userIds)
public void reset()