Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f13f4eb0 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add missing lock

Test: atest
Fixes: 189743705
Change-Id: I23b07e1c3b0c8a45fa2059501f666346b27273ce
parent c0c48273
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -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,10 +6647,10 @@ 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;
        synchronized (mNotificationLock) {
            final int N = mNotificationList.size();
            for (int i = 0; i < N; i++) {
                final NotificationRecord existing = mNotificationList.get(i);
@@ -6671,6 +6671,7 @@ public class NotificationManagerService extends SystemService {
                    count++;
                }
            }
        }
        return count;
    }

+4 −4
Original line number Diff line number Diff line
@@ -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));
    }