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

Commit 6fd611f6 authored by Kateryna Ivanova's avatar Kateryna Ivanova
Browse files

Hide notifications when finished transitioning to AOD screen when DND mode is...

Hide notifications when finished transitioning to AOD screen when DND mode is on and notification intercepted by DND are prevented from appearing on ambient displays

Test: manual test with Pixel phone for DND and normal mode, with active notifications and without
Test: atest filterDozingSuppressAmbient
Bug: 264851742
Change-Id: Iff0b825704d054cae3b0b3381c5f849ff1872d62
parent f58c1ce7
Loading
Loading
Loading
Loading
+17 −1
Original line number Original line Diff line number Diff line
@@ -190,7 +190,9 @@ public class RankingCoordinator implements Coordinator {
            "DndSuppressingVisualEffects") {
            "DndSuppressingVisualEffects") {
        @Override
        @Override
        public boolean shouldFilterOut(NotificationEntry entry, long now) {
        public boolean shouldFilterOut(NotificationEntry entry, long now) {
            if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) {
            if ((mStatusBarStateController.isDozing()
                    || mStatusBarStateController.getDozeAmount() == 1f)
                    && entry.shouldSuppressAmbient()) {
                return true;
                return true;
            }
            }


@@ -200,6 +202,20 @@ public class RankingCoordinator implements Coordinator {


    private final StatusBarStateController.StateListener mStatusBarStateCallback =
    private final StatusBarStateController.StateListener mStatusBarStateCallback =
            new StatusBarStateController.StateListener() {
            new StatusBarStateController.StateListener() {
                private boolean mPrevDozeAmountIsOne = false;

                @Override
                public void onDozeAmountChanged(float linear, float eased) {
                    StatusBarStateController.StateListener.super.onDozeAmountChanged(linear, eased);

                    boolean dozeAmountIsOne = linear == 1f;
                    if (mPrevDozeAmountIsOne != dozeAmountIsOne) {
                        mDndVisualEffectsFilter.invalidateList("dozeAmount changed to "
                                + (dozeAmountIsOne ? "one" : "not one"));
                        mPrevDozeAmountIsOne = dozeAmountIsOne;
                    }
                }

                @Override
                @Override
                public void onDozingChanged(boolean isDozing) {
                public void onDozingChanged(boolean isDozing) {
                    mDndVisualEffectsFilter.invalidateList("onDozingChanged to " + isDozing);
                    mDndVisualEffectsFilter.invalidateList("onDozingChanged to " + isDozing);
+38 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
@@ -48,6 +50,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.statusbar.notification.collection.listbuilder.pluggable.NotifFilter;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.Pluggable;
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider;
import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider;
import com.android.systemui.statusbar.notification.collection.render.NodeController;
import com.android.systemui.statusbar.notification.collection.render.NodeController;
@@ -75,12 +78,15 @@ public class RankingCoordinatorTest extends SysuiTestCase {
    @Mock private NodeController mAlertingHeaderController;
    @Mock private NodeController mAlertingHeaderController;
    @Mock private NodeController mSilentNodeController;
    @Mock private NodeController mSilentNodeController;
    @Mock private SectionHeaderController mSilentHeaderController;
    @Mock private SectionHeaderController mSilentHeaderController;
    @Mock private Pluggable.PluggableListener<NotifFilter> mInvalidationListener;


    @Captor private ArgumentCaptor<NotifFilter> mNotifFilterCaptor;
    @Captor private ArgumentCaptor<NotifFilter> mNotifFilterCaptor;
    @Captor private ArgumentCaptor<StatusBarStateController.StateListener> mStateListenerCaptor;


    private NotificationEntry mEntry;
    private NotificationEntry mEntry;
    private NotifFilter mCapturedSuspendedFilter;
    private NotifFilter mCapturedSuspendedFilter;
    private NotifFilter mCapturedDozingFilter;
    private NotifFilter mCapturedDozingFilter;
    private StatusBarStateController.StateListener mStatusBarStateCallback;
    private RankingCoordinator mRankingCoordinator;
    private RankingCoordinator mRankingCoordinator;


    private NotifSectioner mAlertingSectioner;
    private NotifSectioner mAlertingSectioner;
@@ -106,6 +112,10 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture());
        verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture());
        mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0);
        mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0);
        mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
        mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
        mCapturedDozingFilter.setInvalidationListener(mInvalidationListener);

        verify(mStatusBarStateController, times(1)).addCallback(mStateListenerCaptor.capture());
        mStatusBarStateCallback = mStateListenerCaptor.getAllValues().get(0);


        mAlertingSectioner = mRankingCoordinator.getAlertingSectioner();
        mAlertingSectioner = mRankingCoordinator.getAlertingSectioner();
        mSilentSectioner = mRankingCoordinator.getSilentSectioner();
        mSilentSectioner = mRankingCoordinator.getSilentSectioner();
@@ -170,6 +180,13 @@ public class RankingCoordinatorTest extends SysuiTestCase {


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

        // WHEN it's not dozing and doze amount is 1
        when(mStatusBarStateController.isDozing()).thenReturn(false);
        when(mStatusBarStateController.getDozeAmount()).thenReturn(1f);

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


    @Test
    @Test
@@ -267,6 +284,27 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        verify(mSilentHeaderController, times(2)).setClearSectionEnabled(eq(false));
        verify(mSilentHeaderController, times(2)).setClearSectionEnabled(eq(false));
    }
    }


    @Test
    public void statusBarStateCallbackTest() {
        mStatusBarStateCallback.onDozeAmountChanged(1f, 1f);
        verify(mInvalidationListener, times(1))
                .onPluggableInvalidated(mCapturedDozingFilter, "dozeAmount changed to one");
        reset(mInvalidationListener);

        mStatusBarStateCallback.onDozeAmountChanged(1f, 1f);
        verify(mInvalidationListener, never()).onPluggableInvalidated(any(), any());
        reset(mInvalidationListener);

        mStatusBarStateCallback.onDozeAmountChanged(0.6f, 0.6f);
        verify(mInvalidationListener, times(1))
                .onPluggableInvalidated(mCapturedDozingFilter, "dozeAmount changed to not one");
        reset(mInvalidationListener);

        mStatusBarStateCallback.onDozeAmountChanged(0f, 0f);
        verify(mInvalidationListener, never()).onPluggableInvalidated(any(), any());
        reset(mInvalidationListener);
    }

    private void assertInSection(NotificationEntry entry, NotifSectioner section) {
    private void assertInSection(NotificationEntry entry, NotifSectioner section) {
        for (NotifSectioner current: mSections) {
        for (NotifSectioner current: mSections) {
            if (current == section) {
            if (current == section) {