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

Commit 3c597e7c authored by Jing Ji's avatar Jing Ji Committed by Automerger Merge Worker
Browse files

Merge "Show the stop button in the task manager for user allowlisted apps"...

Merge "Show the stop button in the task manager for user allowlisted apps" into tm-dev am: f8ef8474 am: 52567816 am: 7f284afe

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18161503



Change-Id: I3c4c0fc8cba3b3e38b80e69a26775f0c05610826
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e97cfb8e 7f284afe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -420,7 +420,7 @@ class FgsManagerController @Inject constructor(
                PowerExemptionManager.REASON_SYSTEM_UID,
                PowerExemptionManager.REASON_DEVICE_DEMO_MODE -> UIControl.HIDE_ENTRY

                PowerExemptionManager.REASON_ALLOWLISTED_PACKAGE,
                PowerExemptionManager.REASON_SYSTEM_ALLOW_LISTED,
                PowerExemptionManager.REASON_DEVICE_OWNER,
                PowerExemptionManager.REASON_DISALLOW_APPS_CONTROL,
                PowerExemptionManager.REASON_DPO_PROTECTED_APP,
+46 −3
Original line number Diff line number Diff line
@@ -265,6 +265,20 @@ public final class AppRestrictionController {
     */
    private int[] mDeviceIdleExceptIdleAllowlist = new int[0]; // No lock is needed.

    /**
     * The pre-configured system app-ids in the power-save allow list.
     *
     * @see #mDeviceIdleAllowlist.
     */
    private final ArraySet<Integer> mSystemDeviceIdleAllowlist = new ArraySet<>();

    /**
     * The pre-configured system app-ids in the power-save allow list, except-idle.
     *
     * @see #mDeviceIdleExceptIdleAllowlist.
     */
    private final ArraySet<Integer> mSystemDeviceIdleExceptIdleAllowlist = new ArraySet<>();

    private final Object mLock = new Object();
    private final Object mSettingsLock = new Object();
    private final Injector mInjector;
@@ -1511,14 +1525,33 @@ public final class AppRestrictionController {
    }

    private void initBgRestrictionExemptioFromSysConfig() {
        mBgRestrictionExemptioFromSysConfig =
                SystemConfig.getInstance().getBgRestrictionExemption();
        final SystemConfig sysConfig = SystemConfig.getInstance();
        mBgRestrictionExemptioFromSysConfig = sysConfig.getBgRestrictionExemption();
        if (DEBUG_BG_RESTRICTION_CONTROLLER) {
            final ArraySet<String> exemptedPkgs = mBgRestrictionExemptioFromSysConfig;
            for (int i = exemptedPkgs.size() - 1; i >= 0; i--) {
                Slog.i(TAG, "bg-restriction-exemption: " + exemptedPkgs.valueAt(i));
            }
        }
        loadAppIdsFromPackageList(sysConfig.getAllowInPowerSaveExceptIdle(),
                mSystemDeviceIdleExceptIdleAllowlist);
        loadAppIdsFromPackageList(sysConfig.getAllowInPowerSave(), mSystemDeviceIdleAllowlist);
    }

    private void loadAppIdsFromPackageList(ArraySet<String> packages, ArraySet<Integer> apps) {
        final PackageManager pm = mInjector.getPackageManager();
        for (int i = packages.size() - 1; i >= 0; i--) {
            final String pkg = packages.valueAt(i);
            try {
                final ApplicationInfo ai = pm.getApplicationInfo(pkg,
                        PackageManager.MATCH_SYSTEM_ONLY);
                if (ai == null) {
                    continue;
                }
                apps.add(UserHandle.getAppId(ai.uid));
            } catch (PackageManager.NameNotFoundException e) {
            }
        }
    }

    private boolean isExemptedFromSysConfig(String packageName) {
@@ -2685,6 +2718,13 @@ public final class AppRestrictionController {
                || Arrays.binarySearch(mDeviceIdleExceptIdleAllowlist, appId) >= 0;
    }

    boolean isOnSystemDeviceIdleAllowlist(int uid) {
        final int appId = UserHandle.getAppId(uid);

        return mSystemDeviceIdleAllowlist.contains(appId)
                || mSystemDeviceIdleExceptIdleAllowlist.contains(appId);
    }

    void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids) {
        mDeviceIdleAllowlist = allAppids;
        mDeviceIdleExceptIdleAllowlist = exceptIdleAppids;
@@ -2703,6 +2743,9 @@ public final class AppRestrictionController {
        if (UserHandle.isCore(uid)) {
            return REASON_SYSTEM_UID;
        }
        if (isOnSystemDeviceIdleAllowlist(uid)) {
            return REASON_SYSTEM_ALLOW_LISTED;
        }
        if (isOnDeviceIdleAllowlist(uid)) {
            return REASON_ALLOWLISTED_PACKAGE;
        }
@@ -2748,7 +2791,7 @@ public final class AppRestrictionController {
                } else if (isExemptedFromSysConfig(pkg)) {
                    return REASON_SYSTEM_ALLOW_LISTED;
                } else if (mConstantsObserver.mBgRestrictionExemptedPackages.contains(pkg)) {
                    return REASON_ALLOWLISTED_PACKAGE;
                    return REASON_SYSTEM_ALLOW_LISTED;
                } else if (pm.isPackageStateProtected(pkg, userId)) {
                    return REASON_DPO_PROTECTED_APP;
                }