Merge "Clear content from tile when conversation opened in bubble" into sc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java b/packages/SystemUI/src/com/android/systemui/people/NotificationHelper.java
index a5c2392..b5ac908 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 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 @@
         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<Bubbles> 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 2602d7a..39faf5a 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 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.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 @@
     private NotificationEntryManager mNotificationEntryManager;
     private PackageManager mPackageManager;
     private INotificationManager mINotificationManager;
+    private Optional<Bubbles> mBubblesOptional;
     private UserManager mUserManager;
     private PeopleSpaceWidgetManager mManager;
     public UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
@@ -142,9 +145,9 @@
     @Inject
     public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps,
             NotificationEntryManager notificationEntryManager,
-            PackageManager packageManager, UserManager userManager,
-            NotificationManager notificationManager, BroadcastDispatcher broadcastDispatcher,
-            @Background Executor bgExecutor) {
+            PackageManager packageManager, Optional<Bubbles> 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 @@
         mPackageManager = packageManager;
         mINotificationManager = INotificationManager.Stub.asInterface(
                 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+        mBubblesOptional = bubblesOptional;
         mUserManager = userManager;
         mNotificationManager = notificationManager;
         mManager = this;
@@ -207,8 +211,9 @@
             AppWidgetManager appWidgetManager, IPeopleManager iPeopleManager,
             PeopleManager peopleManager, LauncherApps launcherApps,
             NotificationEntryManager notificationEntryManager, PackageManager packageManager,
-            UserManager userManager, INotificationManager iNotificationManager,
-            NotificationManager notificationManager, @Background Executor executor) {
+            Optional<Bubbles> bubblesOptional, UserManager userManager,
+            INotificationManager iNotificationManager, NotificationManager notificationManager,
+            @Background Executor executor) {
         mContext = context;
         mAppWidgetManager = appWidgetManager;
         mIPeopleManager = iPeopleManager;
@@ -216,6 +221,7 @@
         mLauncherApps = launcherApps;
         mNotificationEntryManager = notificationEntryManager;
         mPackageManager = packageManager;
+        mBubblesOptional = bubblesOptional;
         mUserManager = userManager;
         mINotificationManager = iNotificationManager;
         mNotificationManager = notificationManager;
@@ -483,7 +489,8 @@
                 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 d63c529..46a60dc 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.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.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 @@
     private NotificationManager mNotificationManager;
     @Mock
     private NotificationManager.Policy mNotificationPolicy;
+    @Mock
+    private Bubbles mBubbles;
 
     @Captor
     private ArgumentCaptor<NotificationHandler> mListenerCaptor;
@@ -242,7 +246,8 @@
         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 @@
                 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);
@@ -1193,6 +1199,28 @@
     }
 
     @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);