From 9bb258dfbbb5fe8fca845ac95aa75884de932aca Mon Sep 17 00:00:00 2001 From: Yuri Lin Date: Wed, 5 May 2021 14:45:11 -0400 Subject: [PATCH] Refactor Archive-related bit of dumpImpl into Archive. This allows for actually locking the buffer iteration with mBufferLock to avoid accidental concurrent access. Test: atest NotificationManagerServiceTest; manually inspected dumpsys Bug: 186860793 Change-Id: I6a97a74833f57ec45c118fcfc63f628703ec2557 --- .../NotificationManagerService.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 6083bc5612192..76aba25822d00 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -645,7 +645,7 @@ public class NotificationManagerService extends SystemService { sb.append("Archive ("); sb.append(N); sb.append(" notification"); - sb.append((N==1)?")":"s)"); + sb.append((N == 1) ? ")" : "s)"); return sb.toString(); } @@ -718,6 +718,22 @@ public class NotificationManagerService extends SystemService { } } } + + void dumpImpl(PrintWriter pw, @NonNull DumpFilter filter) { + synchronized (mBufferLock) { + Iterator> iter = descendingIterator(); + int i = 0; + while (iter.hasNext()) { + final StatusBarNotification sbn = iter.next().first; + if (filter != null && !filter.matches(sbn)) continue; + pw.println(" " + sbn); + if (++i >= 5) { + if (iter.hasNext()) pw.println(" ..."); + break; + } + } + } + } } void loadDefaultApprovedServices(int userId) { @@ -5928,17 +5944,7 @@ public class NotificationManagerService extends SystemService { + mPreferencesHelper.shouldHideSilentStatusIcons()); } pw.println(" mArchive=" + mArchive.toString()); - Iterator> iter = mArchive.descendingIterator(); - int j=0; - while (iter.hasNext()) { - final StatusBarNotification sbn = iter.next().first; - if (filter != null && !filter.matches(sbn)) continue; - pw.println(" " + sbn); - if (++j >= 5) { - if (iter.hasNext()) pw.println(" ..."); - break; - } - } + mArchive.dumpImpl(pw, filter); if (!zenOnly) { N = mEnqueuedNotifications.size();