Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a4127d2 authored by Flavio Fiszman's avatar Flavio Fiszman
Browse files

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
parent 1dfd9484
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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<Bubbles> bubblesOptional, NotificationEntry entry) {
        return bubblesOptional.isPresent()
                && bubblesOptional.get().isBubbleNotificationSuppressedFromShade(
                entry.getKey(), entry.getSbn().getGroupKey());
    }
}
+13 −6
Original line number Diff line number Diff line
@@ -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<Bubbles> 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<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 @@ 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<Bubbles> 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())));
+29 −1
Original line number Diff line number Diff line
@@ -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<NotificationHandler> 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);