diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt | 2 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/AppRestrictionController.java | 49 |
2 files changed, 47 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt index 3eb4b10151d9..3e8cdf3a3592 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt @@ -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, diff --git a/services/core/java/com/android/server/am/AppRestrictionController.java b/services/core/java/com/android/server/am/AppRestrictionController.java index f7abb117e3de..6f5d87bab15f 100644 --- a/services/core/java/com/android/server/am/AppRestrictionController.java +++ b/services/core/java/com/android/server/am/AppRestrictionController.java @@ -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; } |