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

Commit be4fc95e authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Preserve unsuspend behavior

When admin unsuspends packages, pass the whole set to PackageManager,
not just those that the admin previously suspended. This preserves
behavior in case of nonexistent packages.

Bug: 378766314
Flag: android.app.admin.flags.unsuspend_not_suspended
Test: atest CtsDevicePolicyTestCases:android.devicepolicy.cts.PackageSuspensionTest#setPackagesSuspended_unsuspendNonexistentPackage_remainUnuspended[IncludeRunOnProfileOwnerPrimaryUser]
Change-Id: Ibebd47d34f9f56e61cc2d11fd92ebcd3494deab6
parent f53f7712
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -285,6 +285,16 @@ flag {
    }
}

flag {
    name: "unsuspend_not_suspended"
    namespace: "enterprise"
    description: "When admin unsuspends packages, pass previously not suspended packages to PM too"
    bug: "378766314"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "backup_connected_apps_settings"
    namespace: "enterprise"
+10 −9
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.devicepolicy;
import static com.android.server.devicepolicy.DevicePolicyManagerService.LOG_TAG;

import android.annotation.Nullable;
import android.app.admin.flags.Flags;
import android.content.pm.PackageManagerInternal;
import android.util.ArraySet;

@@ -64,7 +65,7 @@ public class PackageSuspender {
    /**
     * Suspend packages that are requested by a single admin
     *
     * @return a list of packages that the admin has requested to suspend but could not be
     * @return an array of packages that the admin has requested to suspend but could not be
     * suspended, due to DPM and PackageManager exemption list.
     *
     */
@@ -87,7 +88,7 @@ public class PackageSuspender {
    /**
     * Suspend packages considering the exemption list.
     *
     * @return the list of packages that couldn't be suspended, either due to the exemption list,
     * @return the set of packages that couldn't be suspended, either due to the exemption list,
     * or due to failures from PackageManagerInternal itself.
     */
    private Set<String> suspendWithExemption(Set<String> packages) {
@@ -112,15 +113,15 @@ public class PackageSuspender {
    /**
     * Unsuspend packages that are requested by a single admin
     *
     * @return a list of packages that the admin has requested to unsuspend but could not be
     * unsuspended, due to other amdin's policy or PackageManager restriction.
     * @return an array of packages that the admin has requested to unsuspend but could not be
     * unsuspended, due to other admin's policy or PackageManager restriction.
     *
     */
    public String[] unsuspend(Set<String> packages) {
        // Unlike suspend(), when unsuspending, call PackageManager with the delta of resolved
        // suspended packages list and not what the admin has requested. This is because some
        // packages might still be subject to another admin's suspension request.
        Set<String> packagesToUnsuspend = new ArraySet<>(mSuspendedPackageBefore);
        // Unlike suspend(), when unsuspending, take suspension by other admins into account: only
        // packages not suspended by other admins are passed to PackageManager.
        Set<String> packagesToUnsuspend = new ArraySet<>(
                Flags.unsuspendNotSuspended() ? packages : mSuspendedPackageBefore);
        packagesToUnsuspend.removeAll(mSuspendedPackageAfter);

        // To calculate the result (which packages are not unsuspended), start with packages that
@@ -139,7 +140,7 @@ public class PackageSuspender {
    /**
     * Unsuspend packages considering the exemption list.
     *
     * @return the list of packages that couldn't be unsuspended, either due to the exemption list,
     * @return the set of packages that couldn't be unsuspended, either due to the exemption list,
     * or due to failures from PackageManagerInternal itself.
     */
    private Set<String> unsuspendWithExemption(Set<String> packages) {