From 5a4127d2417257909835e2182ef8034c90f6ba6a Mon Sep 17 00:00:00 2001 From: Flavio Fiszman Date: Fri, 4 Jun 2021 16:12:49 +0100 Subject: [PATCH] Clear content from tile when conversation opened in bubble Manually test by adding a Conversation Widget for a conversation that opens bubbles, get a notification, open the bubble, ensure that notification content goes away from widget. Change-Id: I4e7051870f6b8eaa8d7bcc476bb79c1003230813 Test: manual and PeopleSpaceWidgetManagerTest Bug: 184242416 --- .../systemui/people/NotificationHelper.java | 10 +++++++ .../widget/PeopleSpaceWidgetManager.java | 19 ++++++++---- .../widget/PeopleSpaceWidgetManagerTest.java | 30 ++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java b/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java index a5c239244c106..b5ac90828fceb 100644 --- a/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java +++ b/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java @@ -31,12 +31,14 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.wm.shell.bubbles.Bubbles; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; /** Helper functions to handle notifications in People Tiles. */ @@ -234,5 +236,13 @@ public class NotificationHelper { if (DEBUG) Log.d(TAG, "Returning sender from group conversation notification."); return person.getName(); } + + /** Returns whether {@code entry} is suppressed from shade, meaning we should not show it. */ + public static boolean shouldFilterOut( + Optional bubblesOptional, NotificationEntry entry) { + return bubblesOptional.isPresent() + && bubblesOptional.get().isBubbleNotificationSuppressedFromShade( + entry.getKey(), entry.getSbn().getGroupKey()); + } } diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index 2602d7a3e369a..39faf5a1eed9a 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -26,6 +26,7 @@ import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE import static com.android.systemui.people.NotificationHelper.getContactUri; import static com.android.systemui.people.NotificationHelper.getHighestPriorityNotification; +import static com.android.systemui.people.NotificationHelper.shouldFilterOut; import static com.android.systemui.people.NotificationHelper.shouldMatchNotificationByUri; import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING; import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID; @@ -87,6 +88,7 @@ import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.wm.shell.bubbles.Bubbles; import java.util.ArrayList; import java.util.Collections; @@ -119,6 +121,7 @@ public class PeopleSpaceWidgetManager { private NotificationEntryManager mNotificationEntryManager; private PackageManager mPackageManager; private INotificationManager mINotificationManager; + private Optional mBubblesOptional; private UserManager mUserManager; private PeopleSpaceWidgetManager mManager; public UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); @@ -142,9 +145,9 @@ public class PeopleSpaceWidgetManager { @Inject public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, NotificationEntryManager notificationEntryManager, - PackageManager packageManager, UserManager userManager, - NotificationManager notificationManager, BroadcastDispatcher broadcastDispatcher, - @Background Executor bgExecutor) { + PackageManager packageManager, Optional bubblesOptional, + UserManager userManager, NotificationManager notificationManager, + BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor) { if (DEBUG) Log.d(TAG, "constructor"); mContext = context; mAppWidgetManager = AppWidgetManager.getInstance(context); @@ -157,6 +160,7 @@ public class PeopleSpaceWidgetManager { mPackageManager = packageManager; mINotificationManager = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + mBubblesOptional = bubblesOptional; mUserManager = userManager; mNotificationManager = notificationManager; mManager = this; @@ -207,8 +211,9 @@ public class PeopleSpaceWidgetManager { AppWidgetManager appWidgetManager, IPeopleManager iPeopleManager, PeopleManager peopleManager, LauncherApps launcherApps, NotificationEntryManager notificationEntryManager, PackageManager packageManager, - UserManager userManager, INotificationManager iNotificationManager, - NotificationManager notificationManager, @Background Executor executor) { + Optional bubblesOptional, UserManager userManager, + INotificationManager iNotificationManager, NotificationManager notificationManager, + @Background Executor executor) { mContext = context; mAppWidgetManager = appWidgetManager; mIPeopleManager = iPeopleManager; @@ -216,6 +221,7 @@ public class PeopleSpaceWidgetManager { mLauncherApps = launcherApps; mNotificationEntryManager = notificationEntryManager; mPackageManager = packageManager; + mBubblesOptional = bubblesOptional; mUserManager = userManager; mINotificationManager = iNotificationManager; mNotificationManager = notificationManager; @@ -483,7 +489,8 @@ public class PeopleSpaceWidgetManager { notifications .stream() .filter(entry -> NotificationHelper.isValid(entry) - && NotificationHelper.isMissedCallOrHasContent(entry)) + && NotificationHelper.isMissedCallOrHasContent(entry) + && !shouldFilterOut(mBubblesOptional, entry)) .collect(Collectors.groupingBy( PeopleTileKey::new, Collectors.mapping(Function.identity(), Collectors.toSet()))); diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java index d63c529778b81..46a60dc47e7be 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java @@ -95,6 +95,7 @@ import android.service.notification.ConversationChannelWrapper; import android.service.notification.StatusBarNotification; import android.service.notification.ZenModeConfig; import android.testing.AndroidTestingRunner; +import android.text.TextUtils; import androidx.preference.PreferenceManager; import androidx.test.filters.SmallTest; @@ -112,6 +113,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; import com.android.systemui.util.concurrency.FakeExecutor; import com.android.systemui.util.time.FakeSystemClock; +import com.android.wm.shell.bubbles.Bubbles; import org.junit.Before; import org.junit.Test; @@ -224,6 +226,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private NotificationManager mNotificationManager; @Mock private NotificationManager.Policy mNotificationPolicy; + @Mock + private Bubbles mBubbles; @Captor private ArgumentCaptor mListenerCaptor; @@ -242,7 +246,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager); mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager, mPeopleManager, mLauncherApps, mNotificationEntryManager, mPackageManager, - mUserManager, mINotificationManager, mNotificationManager, mFakeExecutor); + Optional.of(mBubbles), mUserManager, mINotificationManager, mNotificationManager, + mFakeExecutor); mManager.attach(mListenerService); verify(mListenerService).addNotificationHandler(mListenerCaptor.capture()); @@ -267,6 +272,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { INTERRUPTION_FILTER_ALL); int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT}; when(mAppWidgetManager.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + when(mBubbles.isBubbleNotificationSuppressedFromShade(any(), any())).thenReturn(false); when(mMockContext.getPackageName()).thenReturn(TEST_PACKAGE_A); when(mMockContext.getUserId()).thenReturn(0); @@ -1192,6 +1198,28 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .getVisibleNotifications(); } + @Test + public void testAugmentTileFromNotificationEntryManager_notificationHidden() { + when(mBubbles.isBubbleNotificationSuppressedFromShade(any(), any())).thenReturn(true); + PeopleSpaceTile tile = + new PeopleSpaceTile + .Builder(SHORTCUT_ID, "userName", ICON, new Intent()) + .setPackageName(TEST_PACKAGE_A) + .setUserHandle(new UserHandle(0)) + .build(); + when(mNotificationEntryManager.getVisibleNotifications()) + .thenReturn(List.of(mNotificationEntry)); + + PeopleSpaceTile actual = + mManager.augmentTileFromNotificationEntryManager(tile, + Optional.of(WIDGET_ID_WITH_SHORTCUT)); + + assertThat(TextUtils.isEmpty(actual.getNotificationContent())).isTrue(); + + verify(mNotificationEntryManager, times(1)) + .getVisibleNotifications(); + } + @Test public void testUpdateWidgetsOnStateChange() { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);