From 787b788920a035f405de7a43e8375928c9787690 Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 16 May 2022 15:51:25 -0700 Subject: [PATCH] Ignore ongoing notifications in dreams. Ignore ongoing notifications when deciding whether or not to show a notification dot in dreams. Test: atest DreamOverlayNotificationCountProviderTest Bug: 232848687 Change-Id: I167860fc12d8a6a01d787d2c9c99b32f48dce57b --- .../DreamOverlayNotificationCountProvider.java | 6 +++++- .../DreamOverlayNotificationCountProviderTest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java index 6589f26dbde29..3dd43866e4657 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java @@ -37,7 +37,7 @@ import javax.inject.Inject; /*** * {@link DreamOverlayNotificationCountProvider} provides the current notification count to - * registered callbacks. + * registered callbacks. Ongoing notifications are not included in the count. */ @SysUISingleton public class DreamOverlayNotificationCountProvider @@ -49,6 +49,10 @@ public class DreamOverlayNotificationCountProvider @Override public void onNotificationPosted( StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap) { + if (sbn.isOngoing()) { + // Don't count ongoing notifications. + return; + } mNotificationKeys.add(sbn.getKey()); reportNotificationCountChanged(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java index b7de6c15459c9..25d4c472dc634 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java @@ -16,6 +16,7 @@ package com.android.systemui.dreams; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -48,6 +49,8 @@ public class DreamOverlayNotificationCountProviderTest extends SysuiTestCase { @Mock StatusBarNotification mNotification2; @Mock + StatusBarNotification mNotification3; + @Mock NotificationListenerService.RankingMap mRankingMap; private DreamOverlayNotificationCountProvider mProvider; @@ -58,6 +61,8 @@ public class DreamOverlayNotificationCountProviderTest extends SysuiTestCase { when(mNotification1.getKey()).thenReturn("key1"); when(mNotification2.getKey()).thenReturn("key2"); + when(mNotification3.getKey()).thenReturn("key3"); + when(mNotification3.isOngoing()).thenReturn(true); final StatusBarNotification[] notifications = {mNotification1}; when(mNotificationListener.getActiveNotifications()).thenReturn(notifications); @@ -83,4 +88,13 @@ public class DreamOverlayNotificationCountProviderTest extends SysuiTestCase { handlerArgumentCaptor.getValue().onNotificationRemoved(mNotification1, mRankingMap); verify(mCallback).onNotificationCountChanged(0); } + + @Test + public void testPostingOngoingNotificationDoesNotCallCallbackWithNotificationCount() { + final ArgumentCaptor handlerArgumentCaptor = + ArgumentCaptor.forClass(NotificationHandler.class); + verify(mNotificationListener).addNotificationHandler(handlerArgumentCaptor.capture()); + handlerArgumentCaptor.getValue().onNotificationPosted(mNotification3, mRankingMap); + verify(mCallback, never()).onNotificationCountChanged(2); + } }