From c7fc36a82cfb8aec101e57b832472596674fd856 Mon Sep 17 00:00:00 2001 From: Kholoud Mohamed Date: Fri, 21 Apr 2023 12:23:18 +0000 Subject: [PATCH] Fix lock task clearing for affiliated users Fixes: 278141432 Test: com.android.cts.devicepolicy.DeviceOwnerTest#testSetUserControlDisabledPackages_singleUser_reboot_verifyPackageNotStopped Change-Id: I19c64a39cdee4395c7eabf9f3da3f0c53a691d90 --- .../DevicePolicyManagerService.java | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index e79796d366e08..6ca35d0d2c797 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -14957,18 +14957,34 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { continue; } - final List lockTaskPackages = getUserData(userId).mLockTaskPackages; - // TODO(b/278438525): handle in the policy engine - if (!lockTaskPackages.isEmpty()) { - Slogf.d(LOG_TAG, - "User id " + userId + " not affiliated. Clearing lock task packages"); - setLockTaskPackagesLocked(userId, Collections.emptyList()); - } - final int lockTaskFeatures = getUserData(userId).mLockTaskFeatures; - if (lockTaskFeatures != DevicePolicyManager.LOCK_TASK_FEATURE_NONE){ - Slogf.d(LOG_TAG, - "User id " + userId + " not affiliated. Clearing lock task features"); - setLockTaskFeaturesLocked(userId, DevicePolicyManager.LOCK_TASK_FEATURE_NONE); + if (isPolicyEngineForFinanceFlagEnabled()) { + Map> policies = + mDevicePolicyEngine.getLocalPoliciesSetByAdmins( + PolicyDefinition.LOCK_TASK, userId); + Set admins = new HashSet<>(policies.keySet()); + for (EnforcingAdmin admin : admins) { + if (admin.hasAuthority(EnforcingAdmin.DPC_AUTHORITY)) { + mDevicePolicyEngine.removeLocalPolicy( + PolicyDefinition.LOCK_TASK, admin, userId); + } + } + } else { + final List lockTaskPackages = getUserData(userId).mLockTaskPackages; + // TODO(b/278438525): handle in the policy engine + if (!lockTaskPackages.isEmpty()) { + Slogf.d(LOG_TAG, + "User id " + userId + + " not affiliated. Clearing lock task packages"); + setLockTaskPackagesLocked(userId, Collections.emptyList()); + } + final int lockTaskFeatures = getUserData(userId).mLockTaskFeatures; + if (lockTaskFeatures != DevicePolicyManager.LOCK_TASK_FEATURE_NONE) { + Slogf.d(LOG_TAG, + "User id " + userId + + " not affiliated. Clearing lock task features"); + setLockTaskFeaturesLocked(userId, + DevicePolicyManager.LOCK_TASK_FEATURE_NONE); + } } } });