Loading core/java/com/android/server/SystemConfig.java +22 −0 Original line number Diff line number Diff line Loading @@ -237,6 +237,10 @@ public class SystemConfig { // be delivered anonymously even to apps which target O+. final ArraySet<String> mAllowImplicitBroadcasts = new ArraySet<>(); // These are the packages that are exempted from the background restriction applied // by the system automatically, i.e., due to high background current drain. final ArraySet<String> mBgRestrictionExemption = new ArraySet<>(); // These are the package names of apps which should be automatically granted domain verification // for all of their domains. The only way these apps can be overridden by the user is by // explicitly disabling overall link handling support in app info. Loading Loading @@ -389,6 +393,10 @@ public class SystemConfig { return mAllowIgnoreLocationSettings; } public ArraySet<String> getBgRestrictionExemption() { return mBgRestrictionExemption; } public ArraySet<String> getLinkedApps() { return mLinkedApps; } Loading Loading @@ -1049,6 +1057,20 @@ public class SystemConfig { } XmlUtils.skipCurrentTag(parser); } break; case "bg-restriction-exemption": { if (allowOverrideAppRestrictions) { String pkgname = parser.getAttributeValue(null, "package"); if (pkgname == null) { Slog.w(TAG, "<" + name + "> without package in " + permFile + " at " + parser.getPositionDescription()); } else { mBgRestrictionExemption.add(pkgname); } } else { logNotAllowedInPartition(name, permFile, parser); } XmlUtils.skipCurrentTag(parser); } break; case "default-enabled-vr-app": { if (allowAppConfigs) { String pkgname = parser.getAttributeValue(null, "package"); Loading services/core/java/com/android/server/am/AppRestrictionController.java +30 −7 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import static android.os.PowerExemptionManager.REASON_PROC_STATE_PERSISTENT_UI; import static android.os.PowerExemptionManager.REASON_PROFILE_OWNER; import static android.os.PowerExemptionManager.REASON_ROLE_DIALER; import static android.os.PowerExemptionManager.REASON_ROLE_EMERGENCY; import static android.os.PowerExemptionManager.REASON_SYSTEM_ALLOW_LISTED; import static android.os.PowerExemptionManager.REASON_SYSTEM_MODULE; import static android.os.PowerExemptionManager.REASON_SYSTEM_UID; import static android.os.Process.SYSTEM_UID; Loading Loading @@ -140,6 +141,7 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.util.function.TriConsumer; import com.android.server.AppStateTracker; import com.android.server.LocalServices; import com.android.server.SystemConfig; import com.android.server.apphibernation.AppHibernationManagerInternal; import com.android.server.pm.UserManagerInternal; import com.android.server.usage.AppStandbyInternal; Loading Loading @@ -231,6 +233,11 @@ public final class AppRestrictionController { @GuardedBy("mLock") private final HashMap<String, Boolean> mSystemModulesCache = new HashMap<>(); /** * The pre-config packages that are exempted from the background restrictions. */ private ArraySet<String> mBgRestrictionExemptioFromSysConfig; /** * Lock specifically for bookkeeping around the carrier-privileged app set. * Do not acquire any other locks while holding this one. Methods that Loading Loading @@ -705,6 +712,7 @@ public final class AppRestrictionController { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, ActivityThread.currentApplication().getMainExecutor(), mConstantsObserver); mConstantsObserver.start(); initBgRestrictionExemptioFromSysConfig(); initRestrictionStates(); initSystemModuleNames(); registerForUidObservers(); Loading @@ -726,6 +734,22 @@ public final class AppRestrictionController { initRestrictionStates(); } private void initBgRestrictionExemptioFromSysConfig() { mBgRestrictionExemptioFromSysConfig = SystemConfig.getInstance().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)); } } } private boolean isExemptedFromSysConfig(String packageName) { return mBgRestrictionExemptioFromSysConfig != null && mBgRestrictionExemptioFromSysConfig.contains(packageName); } private void initRestrictionStates() { final int[] allUsers = mInjector.getUserManagerInternal().getUserIds(); for (int userId : allUsers) { Loading Loading @@ -1557,14 +1581,11 @@ public final class AppRestrictionController { } } boolean isOnDeviceIdleAllowlist(int uid, boolean allowExceptIdle) { boolean isOnDeviceIdleAllowlist(int uid) { final int appId = UserHandle.getAppId(uid); final int[] allowlist = allowExceptIdle ? mDeviceIdleExceptIdleAllowlist : mDeviceIdleAllowlist; return Arrays.binarySearch(allowlist, appId) >= 0; return Arrays.binarySearch(mDeviceIdleAllowlist, appId) >= 0 || Arrays.binarySearch(mDeviceIdleExceptIdleAllowlist, appId) >= 0; } void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids) { Loading @@ -1585,7 +1606,7 @@ public final class AppRestrictionController { if (UserHandle.isCore(uid)) { return REASON_SYSTEM_UID; } if (isOnDeviceIdleAllowlist(uid, false)) { if (isOnDeviceIdleAllowlist(uid)) { return REASON_ALLOWLISTED_PACKAGE; } final ActivityManagerInternal am = mInjector.getActivityManagerInternal(); Loading Loading @@ -1621,6 +1642,8 @@ public final class AppRestrictionController { return REASON_SYSTEM_MODULE; } else if (isCarrierApp(pkg)) { return REASON_CARRIER_PRIVILEGED_APP; } else if (isExemptedFromSysConfig(pkg)) { return REASON_SYSTEM_ALLOW_LISTED; } } } Loading Loading
core/java/com/android/server/SystemConfig.java +22 −0 Original line number Diff line number Diff line Loading @@ -237,6 +237,10 @@ public class SystemConfig { // be delivered anonymously even to apps which target O+. final ArraySet<String> mAllowImplicitBroadcasts = new ArraySet<>(); // These are the packages that are exempted from the background restriction applied // by the system automatically, i.e., due to high background current drain. final ArraySet<String> mBgRestrictionExemption = new ArraySet<>(); // These are the package names of apps which should be automatically granted domain verification // for all of their domains. The only way these apps can be overridden by the user is by // explicitly disabling overall link handling support in app info. Loading Loading @@ -389,6 +393,10 @@ public class SystemConfig { return mAllowIgnoreLocationSettings; } public ArraySet<String> getBgRestrictionExemption() { return mBgRestrictionExemption; } public ArraySet<String> getLinkedApps() { return mLinkedApps; } Loading Loading @@ -1049,6 +1057,20 @@ public class SystemConfig { } XmlUtils.skipCurrentTag(parser); } break; case "bg-restriction-exemption": { if (allowOverrideAppRestrictions) { String pkgname = parser.getAttributeValue(null, "package"); if (pkgname == null) { Slog.w(TAG, "<" + name + "> without package in " + permFile + " at " + parser.getPositionDescription()); } else { mBgRestrictionExemption.add(pkgname); } } else { logNotAllowedInPartition(name, permFile, parser); } XmlUtils.skipCurrentTag(parser); } break; case "default-enabled-vr-app": { if (allowAppConfigs) { String pkgname = parser.getAttributeValue(null, "package"); Loading
services/core/java/com/android/server/am/AppRestrictionController.java +30 −7 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import static android.os.PowerExemptionManager.REASON_PROC_STATE_PERSISTENT_UI; import static android.os.PowerExemptionManager.REASON_PROFILE_OWNER; import static android.os.PowerExemptionManager.REASON_ROLE_DIALER; import static android.os.PowerExemptionManager.REASON_ROLE_EMERGENCY; import static android.os.PowerExemptionManager.REASON_SYSTEM_ALLOW_LISTED; import static android.os.PowerExemptionManager.REASON_SYSTEM_MODULE; import static android.os.PowerExemptionManager.REASON_SYSTEM_UID; import static android.os.Process.SYSTEM_UID; Loading Loading @@ -140,6 +141,7 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.util.function.TriConsumer; import com.android.server.AppStateTracker; import com.android.server.LocalServices; import com.android.server.SystemConfig; import com.android.server.apphibernation.AppHibernationManagerInternal; import com.android.server.pm.UserManagerInternal; import com.android.server.usage.AppStandbyInternal; Loading Loading @@ -231,6 +233,11 @@ public final class AppRestrictionController { @GuardedBy("mLock") private final HashMap<String, Boolean> mSystemModulesCache = new HashMap<>(); /** * The pre-config packages that are exempted from the background restrictions. */ private ArraySet<String> mBgRestrictionExemptioFromSysConfig; /** * Lock specifically for bookkeeping around the carrier-privileged app set. * Do not acquire any other locks while holding this one. Methods that Loading Loading @@ -705,6 +712,7 @@ public final class AppRestrictionController { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, ActivityThread.currentApplication().getMainExecutor(), mConstantsObserver); mConstantsObserver.start(); initBgRestrictionExemptioFromSysConfig(); initRestrictionStates(); initSystemModuleNames(); registerForUidObservers(); Loading @@ -726,6 +734,22 @@ public final class AppRestrictionController { initRestrictionStates(); } private void initBgRestrictionExemptioFromSysConfig() { mBgRestrictionExemptioFromSysConfig = SystemConfig.getInstance().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)); } } } private boolean isExemptedFromSysConfig(String packageName) { return mBgRestrictionExemptioFromSysConfig != null && mBgRestrictionExemptioFromSysConfig.contains(packageName); } private void initRestrictionStates() { final int[] allUsers = mInjector.getUserManagerInternal().getUserIds(); for (int userId : allUsers) { Loading Loading @@ -1557,14 +1581,11 @@ public final class AppRestrictionController { } } boolean isOnDeviceIdleAllowlist(int uid, boolean allowExceptIdle) { boolean isOnDeviceIdleAllowlist(int uid) { final int appId = UserHandle.getAppId(uid); final int[] allowlist = allowExceptIdle ? mDeviceIdleExceptIdleAllowlist : mDeviceIdleAllowlist; return Arrays.binarySearch(allowlist, appId) >= 0; return Arrays.binarySearch(mDeviceIdleAllowlist, appId) >= 0 || Arrays.binarySearch(mDeviceIdleExceptIdleAllowlist, appId) >= 0; } void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids) { Loading @@ -1585,7 +1606,7 @@ public final class AppRestrictionController { if (UserHandle.isCore(uid)) { return REASON_SYSTEM_UID; } if (isOnDeviceIdleAllowlist(uid, false)) { if (isOnDeviceIdleAllowlist(uid)) { return REASON_ALLOWLISTED_PACKAGE; } final ActivityManagerInternal am = mInjector.getActivityManagerInternal(); Loading Loading @@ -1621,6 +1642,8 @@ public final class AppRestrictionController { return REASON_SYSTEM_MODULE; } else if (isCarrierApp(pkg)) { return REASON_CARRIER_PRIVILEGED_APP; } else if (isExemptedFromSysConfig(pkg)) { return REASON_SYSTEM_ALLOW_LISTED; } } } Loading