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

Commit bcb37d8a authored by Ned Burns's avatar Ned Burns
Browse files

Split RankingCoordinator's filter into two

Makes it clearer in logs why something was filtered.

Bug: 112656837
Test: atest
Change-Id: I0a5a077974a7070b243066d03a2d026ce230cbce
parent f1d96d48
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@ public class RankingCoordinator implements Coordinator {
    public void attach(NotifPipeline pipeline) {
        mStatusBarStateController.addCallback(mStatusBarStateCallback);

        pipeline.addPreGroupFilter(mNotifFilter);
        pipeline.addPreGroupFilter(mSuspendedFilter);
        pipeline.addPreGroupFilter(mDozingFilter);
    }

    /**
@@ -53,33 +54,30 @@ public class RankingCoordinator implements Coordinator {
     * NotifListBuilder invalidates the notification list each time the ranking is updated,
     * so we don't need to explicitly invalidate this filter on ranking update.
     */
    private final NotifFilter mNotifFilter = new NotifFilter(TAG) {
    private final NotifFilter mSuspendedFilter = new NotifFilter("IsSuspendedFilter") {
        @Override
        public boolean shouldFilterOut(NotificationEntry entry, long now) {
            // App suspended from Ranking
            if (entry.getRanking().isSuspended()) {
                return true;
            return entry.getRanking().isSuspended();
        }
    };

    private final NotifFilter mDozingFilter = new NotifFilter("IsDozingFilter") {
        @Override
        public boolean shouldFilterOut(NotificationEntry entry, long now) {
            // Dozing + DND Settings from Ranking object
            if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) {
                return true;
            }

            if (!mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList()) {
                return true;
            }

            return false;
            return !mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList();
        }
    };


    private final StatusBarStateController.StateListener mStatusBarStateCallback =
            new StatusBarStateController.StateListener() {
                @Override
                public void onDozingChanged(boolean isDozing) {
                    mNotifFilter.invalidateList();
                    mDozingFilter.invalidateList();
                }
            };
}
+19 −16
Original line number Diff line number Diff line
@@ -19,9 +19,8 @@ package com.android.systemui.statusbar.notification.collection.coordinator;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -42,6 +41,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -51,20 +51,23 @@ public class RankingCoordinatorTest extends SysuiTestCase {

    @Mock private StatusBarStateController mStatusBarStateController;
    @Mock private NotifPipeline mNotifPipeline;

    @Captor private ArgumentCaptor<NotifFilter> mNotifFilterCaptor;

    private NotificationEntry mEntry;
    private RankingCoordinator mRankingCoordinator;
    private NotifFilter mRankingFilter;
    private NotifFilter mCapturedSuspendedFilter;
    private NotifFilter mCapturedDozingFilter;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mRankingCoordinator = new RankingCoordinator(mStatusBarStateController);
        RankingCoordinator rankingCoordinator = new RankingCoordinator(mStatusBarStateController);
        mEntry = new NotificationEntryBuilder().build();

        ArgumentCaptor<NotifFilter> filterCaptor = ArgumentCaptor.forClass(NotifFilter.class);
        mRankingCoordinator.attach(mNotifPipeline);
        verify(mNotifPipeline, times(1)).addPreGroupFilter(filterCaptor.capture());
        mRankingFilter = filterCaptor.getValue();
        rankingCoordinator.attach(mNotifPipeline);
        verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture());
        mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0);
        mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
    }

    @Test
@@ -73,7 +76,7 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        mEntry.setRanking(getRankingForUnfilteredNotif().build());

        // THEN don't filter out the notification
        assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertFalse(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0));
    }

    @Test
@@ -84,7 +87,7 @@ public class RankingCoordinatorTest extends SysuiTestCase {
                .build());

        // THEN filter out the notification
        assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertTrue(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0));
    }

    @Test
@@ -98,13 +101,13 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        when(mStatusBarStateController.isDozing()).thenReturn(true);

        // THEN filter out the notification
        assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));

        // WHEN it's not dozing (showing the notification list)
        when(mStatusBarStateController.isDozing()).thenReturn(false);

        // THEN don't filter out the notification
        assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));
    }

    @Test
@@ -118,13 +121,13 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        when(mStatusBarStateController.isDozing()).thenReturn(true);

        // THEN don't filter out the notification
        assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));

        // WHEN it's not dozing (showing the notification list)
        when(mStatusBarStateController.isDozing()).thenReturn(false);

        // THEN filter out the notification
        assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0));
        assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));
    }

    private RankingBuilder getRankingForUnfilteredNotif() {