Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90261a0f authored by Felipe Leme's avatar Felipe Leme
Browse files

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
parent c8472887
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -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<String> 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<String> 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<String> 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 {
+3 −0
Original line number Diff line number Diff line
@@ -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);