From d6df8749dae8d3f2cfa59dc0c37e8e14dcb93557 Mon Sep 17 00:00:00 2001 From: lijilou <lijilou@xiaomi.corp-partner.google.com> Date: Fri, 31 May 2024 11:21:04 +0800 Subject: [PATCH] NotificationManagerService: add right lock for some methods. Test: atest Bug: 343818003 Change-Id: Ia30d818d6ac19c2a3e9ae31b29122fb5bbac338a --- .../NotificationManagerService.java | 20 ++++++++++++------- 1 file changed, 13 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 4d05c36cff3a..4e029fde8bf5 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2291,7 +2291,7 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting void clearNotifications() { - synchronized (mNotificationList) { + synchronized (mNotificationLock) { mEnqueuedNotifications.clear(); mNotificationList.clear(); mNotificationsByKey.clear(); @@ -2301,21 +2301,27 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting void addNotification(NotificationRecord r) { - mNotificationList.add(r); - mNotificationsByKey.put(r.getSbn().getKey(), r); - if (r.getSbn().isGroup()) { - mSummaryByGroupKey.put(r.getGroupKey(), r); + synchronized (mNotificationLock) { + mNotificationList.add(r); + mNotificationsByKey.put(r.getSbn().getKey(), r); + if (r.getSbn().isGroup()) { + mSummaryByGroupKey.put(r.getGroupKey(), r); + } } } @VisibleForTesting void addEnqueuedNotification(NotificationRecord r) { - mEnqueuedNotifications.add(r); + synchronized (mNotificationLock) { + mEnqueuedNotifications.add(r); + } } @VisibleForTesting NotificationRecord getNotificationRecord(String key) { - return mNotificationsByKey.get(key); + synchronized (mNotificationLock) { + return mNotificationsByKey.get(key); + } } -- GitLab