From 5d7808a0c2cffc8091c908195077fe46b8c5c5f3 Mon Sep 17 00:00:00 2001 From: qinyige1 Date: Fri, 17 Jun 2022 10:52:45 +0800 Subject: [PATCH] [NMS] Call isServiceTokenValidLocked with lock. Method isServiceTokenValidLocked should be called with mNotificationLock held, otherwise there will be race condition. Bug: 236512598 Test: Manual Change-Id: I7e24b5afe3d0a5233debf9da45200c2f4e1f570f --- .../notification/NotificationManagerService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index f836a6c4af7af..b7fc38d8c8670 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -9404,10 +9404,16 @@ public class NotificationManagerService extends SystemService { * given NAS is bound in. */ private boolean isInteractionVisibleToListener(ManagedServiceInfo info, int userId) { - boolean isAssistantService = mAssistants.isServiceTokenValidLocked(info.service); + boolean isAssistantService = isServiceTokenValid(info.service); return !isAssistantService || info.isSameUser(userId); } + private boolean isServiceTokenValid(IInterface service) { + synchronized (mNotificationLock) { + return mAssistants.isServiceTokenValidLocked(service); + } + } + private boolean isPackageSuspendedForUser(String pkg, int uid) { final long identity = Binder.clearCallingIdentity(); int userId = UserHandle.getUserId(uid); @@ -10652,7 +10658,7 @@ public class NotificationManagerService extends SystemService { BackgroundThread.getHandler().post(() -> { if (info.isSystem || hasCompanionDevice(info) - || mAssistants.isServiceTokenValidLocked(info.service)) { + || isServiceTokenValid(info.service)) { notifyNotificationChannelChanged( info, pkg, user, channel, modificationType); }