Fix bug in policy engine

Fixes: 284310582
Test: btest android.devicepolicy.cts.DeviceManagementCoexistenceTest#multiplePoliciesSet_dpcRemoved_removesPolicies
Change-Id: Ifeba7225d41acfc3223706c23a0fd302af670f05
This commit is contained in:
Kholoud Mohamed
2023-05-30 09:53:59 +00:00
parent 20c31b7b20
commit 0ec0709b7e
3 changed files with 6 additions and 13 deletions

View File

@@ -454,8 +454,8 @@ final class DevicePolicyEngine {
onGlobalPolicyChanged(policyDefinition, enforcingAdmin);
}
applyGlobalPolicyOnUsersWithLocalPoliciesLocked(
policyDefinition, enforcingAdmin, /* value= */ null, /* enforcePolicy= */ true);
applyGlobalPolicyOnUsersWithLocalPoliciesLocked(policyDefinition, enforcingAdmin,
/* value= */ null, /* skipEnforcePolicy= */ false);
sendPolicyResultToAdmin(
enforcingAdmin,

View File

@@ -14907,8 +14907,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
policy = new LockTaskPolicy(currentPolicy);
policy.setPackages(Set.of(packages));
}
if (policy.getPackages().isEmpty()
&& policy.getFlags() == DevicePolicyManager.LOCK_TASK_FEATURE_NONE) {
if (policy.getPackages().isEmpty()) {
mDevicePolicyEngine.removeLocalPolicy(
PolicyDefinition.LOCK_TASK,
enforcingAdmin,
@@ -20690,7 +20689,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
private void addUserControlDisabledPackages(CallerIdentity caller,
EnforcingAdmin enforcingAdmin, Set<String> packages) {
if (isCallerDeviceOwner(caller)) {
if (isDeviceOwner(caller)) {
mDevicePolicyEngine.setGlobalPolicy(
PolicyDefinition.USER_CONTROLLED_DISABLED_PACKAGES,
enforcingAdmin,
@@ -20706,7 +20705,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
private void removeUserControlDisabledPackages(CallerIdentity caller,
EnforcingAdmin enforcingAdmin) {
if (isCallerDeviceOwner(caller)) {
if (isDeviceOwner(caller)) {
mDevicePolicyEngine.removeGlobalPolicy(
PolicyDefinition.USER_CONTROLLED_DISABLED_PACKAGES,
enforcingAdmin);
@@ -20718,12 +20717,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
}
private boolean isCallerDeviceOwner(CallerIdentity caller) {
synchronized (getLockObject()) {
return getDeviceOwnerUserIdUncheckedLocked() == caller.getUserId();
}
}
@Override
public List<String> getUserControlDisabledPackages(ComponentName who,
String callerPackageName) {

View File

@@ -167,7 +167,7 @@ final class PolicyEnforcerCallbacks {
packages == null ? null : packages.stream().toList());
LocalServices.getService(UsageStatsManagerInternal.class)
.setAdminProtectedPackages(
packages == null ? null : new ArraySet(packages), userId);
packages == null ? null : new ArraySet<>(packages), userId);
});
return true;
}