diff options
| author | 2020-05-01 11:55:57 -0400 | |
|---|---|---|
| committer | 2020-05-01 11:57:04 -0400 | |
| commit | 1a80b29eace941b36eea56e47519cc0a6bcd0860 (patch) | |
| tree | 0f39f910354ff141ee99cb0436d662c4042c04da | |
| parent | 04ffadbc867f3c27539dec87b1a5717a119cac70 (diff) | |
Show FGS notifs even if app is over limit
Test: atest
Fixes: 149957552
Change-Id: Ia6221762f166a7e30b8f4796df21519218956a75
2 files changed, 67 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 76acf57db408..4d2994fd00a9 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -5959,13 +5959,15 @@ public class NotificationManagerService extends SystemService { } } - // limit the number of outstanding notificationrecords an app can have - int count = getNotificationCountLocked(pkg, userId, id, tag); - if (count >= MAX_PACKAGE_NOTIFICATIONS) { - mUsageStats.registerOverCountQuota(pkg); - Slog.e(TAG, "Package has already posted or enqueued " + count - + " notifications. Not showing more. package=" + pkg); - return false; + // limit the number of non-fgs outstanding notificationrecords an app can have + if (!r.getNotification().isForegroundService()) { + int count = getNotificationCountLocked(pkg, userId, id, tag); + if (count >= MAX_PACKAGE_NOTIFICATIONS) { + mUsageStats.registerOverCountQuota(pkg); + Slog.e(TAG, "Package has already posted or enqueued " + count + + " notifications. Not showing more. package=" + pkg); + return false; + } } } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index d5ecfeb55e95..7da4ff607bb3 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -6630,4 +6630,62 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(mBinderService.hasSentMessage(PKG, mUid)); } + + @Test + public void testCanPostFgsWhenOverLimit() throws RemoteException { + for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { + StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, + i, null, false).getSbn(); + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "testCanPostFgsWhenOverLimit", + sbn.getId(), sbn.getNotification(), sbn.getUserId()); + } + + final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); + sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "testCanPostFgsWhenOverLimit - fgs over limit!", + sbn.getId(), sbn.getNotification(), sbn.getUserId()); + + waitForIdle(); + + StatusBarNotification[] notifs = + mBinderService.getActiveNotifications(sbn.getPackageName()); + assertEquals(NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS + 1, notifs.length); + assertEquals(NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS + 1, + mService.getNotificationRecordCount()); + } + + @Test + public void testCannotPostNonFgsWhenOverLimit() throws RemoteException { + for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { + StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, + i, null, false).getSbn(); + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "testCanPostFgsWhenOverLimit", + sbn.getId(), sbn.getNotification(), sbn.getUserId()); + waitForIdle(); + } + + final StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, + 100, null, false).getSbn(); + sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "testCanPostFgsWhenOverLimit - fgs over limit!", + sbn.getId(), sbn.getNotification(), sbn.getUserId()); + + final StatusBarNotification sbn2 = generateNotificationRecord(mTestNotificationChannel, + 101, null, false).getSbn(); + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "testCanPostFgsWhenOverLimit - non fgs over limit!", + sbn2.getId(), sbn2.getNotification(), sbn2.getUserId()); + + waitForIdle(); + + StatusBarNotification[] notifs = + mBinderService.getActiveNotifications(sbn.getPackageName()); + assertEquals(NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS + 1, notifs.length); + assertEquals(NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS + 1, + mService.getNotificationRecordCount()); + } } |