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

Commit c1722c61 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "Move DndVisualEffectsFilter to finalize stage for doze-dependent notifs." into main

parents 20ec7596 f34674e9
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,16 @@ flag {
   }
   }
}
}


flag {
   name: "notification_ambient_suppression_after_inflation"
   namespace: "systemui"
   description: "Move the DND visual effects filter to the finalize stage of the pipeline when it is doze-dependent, but keep it in the pre-group stage when it is doze-independent."
   bug: "373411431"
   metadata {
        purpose: PURPOSE_BUGFIX
   }
}

flag {
flag {
   name: "notification_over_expansion_clipping_fix"
   name: "notification_over_expansion_clipping_fix"
   namespace: "systemui"
   namespace: "systemui"
+47 −1
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.NotificationManager;
import android.platform.test.annotations.EnableFlags;


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -61,6 +62,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -83,6 +85,7 @@ public class RankingCoordinatorTest extends SysuiTestCase {


    private NotificationEntry mEntry;
    private NotificationEntry mEntry;
    private NotifFilter mCapturedSuspendedFilter;
    private NotifFilter mCapturedSuspendedFilter;
    private NotifFilter mCapturedDndStatelessFilter;
    private NotifFilter mCapturedDozingFilter;
    private NotifFilter mCapturedDozingFilter;
    private StatusBarStateController.StateListener mStatusBarStateCallback;
    private StatusBarStateController.StateListener mStatusBarStateCallback;
    private RankingCoordinator mRankingCoordinator;
    private RankingCoordinator mRankingCoordinator;
@@ -107,6 +110,15 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        mRankingCoordinator.attach(mNotifPipeline);
        mRankingCoordinator.attach(mNotifPipeline);
        verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture());
        verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture());
        mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0);
        mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0);
        if (com.android.systemui.Flags.notificationAmbientSuppressionAfterInflation()) {
            verify(mNotifPipeline).addFinalizeFilter(mNotifFilterCaptor.capture());
            mCapturedDndStatelessFilter = mNotifFilterCaptor.getAllValues().get(1);
            mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(2);
        } else {
            verify(mNotifPipeline, never()).addFinalizeFilter(any());
            mCapturedDndStatelessFilter = null;
            mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
        }
        mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
        mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1);
        mCapturedDozingFilter.setInvalidationListener(mInvalidationListener);
        mCapturedDozingFilter.setInvalidationListener(mInvalidationListener);


@@ -158,6 +170,40 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        assertTrue(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0));
        assertTrue(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0));
    }
    }


    @Test
    @EnableFlags(com.android.systemui.Flags.FLAG_NOTIFICATION_AMBIENT_SUPPRESSION_AFTER_INFLATION)
    public void filterStatelessVisualEffectsSuppression() {
        Mockito.clearInvocations(mStatusBarStateController);

        // WHEN should suppress ambient
        mEntry.setRanking(getRankingForUnfilteredNotif()
                .setSuppressedVisualEffects(SUPPRESSED_EFFECT_AMBIENT)
                .build());

        // THEN do not filter out the notification
        assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));

        // WHEN should suppress list
        mEntry.setRanking(getRankingForUnfilteredNotif()
                .setSuppressedVisualEffects(SUPPRESSED_EFFECT_NOTIFICATION_LIST)
                .build());

        // THEN do not filter out the notification
        assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0));

        // WHEN should suppress both ambient and list
        mEntry.setRanking(getRankingForUnfilteredNotif()
                .setSuppressedVisualEffects(
                    SUPPRESSED_EFFECT_AMBIENT | SUPPRESSED_EFFECT_NOTIFICATION_LIST)
                .build());

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

        // VERIFY that we don't check the dozing state
        verify(mStatusBarStateController, never()).isDozing();
    }

    @Test
    @Test
    public void filterDozingSuppressAmbient() {
    public void filterDozingSuppressAmbient() {
        // GIVEN should suppress ambient
        // GIVEN should suppress ambient
+16 −1
Original line number Original line Diff line number Diff line
@@ -74,8 +74,13 @@ public class RankingCoordinator implements Coordinator {
        mStatusBarStateController.addCallback(mStatusBarStateCallback);
        mStatusBarStateController.addCallback(mStatusBarStateCallback);


        pipeline.addPreGroupFilter(mSuspendedFilter);
        pipeline.addPreGroupFilter(mSuspendedFilter);
        if (com.android.systemui.Flags.notificationAmbientSuppressionAfterInflation()) {
            pipeline.addPreGroupFilter(mDndPreGroupFilter);
            pipeline.addFinalizeFilter(mDndVisualEffectsFilter);
        } else {
            pipeline.addPreGroupFilter(mDndVisualEffectsFilter);
            pipeline.addPreGroupFilter(mDndVisualEffectsFilter);
        }
        }
    }


    public NotifSectioner getAlertingSectioner() {
    public NotifSectioner getAlertingSectioner() {
        return mAlertingNotifSectioner;
        return mAlertingNotifSectioner;
@@ -191,6 +196,16 @@ public class RankingCoordinator implements Coordinator {
        }
        }
    };
    };


    private final NotifFilter mDndPreGroupFilter = new NotifFilter("DndPreGroupFilter") {
        @Override
        public boolean shouldFilterOut(NotificationEntry entry, long now) {
            // Entries with both flags set should be suppressed ASAP regardless of dozing state.
            // As a result of being doze-independent, they can also be suppressed early in the
            // pipeline.
            return entry.shouldSuppressNotificationList() && entry.shouldSuppressAmbient();
        }
    };

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