Loading services/core/java/com/android/server/am/AppRestrictionController.java +53 −5 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import static com.android.internal.notification.SystemNotificationChannels.ABUSI import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.am.AppFGSTracker.foregroundServiceTypeToIndex; import static com.android.server.am.BaseAppStateTracker.ONE_DAY; import android.annotation.ElapsedRealtimeLong; import android.annotation.IntDef; Loading Loading @@ -647,6 +648,13 @@ public final class AppRestrictionController { static final String KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "abusive_notification_minimal_interval"; /** * The minimal interval in ms before posting a notification again on long running FGS * from a certain package. */ static final String KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "long_fgs_notification_minimal_interval"; /** * The behavior for an app with a FGS and its notification is still showing, when the system * detects it's abusive and should be put into bg restricted level. {@code true} - we'll Loading @@ -661,8 +669,20 @@ public final class AppRestrictionController { static final String KEY_BG_RESTRICTION_EXEMPTED_PACKAGES = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "restriction_exempted_packages"; /** * Default value to {@link #mBgAutoRestrictedBucket}. */ static final boolean DEFAULT_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = false; static final long DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS = 24 * 60 * 60 * 1000; /** * Default value to {@link #mBgAbusiveNotificationMinIntervalMs}. */ static final long DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS = ONE_DAY; /** * Default value to {@link #mBgAbusiveNotificationMinIntervalMs}. */ static final long DEFAULT_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL_MS = 30 * ONE_DAY; /** * Default value to {@link #mBgPromptFgsWithNotiToBgRestricted}. Loading @@ -673,7 +693,9 @@ public final class AppRestrictionController { volatile boolean mRestrictedBucketEnabled; volatile long mBgNotificationMinIntervalMs; volatile long mBgAbusiveNotificationMinIntervalMs; volatile long mBgLongFgsNotificationMinIntervalMs; /** * @see #KEY_BG_RESTRICTION_EXEMPTED_PACKAGES. Loading Loading @@ -706,6 +728,9 @@ public final class AppRestrictionController { case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL: updateBgAbusiveNotificationMinimalInterval(); break; case KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL: updateBgLongFgsNotificationMinimalInterval(); break; case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED: updateBgPromptFgsWithNotiToBgRestricted(); break; Loading Loading @@ -743,6 +768,7 @@ public final class AppRestrictionController { void updateDeviceConfig() { updateBgAutoRestrictedBucketChanged(); updateBgAbusiveNotificationMinimalInterval(); updateBgLongFgsNotificationMinimalInterval(); updateBgPromptFgsWithNotiToBgRestricted(); updateBgRestrictionExemptedPackages(); } Loading @@ -759,12 +785,19 @@ public final class AppRestrictionController { } private void updateBgAbusiveNotificationMinimalInterval() { mBgNotificationMinIntervalMs = DeviceConfig.getLong( mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL, DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS); } private void updateBgLongFgsNotificationMinimalInterval() { mBgLongFgsNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL, DEFAULT_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL_MS); } private void updateBgPromptFgsWithNotiToBgRestricted() { mBgPromptFgsWithNotiToBgRestricted = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, Loading Loading @@ -801,7 +834,11 @@ public final class AppRestrictionController { pw.print(prefix); pw.print(KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgNotificationMinIntervalMs); pw.println(mBgAbusiveNotificationMinIntervalMs); pw.print(prefix); pw.print(KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgLongFgsNotificationMinIntervalMs); pw.print(prefix); pw.print(KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED); pw.print('='); Loading Loading @@ -1650,6 +1687,17 @@ public final class AppRestrictionController { pendingIntent, packageName, uid, null); } long getNotificationMinInterval(@NotificationType int notificationType) { switch (notificationType) { case NOTIFICATION_TYPE_ABUSIVE_CURRENT_DRAIN: return mBgController.mConstantsObserver.mBgAbusiveNotificationMinIntervalMs; case NOTIFICATION_TYPE_LONG_RUNNING_FGS: return mBgController.mConstantsObserver.mBgLongFgsNotificationMinIntervalMs; default: return 0L; } } int getNotificationIdIfNecessary(@NotificationType int notificationType, String packageName, int uid) { synchronized (mSettingsLock) { Loading @@ -1663,7 +1711,7 @@ public final class AppRestrictionController { final long lastNotificationShownTimeElapsed = settings.getLastNotificationTime(notificationType); if (lastNotificationShownTimeElapsed != 0 && (lastNotificationShownTimeElapsed + mBgController.mConstantsObserver.mBgNotificationMinIntervalMs > now)) { + getNotificationMinInterval(notificationType) > now)) { if (DEBUG_BG_RESTRICTION_CONTROLLER) { Slog.i(TAG, "Not showing notification as last notification was shown " + TimeUtils.formatDuration(now - lastNotificationShownTimeElapsed) Loading Loading
services/core/java/com/android/server/am/AppRestrictionController.java +53 −5 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import static com.android.internal.notification.SystemNotificationChannels.ABUSI import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.am.AppFGSTracker.foregroundServiceTypeToIndex; import static com.android.server.am.BaseAppStateTracker.ONE_DAY; import android.annotation.ElapsedRealtimeLong; import android.annotation.IntDef; Loading Loading @@ -647,6 +648,13 @@ public final class AppRestrictionController { static final String KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "abusive_notification_minimal_interval"; /** * The minimal interval in ms before posting a notification again on long running FGS * from a certain package. */ static final String KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "long_fgs_notification_minimal_interval"; /** * The behavior for an app with a FGS and its notification is still showing, when the system * detects it's abusive and should be put into bg restricted level. {@code true} - we'll Loading @@ -661,8 +669,20 @@ public final class AppRestrictionController { static final String KEY_BG_RESTRICTION_EXEMPTED_PACKAGES = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "restriction_exempted_packages"; /** * Default value to {@link #mBgAutoRestrictedBucket}. */ static final boolean DEFAULT_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = false; static final long DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS = 24 * 60 * 60 * 1000; /** * Default value to {@link #mBgAbusiveNotificationMinIntervalMs}. */ static final long DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS = ONE_DAY; /** * Default value to {@link #mBgAbusiveNotificationMinIntervalMs}. */ static final long DEFAULT_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL_MS = 30 * ONE_DAY; /** * Default value to {@link #mBgPromptFgsWithNotiToBgRestricted}. Loading @@ -673,7 +693,9 @@ public final class AppRestrictionController { volatile boolean mRestrictedBucketEnabled; volatile long mBgNotificationMinIntervalMs; volatile long mBgAbusiveNotificationMinIntervalMs; volatile long mBgLongFgsNotificationMinIntervalMs; /** * @see #KEY_BG_RESTRICTION_EXEMPTED_PACKAGES. Loading Loading @@ -706,6 +728,9 @@ public final class AppRestrictionController { case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL: updateBgAbusiveNotificationMinimalInterval(); break; case KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL: updateBgLongFgsNotificationMinimalInterval(); break; case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED: updateBgPromptFgsWithNotiToBgRestricted(); break; Loading Loading @@ -743,6 +768,7 @@ public final class AppRestrictionController { void updateDeviceConfig() { updateBgAutoRestrictedBucketChanged(); updateBgAbusiveNotificationMinimalInterval(); updateBgLongFgsNotificationMinimalInterval(); updateBgPromptFgsWithNotiToBgRestricted(); updateBgRestrictionExemptedPackages(); } Loading @@ -759,12 +785,19 @@ public final class AppRestrictionController { } private void updateBgAbusiveNotificationMinimalInterval() { mBgNotificationMinIntervalMs = DeviceConfig.getLong( mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL, DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS); } private void updateBgLongFgsNotificationMinimalInterval() { mBgLongFgsNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL, DEFAULT_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL_MS); } private void updateBgPromptFgsWithNotiToBgRestricted() { mBgPromptFgsWithNotiToBgRestricted = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, Loading Loading @@ -801,7 +834,11 @@ public final class AppRestrictionController { pw.print(prefix); pw.print(KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgNotificationMinIntervalMs); pw.println(mBgAbusiveNotificationMinIntervalMs); pw.print(prefix); pw.print(KEY_BG_LONG_FGS_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgLongFgsNotificationMinIntervalMs); pw.print(prefix); pw.print(KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED); pw.print('='); Loading Loading @@ -1650,6 +1687,17 @@ public final class AppRestrictionController { pendingIntent, packageName, uid, null); } long getNotificationMinInterval(@NotificationType int notificationType) { switch (notificationType) { case NOTIFICATION_TYPE_ABUSIVE_CURRENT_DRAIN: return mBgController.mConstantsObserver.mBgAbusiveNotificationMinIntervalMs; case NOTIFICATION_TYPE_LONG_RUNNING_FGS: return mBgController.mConstantsObserver.mBgLongFgsNotificationMinIntervalMs; default: return 0L; } } int getNotificationIdIfNecessary(@NotificationType int notificationType, String packageName, int uid) { synchronized (mSettingsLock) { Loading @@ -1663,7 +1711,7 @@ public final class AppRestrictionController { final long lastNotificationShownTimeElapsed = settings.getLastNotificationTime(notificationType); if (lastNotificationShownTimeElapsed != 0 && (lastNotificationShownTimeElapsed + mBgController.mConstantsObserver.mBgNotificationMinIntervalMs > now)) { + getNotificationMinInterval(notificationType) > now)) { if (DEBUG_BG_RESTRICTION_CONTROLLER) { Slog.i(TAG, "Not showing notification as last notification was shown " + TimeUtils.formatDuration(now - lastNotificationShownTimeElapsed) Loading