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

Commit 3cb146f1 authored by Flavio Fiszman's avatar Flavio Fiszman Committed by Automerger Merge Worker
Browse files

Merge "Clear content from tile when conversation opened in bubble" into sc-dev am: 4c91e055

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14840469

Change-Id: Ib7126ed5662a45fcc85f5e621756498cecc7ee86
parents c75d4fc4 4c91e055
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -31,12 +31,14 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ArrayUtils;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.wm.shell.bubbles.Bubbles;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.Comparator;
import java.util.Comparator;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.Set;


/** Helper functions to handle notifications in People Tiles. */
/** 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.");
        if (DEBUG) Log.d(TAG, "Returning sender from group conversation notification.");
        return person.getName();
        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 Original line 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.getContactUri;
import static com.android.systemui.people.NotificationHelper.getHighestPriorityNotification;
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.NotificationHelper.shouldMatchNotificationByUri;
import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING;
import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING;
import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID;
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.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.wm.shell.bubbles.Bubbles;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
@@ -119,6 +121,7 @@ public class PeopleSpaceWidgetManager {
    private NotificationEntryManager mNotificationEntryManager;
    private NotificationEntryManager mNotificationEntryManager;
    private PackageManager mPackageManager;
    private PackageManager mPackageManager;
    private INotificationManager mINotificationManager;
    private INotificationManager mINotificationManager;
    private Optional<Bubbles> mBubblesOptional;
    private UserManager mUserManager;
    private UserManager mUserManager;
    private PeopleSpaceWidgetManager mManager;
    private PeopleSpaceWidgetManager mManager;
    public UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
    public UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
@@ -142,9 +145,9 @@ public class PeopleSpaceWidgetManager {
    @Inject
    @Inject
    public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps,
    public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps,
            NotificationEntryManager notificationEntryManager,
            NotificationEntryManager notificationEntryManager,
            PackageManager packageManager, UserManager userManager,
            PackageManager packageManager, Optional<Bubbles> bubblesOptional,
            NotificationManager notificationManager, BroadcastDispatcher broadcastDispatcher,
            UserManager userManager, NotificationManager notificationManager,
            @Background Executor bgExecutor) {
            BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor) {
        if (DEBUG) Log.d(TAG, "constructor");
        if (DEBUG) Log.d(TAG, "constructor");
        mContext = context;
        mContext = context;
        mAppWidgetManager = AppWidgetManager.getInstance(context);
        mAppWidgetManager = AppWidgetManager.getInstance(context);
@@ -157,6 +160,7 @@ public class PeopleSpaceWidgetManager {
        mPackageManager = packageManager;
        mPackageManager = packageManager;
        mINotificationManager = INotificationManager.Stub.asInterface(
        mINotificationManager = INotificationManager.Stub.asInterface(
                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        mBubblesOptional = bubblesOptional;
        mUserManager = userManager;
        mUserManager = userManager;
        mNotificationManager = notificationManager;
        mNotificationManager = notificationManager;
        mManager = this;
        mManager = this;
@@ -207,8 +211,9 @@ public class PeopleSpaceWidgetManager {
            AppWidgetManager appWidgetManager, IPeopleManager iPeopleManager,
            AppWidgetManager appWidgetManager, IPeopleManager iPeopleManager,
            PeopleManager peopleManager, LauncherApps launcherApps,
            PeopleManager peopleManager, LauncherApps launcherApps,
            NotificationEntryManager notificationEntryManager, PackageManager packageManager,
            NotificationEntryManager notificationEntryManager, PackageManager packageManager,
            UserManager userManager, INotificationManager iNotificationManager,
            Optional<Bubbles> bubblesOptional, UserManager userManager,
            NotificationManager notificationManager, @Background Executor executor) {
            INotificationManager iNotificationManager, NotificationManager notificationManager,
            @Background Executor executor) {
        mContext = context;
        mContext = context;
        mAppWidgetManager = appWidgetManager;
        mAppWidgetManager = appWidgetManager;
        mIPeopleManager = iPeopleManager;
        mIPeopleManager = iPeopleManager;
@@ -216,6 +221,7 @@ public class PeopleSpaceWidgetManager {
        mLauncherApps = launcherApps;
        mLauncherApps = launcherApps;
        mNotificationEntryManager = notificationEntryManager;
        mNotificationEntryManager = notificationEntryManager;
        mPackageManager = packageManager;
        mPackageManager = packageManager;
        mBubblesOptional = bubblesOptional;
        mUserManager = userManager;
        mUserManager = userManager;
        mINotificationManager = iNotificationManager;
        mINotificationManager = iNotificationManager;
        mNotificationManager = notificationManager;
        mNotificationManager = notificationManager;
@@ -483,7 +489,8 @@ public class PeopleSpaceWidgetManager {
                notifications
                notifications
                        .stream()
                        .stream()
                        .filter(entry -> NotificationHelper.isValid(entry)
                        .filter(entry -> NotificationHelper.isValid(entry)
                                && NotificationHelper.isMissedCallOrHasContent(entry))
                                && NotificationHelper.isMissedCallOrHasContent(entry)
                                && !shouldFilterOut(mBubblesOptional, entry))
                        .collect(Collectors.groupingBy(
                        .collect(Collectors.groupingBy(
                                PeopleTileKey::new,
                                PeopleTileKey::new,
                                Collectors.mapping(Function.identity(), Collectors.toSet())));
                                Collectors.mapping(Function.identity(), Collectors.toSet())));
+29 −1
Original line number Original line Diff line number Diff line
@@ -95,6 +95,7 @@ import android.service.notification.ConversationChannelWrapper;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig;
import android.testing.AndroidTestingRunner;
import android.testing.AndroidTestingRunner;
import android.text.TextUtils;


import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import androidx.test.filters.SmallTest;
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.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.wm.shell.bubbles.Bubbles;


import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
@@ -224,6 +226,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
    private NotificationManager mNotificationManager;
    private NotificationManager mNotificationManager;
    @Mock
    @Mock
    private NotificationManager.Policy mNotificationPolicy;
    private NotificationManager.Policy mNotificationPolicy;
    @Mock
    private Bubbles mBubbles;


    @Captor
    @Captor
    private ArgumentCaptor<NotificationHandler> mListenerCaptor;
    private ArgumentCaptor<NotificationHandler> mListenerCaptor;
@@ -242,7 +246,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
        mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager);
        mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager);
        mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager,
        mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager,
                mPeopleManager, mLauncherApps, mNotificationEntryManager, mPackageManager,
                mPeopleManager, mLauncherApps, mNotificationEntryManager, mPackageManager,
                mUserManager, mINotificationManager, mNotificationManager, mFakeExecutor);
                Optional.of(mBubbles), mUserManager, mINotificationManager, mNotificationManager,
                mFakeExecutor);
        mManager.attach(mListenerService);
        mManager.attach(mListenerService);


        verify(mListenerService).addNotificationHandler(mListenerCaptor.capture());
        verify(mListenerService).addNotificationHandler(mListenerCaptor.capture());
@@ -267,6 +272,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
                INTERRUPTION_FILTER_ALL);
                INTERRUPTION_FILTER_ALL);
        int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT};
        int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT};
        when(mAppWidgetManager.getAppWidgetIds(any())).thenReturn(widgetIdsArray);
        when(mAppWidgetManager.getAppWidgetIds(any())).thenReturn(widgetIdsArray);
        when(mBubbles.isBubbleNotificationSuppressedFromShade(any(), any())).thenReturn(false);


        when(mMockContext.getPackageName()).thenReturn(TEST_PACKAGE_A);
        when(mMockContext.getPackageName()).thenReturn(TEST_PACKAGE_A);
        when(mMockContext.getUserId()).thenReturn(0);
        when(mMockContext.getUserId()).thenReturn(0);
@@ -1192,6 +1198,28 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
                .getVisibleNotifications();
                .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
    @Test
    public void testUpdateWidgetsOnStateChange() {
    public void testUpdateWidgetsOnStateChange() {
        mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
        mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);