diff options
2 files changed, 24 insertions, 23 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index e24c4af7026e..412eee840d4f 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -6568,7 +6568,7 @@ public class NotificationManagerService extends SystemService { // limit the number of non-fgs outstanding notificationrecords an app can have if (!n.isForegroundService()) { - int count = getNotificationCountLocked(pkg, userId, id, tag); + int count = getNotificationCount(pkg, userId, id, tag); if (count >= MAX_PACKAGE_NOTIFICATIONS) { mUsageStats.registerOverCountQuota(pkg); Slog.e(TAG, "Package has already posted or enqueued " + count @@ -6647,28 +6647,29 @@ public class NotificationManagerService extends SystemService { return true; } - @GuardedBy("mNotificationLock") - protected int getNotificationCountLocked(String pkg, int userId, int excludedId, + protected int getNotificationCount(String pkg, int userId, int excludedId, String excludedTag) { int count = 0; - final int N = mNotificationList.size(); - for (int i = 0; i < N; i++) { - final NotificationRecord existing = mNotificationList.get(i); - if (existing.getSbn().getPackageName().equals(pkg) - && existing.getSbn().getUserId() == userId) { - if (existing.getSbn().getId() == excludedId - && TextUtils.equals(existing.getSbn().getTag(), excludedTag)) { - continue; + synchronized (mNotificationLock) { + final int N = mNotificationList.size(); + for (int i = 0; i < N; i++) { + final NotificationRecord existing = mNotificationList.get(i); + if (existing.getSbn().getPackageName().equals(pkg) + && existing.getSbn().getUserId() == userId) { + if (existing.getSbn().getId() == excludedId + && TextUtils.equals(existing.getSbn().getTag(), excludedTag)) { + continue; + } + count++; } - count++; } - } - final int M = mEnqueuedNotifications.size(); - for (int i = 0; i < M; i++) { - final NotificationRecord existing = mEnqueuedNotifications.get(i); - if (existing.getSbn().getPackageName().equals(pkg) - && existing.getSbn().getUserId() == userId) { - count++; + final int M = mEnqueuedNotifications.size(); + for (int i = 0; i < M; i++) { + final NotificationRecord existing = mEnqueuedNotifications.get(i); + if (existing.getSbn().getPackageName().equals(pkg) + && existing.getSbn().getUserId() == userId) { + count++; + } } } return count; 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 c480258c7fd9..08847f247f2c 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -3394,16 +3394,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // anything that's currently enqueued or posted int userId = UserHandle.getUserId(mUid); assertEquals(40, - mService.getNotificationCountLocked(PKG, userId, 0, null)); + mService.getNotificationCount(PKG, userId, 0, null)); assertEquals(40, - mService.getNotificationCountLocked(PKG, userId, 0, "tag2")); + mService.getNotificationCount(PKG, userId, 0, "tag2")); // return all for package "a" - "banana" tag isn't used assertEquals(2, - mService.getNotificationCountLocked("a", userId, 0, "banana")); + mService.getNotificationCount("a", userId, 0, "banana")); // exclude a known notification - it's excluded from only the posted list, not enqueued - assertEquals(39, mService.getNotificationCountLocked( + assertEquals(39, mService.getNotificationCount( PKG, userId, sampleIdToExclude, sampleTagToExclude)); } |