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

Commit b4083e03 authored by Pavel Grafov's avatar Pavel Grafov Committed by Android (Google) Code Review
Browse files

Merge "Enforce DevicePolicyManager.setUserControlDisabledPackages in...

Merge "Enforce DevicePolicyManager.setUserControlDisabledPackages in AppStandbyController" into rvc-dev
parents 9fa25877 552dbbc1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -146,6 +146,8 @@ public interface AppStandbyInternal {

    void setActiveAdminApps(Set<String> adminPkgs, int userId);

    void setAdminProtectedPackages(Set<String> packageNames, int userId);

    void onAdminDataAvailable();

    void clearCarrierPrivilegedApps();
+40 −0
Original line number Diff line number Diff line
@@ -233,6 +233,10 @@ public class AppStandbyController implements AppStandbyInternal {
    @GuardedBy("mActiveAdminApps")
    private final SparseArray<Set<String>> mActiveAdminApps = new SparseArray<>();

    /** List of admin protected packages. Can contain {@link android.os.UserHandle#USER_ALL}. */
    @GuardedBy("mAdminProtectedPackages")
    private final SparseArray<Set<String>> mAdminProtectedPackages = new SparseArray<>();

    /**
     * Set of system apps that are headless (don't have any declared activities, enabled or
     * disabled). Presence in this map indicates that the app is a headless system app.
@@ -1020,6 +1024,9 @@ public class AppStandbyController implements AppStandbyInternal {
            synchronized (mActiveAdminApps) {
                mActiveAdminApps.remove(userId);
            }
            synchronized (mAdminProtectedPackages) {
                mAdminProtectedPackages.remove(userId);
            }
        }
    }

@@ -1109,6 +1116,10 @@ public class AppStandbyController implements AppStandbyInternal {
                return STANDBY_BUCKET_EXEMPTED;
            }

            if (isAdminProtectedPackages(packageName, userId)) {
                return STANDBY_BUCKET_EXEMPTED;
            }

            if (isActiveNetworkScorer(packageName)) {
                return STANDBY_BUCKET_EXEMPTED;
            }
@@ -1507,6 +1518,17 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    private boolean isAdminProtectedPackages(String packageName, int userId) {
        synchronized (mAdminProtectedPackages) {
            if (mAdminProtectedPackages.contains(UserHandle.USER_ALL)
                    && mAdminProtectedPackages.get(UserHandle.USER_ALL).contains(packageName)) {
                return true;
            }
            return mAdminProtectedPackages.contains(userId)
                    && mAdminProtectedPackages.get(userId).contains(packageName);
        }
    }

    @Override
    public void addActiveDeviceAdmin(String adminPkg, int userId) {
        synchronized (mActiveAdminApps) {
@@ -1530,6 +1552,17 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    @Override
    public void setAdminProtectedPackages(Set<String> packageNames, int userId) {
        synchronized (mAdminProtectedPackages) {
            if (packageNames == null || packageNames.isEmpty()) {
                mAdminProtectedPackages.remove(userId);
            } else {
                mAdminProtectedPackages.put(userId, packageNames);
            }
        }
    }

    @Override
    public void onAdminDataAvailable() {
        mAdminDataAvailableLatch.countDown();
@@ -1552,6 +1585,13 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    @VisibleForTesting
    Set<String> getAdminProtectedPackagesForTest(int userId) {
        synchronized (mAdminProtectedPackages) {
            return mAdminProtectedPackages.get(userId);
        }
    }

    /**
     * Returns {@code true} if the supplied package is the device provisioning app. Otherwise,
     * returns {@code false}.
+2 −1
Original line number Diff line number Diff line
@@ -11990,7 +11990,8 @@ public class DevicePolicyManager {
    /**
     * Called by Device owner to disable user control over apps. User will not be able to clear
     * app data or force-stop packages.
     * app data or force-stop packages. Packages with user control disabled are exempted from
     * App Standby Buckets.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with
     * @param packages The package names for the apps.
+10 −0
Original line number Diff line number Diff line
@@ -198,6 +198,16 @@ public abstract class UsageStatsManagerInternal {
     */
    public abstract void setActiveAdminApps(Set<String> adminApps, int userId);

    /**
     * Called by DevicePolicyManagerService to inform about the protected packages for a user.
     * User control will be disabled for protected packages.
     *
     * @param packageNames the set of protected packages for {@code userId}.
     * @param userId the userId to which the protected packages belong.
     */
    public abstract void setAdminProtectedPackages(@Nullable Set<String> packageNames,
            @UserIdInt int userId);

    /**
     * Called by DevicePolicyManagerService during boot to inform that admin data is loaded and
     * pushed to UsageStatsService.
+5 −1
Original line number Diff line number Diff line
@@ -4013,7 +4013,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        updateMaximumTimeToLockLocked(userHandle);
        updateLockTaskPackagesLocked(policy.mLockTaskPackages, userHandle);
        updateLockTaskFeaturesLocked(policy.mLockTaskFeatures, userHandle);
        if (userHandle == UserHandle.USER_SYSTEM) {
            updateUserControlDisabledPackagesLocked(policy.mUserControlDisabledPackages);
        }
        if (policy.mStatusBarDisabled) {
            setStatusBarDisabledInternal(policy.mStatusBarDisabled, userHandle);
        }
@@ -4041,6 +4043,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private void updateUserControlDisabledPackagesLocked(List<String> packages) {
        mInjector.getPackageManagerInternal().setDeviceOwnerProtectedPackages(packages);
        mUsageStatsManagerInternal.setAdminProtectedPackages(
                new ArraySet(packages), UserHandle.USER_ALL);
    }
    private void updateLockTaskFeaturesLocked(int flags, int userId) {
Loading