From 90261a0f41c5ba79b64bdc06775b2e793749cf91 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 6 Apr 2021 12:35:55 -0700 Subject: [PATCH] Integrated policy-exempt-apps into setLockTaskPackages(). Test: atest FrameworksServicesTests:DevicePolicyManagerTest Test: manual verification using TestDPC (cannot test using CTS because it require launching an activity provided by the OEM, which the test has no control over). Bug: 181238156 Change-Id: I5c2bfed3b1dcd66cb94461cb5695868b6090219a --- .../DevicePolicyManagerService.java | 31 +++++++++++++++++-- .../devicepolicy/DevicePolicyManagerTest.java | 3 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 807edca939d7b..aee6fdd10edd1 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -333,6 +333,7 @@ import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.storage.DeviceStorageMonitorInternal; import com.android.server.uri.NeededUriGrants; import com.android.server.uri.UriGrantsManagerInternal; +import com.android.server.utils.Slogf; import com.android.server.wm.ActivityTaskManagerInternal; import com.google.android.collect.Sets; @@ -2839,10 +2840,36 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } private void updateLockTaskPackagesLocked(List packages, int userId) { + String[] packagesArray = null; + + if (!packages.isEmpty()) { + // When adding packages, we need to include the exempt apps so they can still be + // launched (ideally we should use a different AM API as these apps don't need to use + // lock-task mode). + // They're not added when the packages is empty though, as in that case we're disabling + // lock-task mode. + List exemptApps = listPolicyExemptAppsUnchecked(); + if (!exemptApps.isEmpty()) { + // TODO(b/175377361): add unit test to verify it (cannot be CTS because the policy- + // -exempt apps are provided by OEM and the test would have no control over it) once + // tests are migrated to the new infra-structure + HashSet updatedPackages = new HashSet<>(packages); + updatedPackages.addAll(exemptApps); + if (VERBOSE_LOG) { + Slogf.v(LOG_TAG, "added %d policy-exempt apps to %d lock task packages. Final " + + "list: %s", exemptApps.size(), packages.size(), updatedPackages); + } + packagesArray = updatedPackages.toArray(new String[updatedPackages.size()]); + } + } + + if (packagesArray == null) { + packagesArray = packages.toArray(new String[packages.size()]); + } + long ident = mInjector.binderClearCallingIdentity(); try { - mInjector.getIActivityManager() - .updateLockTaskPackages(userId, packages.toArray(new String[packages.size()])); + mInjector.getIActivityManager().updateLockTaskPackages(userId, packagesArray); } catch (RemoteException e) { // Not gonna happen. } finally { diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index cc206a1353b88..2fbbfdc4ae361 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -4537,6 +4537,9 @@ public class DevicePolicyManagerTest extends DpmTestBase { @Test public void testLockTaskPolicyForProfileOwner() throws Exception { + mockPolicyExemptApps(); + mockVendorPolicyExemptApps(); + // Setup a PO mContext.binder.callingUid = DpmMockContext.CALLER_UID; setAsProfileOwner(admin1);