Merge "Cache permission policy" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e51a931cd2
@@ -50,6 +50,12 @@ public abstract class DevicePolicyCache {
|
|||||||
*/
|
*/
|
||||||
public abstract int getPasswordQuality(@UserIdInt int userHandle);
|
public abstract int getPasswordQuality(@UserIdInt int userHandle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches {@link DevicePolicyManager#getPermissionPolicy(android.content.ComponentName)} of
|
||||||
|
* the given user.
|
||||||
|
*/
|
||||||
|
public abstract int getPermissionPolicy(@UserIdInt int userHandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty implementation.
|
* Empty implementation.
|
||||||
*/
|
*/
|
||||||
@@ -66,5 +72,10 @@ public abstract class DevicePolicyCache {
|
|||||||
public int getPasswordQuality(int userHandle) {
|
public int getPasswordQuality(int userHandle) {
|
||||||
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPermissionPolicy(int userHandle) {
|
||||||
|
return DevicePolicyManager.PERMISSION_POLICY_PROMPT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,14 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private final SparseIntArray mPasswordQuality = new SparseIntArray();
|
private final SparseIntArray mPasswordQuality = new SparseIntArray();
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
private final SparseIntArray mPermissionPolicy = new SparseIntArray();
|
||||||
|
|
||||||
public void onUserRemoved(int userHandle) {
|
public void onUserRemoved(int userHandle) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mScreenCaptureDisabled.delete(userHandle);
|
mScreenCaptureDisabled.delete(userHandle);
|
||||||
mPasswordQuality.delete(userHandle);
|
mPasswordQuality.delete(userHandle);
|
||||||
|
mPermissionPolicy.delete(userHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +82,28 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPermissionPolicy(@UserIdInt int userHandle) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
return mPermissionPolicy.get(userHandle,
|
||||||
|
DevicePolicyManager.PERMISSION_POLICY_PROMPT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Update the permission policy for the given user. */
|
||||||
|
public void setPermissionPolicy(@UserIdInt int userHandle, int policy) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
mPermissionPolicy.put(userHandle, policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Dump content */
|
/** Dump content */
|
||||||
public void dump(IndentingPrintWriter pw) {
|
public void dump(IndentingPrintWriter pw) {
|
||||||
pw.println("Device policy cache:");
|
pw.println("Device policy cache:");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
pw.println("Screen capture disabled: " + mScreenCaptureDisabled.toString());
|
pw.println("Screen capture disabled: " + mScreenCaptureDisabled.toString());
|
||||||
pw.println("Password quality: " + mPasswordQuality.toString());
|
pw.println("Password quality: " + mPasswordQuality.toString());
|
||||||
|
pw.println("Permission policy: " + mPermissionPolicy.toString());
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2935,6 +2935,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
// reading the value during user switch, due to onStartUser() being asynchronous.
|
// reading the value during user switch, due to onStartUser() being asynchronous.
|
||||||
updatePasswordQualityCacheForUserGroup(
|
updatePasswordQualityCacheForUserGroup(
|
||||||
userId == UserHandle.USER_SYSTEM ? UserHandle.USER_ALL : userId);
|
userId == UserHandle.USER_SYSTEM ? UserHandle.USER_ALL : userId);
|
||||||
|
updatePermissionPolicyCache(userId);
|
||||||
|
|
||||||
startOwnerService(userId, "start-user");
|
startOwnerService(userId, "start-user");
|
||||||
}
|
}
|
||||||
@@ -12461,11 +12462,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
|| (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_PERMISSION_GRANT)));
|
|| (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_PERMISSION_GRANT)));
|
||||||
checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_SET_PERMISSION_POLICY);
|
checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_SET_PERMISSION_POLICY);
|
||||||
|
|
||||||
|
final int forUser = caller.getUserId();
|
||||||
synchronized (getLockObject()) {
|
synchronized (getLockObject()) {
|
||||||
DevicePolicyData userPolicy = getUserData(caller.getUserId());
|
DevicePolicyData userPolicy = getUserData(forUser);
|
||||||
if (userPolicy.mPermissionPolicy != policy) {
|
if (userPolicy.mPermissionPolicy != policy) {
|
||||||
userPolicy.mPermissionPolicy = policy;
|
userPolicy.mPermissionPolicy = policy;
|
||||||
saveSettingsLocked(caller.getUserId());
|
mPolicyCache.setPermissionPolicy(forUser, policy);
|
||||||
|
saveSettingsLocked(forUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DevicePolicyEventLogger
|
DevicePolicyEventLogger
|
||||||
@@ -12476,13 +12479,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
.write();
|
.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updatePermissionPolicyCache(int userId) {
|
||||||
|
synchronized (getLockObject()) {
|
||||||
|
DevicePolicyData userPolicy = getUserData(userId);
|
||||||
|
mPolicyCache.setPermissionPolicy(userId, userPolicy.mPermissionPolicy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPermissionPolicy(ComponentName admin) throws RemoteException {
|
public int getPermissionPolicy(ComponentName admin) throws RemoteException {
|
||||||
int userId = UserHandle.getCallingUserId();
|
int userId = UserHandle.getCallingUserId();
|
||||||
synchronized (getLockObject()) {
|
return mPolicyCache.getPermissionPolicy(userId);
|
||||||
DevicePolicyData userPolicy = getUserData(userId);
|
|
||||||
return userPolicy.mPermissionPolicy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user