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

Commit 8a638f92 authored by Yining Liu's avatar Yining Liu
Browse files

Suppress NSSL height updates when QS expand fraction is greater than 0

We used to suppress the NSSL height updates to make the UI stable when
expand QS panel in NSSL#updateStackEndHeightAndStackHeight, which gets
value from getQsExpansionFraction() before flexi-glass.

This change empowers the existing height update suppression flow to also
suppress the height updates when the QS is expanded at some fraction.

Bug: 433919013
Test: NotificationStackScrollLayoutTest
Flag: com.android.systemui.scene_container
Change-Id: I41e88c7a95bf89928a9ed4c4a86562f19604fc9b
parent bf909f9b
Loading
Loading
Loading
Loading
+81 −6
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import static com.android.systemui.flags.SceneContainerFlagParameterizationKt.pa
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_GENTLE;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.RUBBER_BAND_FACTOR_NORMAL;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

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

import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -101,6 +104,8 @@ import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.ResourcesSplitShadeStateController;

import kotlin.Unit;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -111,14 +116,13 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import kotlin.Unit;
import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

/**
 * Tests for {@link NotificationStackScrollLayout}.
 */
@@ -248,6 +252,78 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
        assertThat(mAmbientState.getStackY()).isEqualTo(expected);
    }

    @Test
    @EnableSceneContainer
    public void updateInterpolatedStackHeight_qsExpanded_shouldSkipUpdateStackEndHeight() {
        // Before: QS is fully expanded
        final float expansionFraction = 0.2f;
        final float endHeight = 200f;

        mStackScroller.setQsExpandFraction(1f);
        mStackScroller.suppressHeightUpdates(true);
        mAmbientState.setExpansionFraction(expansionFraction);
        mAmbientState.setStackEndHeight(endHeight);

        // When: update StackEndHeightAndStackHeight
        mStackScroller.updateStackEndHeightAndStackHeight(expansionFraction);

        // Then: stackEndHeight is not updated
        float expected = mStackScroller
                .calculateInterpolatedStackHeight(endHeight, expansionFraction);

        assertThat(mAmbientState.getInterpolatedStackHeight()).isEqualTo(expected);
    }

    @Test
    @EnableSceneContainer
    public void updateInterpolatedStackHeight_onLockScreenStack_shouldUpdateStackEndHeight() {
        // Before: QS is fully collapsed, on lockscreen
        final float expansionFraction = 0.2f;
        final float endHeight = 200f;

        mStackScroller.setQsExpandFraction(0f);
        mStackScroller.suppressHeightUpdates(false);
        mStackScroller.setMaxDisplayedNotifications(2);
        mAmbientState.setExpansionFraction(expansionFraction);
        mAmbientState.setStackEndHeight(endHeight);


        // When: update StackEndHeightAndStackHeight
        mStackScroller.updateStackEndHeightAndStackHeight(expansionFraction);

        // Then: updatedEndHeight should be mStackScroller.getIntrinsicStackHeight()
        float updatedEndHeight = mStackScroller.getIntrinsicStackHeight();
        float expected = mStackScroller.calculateInterpolatedStackHeight(
                updatedEndHeight, expansionFraction);
        assertThat(mAmbientState.getInterpolatedStackHeight()).isEqualTo(expected);
    }

    @Test
    @EnableSceneContainer
    public void updateInterpolatedStackHeight_onExpandedShade_shouldUpdateStackEndHeight() {
        // Before: QS is fully collapsed, on expanded Shade
        final float expansionFraction = 0.2f;
        final float endHeight = 200f;

        mStackScroller.setQsExpandFraction(0f);
        mStackScroller.suppressHeightUpdates(false);
        mStackScroller.setMaxDisplayedNotifications(-1);
        mAmbientState.setExpansionFraction(expansionFraction);
        mAmbientState.setStackEndHeight(endHeight);


        // When: update StackEndHeightAndStackHeight
        mStackScroller.updateStackEndHeightAndStackHeight(expansionFraction);

        // Then: updatedEndHeight should be determined by the stack cutoffs
        float updatedEndHeight = Math.max(
                0f, mAmbientState.getStackCutoff() - mAmbientState.getStackTop());
        float expected = mStackScroller.calculateInterpolatedStackHeight(
                updatedEndHeight, expansionFraction);
        assertThat(mAmbientState.getInterpolatedStackHeight()).isEqualTo(expected);
    }


    @Test
    @EnableSceneContainer
    public void testIntrinsicStackHeight() {
@@ -281,8 +357,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
    public void testUpdateStackHeight_withExpansionAmount_whenDozeNotChanging() {
        final float endHeight = 8f;
        final float expansionFraction = 0.5f;
        final float expected = MathUtils.lerp(
                endHeight * StackScrollAlgorithm.START_FRACTION,
        final float expected = mStackScroller.calculateInterpolatedStackHeight(
                endHeight, expansionFraction);

        mStackScroller.updateInterpolatedStackHeight(endHeight, expansionFraction);
+10 −2
Original line number Diff line number Diff line
@@ -609,6 +609,8 @@ public class NotificationStackScrollLayout
    private boolean mShouldSkipTopPaddingAnimationAfterFold = false;
    @Nullable private SplitShadeStateController mSplitShadeStateController = null;
    private boolean mIsSmallLandscapeLockscreenEnabled = false;

    /** Suppress the stackEndHeight updates. */
    private boolean mSuppressHeightUpdates;
    private boolean mIsOnLockscreen;

@@ -1740,6 +1742,7 @@ public class NotificationStackScrollLayout
     * True when
     * 1) Unlock hint is running
     * 2) Swiping up on lockscreen or flinging down after swipe up
     * 3) When transiting between the expanded QS and the single Shade.
     */
    private boolean shouldSkipHeightUpdate() {
        if (SceneContainerFlag.isEnabled()) {
@@ -1842,8 +1845,13 @@ public class NotificationStackScrollLayout
    @VisibleForTesting
    public void updateInterpolatedStackHeight(float endHeight, float fraction) {
        mAmbientState.setInterpolatedStackHeight(
                MathUtils.lerp(endHeight * StackScrollAlgorithm.START_FRACTION,
                        endHeight, fraction));
                calculateInterpolatedStackHeight(endHeight, fraction));
    }

    @VisibleForTesting
    float calculateInterpolatedStackHeight(float endHeight, float fraction) {
        return MathUtils.lerp(endHeight * StackScrollAlgorithm.START_FRACTION,
                endHeight, fraction);
    }

    /**
+18 −8
Original line number Diff line number Diff line
@@ -150,13 +150,26 @@ constructor(
        }
    }

    val qsExpandFraction: Flow<Float> =
        shadeInteractor.qsExpansion.dumpWhileCollecting("qsExpandFraction")

    /** Are notification stack height updates suppressed? */
    val suppressHeightUpdates: Flow<Boolean> =
        sceneInteractor.transitionState.map { transition: ObservableTransitionState ->
            transition is Transition &&
                transition.fromContent == Scenes.Lockscreen &&
                (transition.toContent == Overlays.Bouncer || transition.toContent == Scenes.Gone)
        sceneInteractor.transitionState
            .map { state: ObservableTransitionState ->
                when (state) {
                    is Idle -> {
                        state.currentScene == Scenes.QuickSettings
                    }
                    is Transition -> {
                        state.isTransitioningBetween(Scenes.Shade, Scenes.QuickSettings) ||
                            state.fromContent == Scenes.Lockscreen &&
                                (state.toContent == Overlays.Bouncer ||
                                    state.toContent == Scenes.Gone)
                    }
                }
            }
            .dumpWhileCollecting("suppressHeightUpdates")

    /**
     * The expansion fraction of the notification stack. It should go from 0 to 1 when transitioning
@@ -206,9 +219,6 @@ constructor(
            .distinctUntilChanged()
            .dumpWhileCollecting("expandFraction")

    val qsExpandFraction: Flow<Float> =
        shadeInteractor.qsExpansion.dumpWhileCollecting("qsExpandFraction")

    val isOccluded: Flow<Boolean> =
        bouncerInteractor.bouncerExpansion
            .map { it == 1f }