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

Commit 319f4d77 authored by Josh Tsuji's avatar Josh Tsuji Committed by Jeff DeCew
Browse files

Keep the clock centered until the delayed doze animation plays.

This prevents the clock from moving until the notifications
come down.

Bug: 269085199
Test: atest NotificationPanelViewTest
Change-Id: Iaf3f5f6ba3dd5b7a62b4e41d857069f7c8cb888e
parent 7a42fd9b
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -589,6 +589,12 @@ public final class NotificationPanelViewController implements Dumpable {
    private boolean mGestureWaitForTouchSlop;
    private boolean mIgnoreXTouchSlop;
    private boolean mExpandLatencyTracking;
    /**
     * Whether we're waking up and will play the delayed doze animation in
     * {@link NotificationWakeUpCoordinator}. If so, we'll want to keep the clock centered until the
     * delayed doze animation starts.
     */
    private boolean mWillPlayDelayedDozeAmountAnimation = false;
    private final DreamingToLockscreenTransitionViewModel mDreamingToLockscreenTransitionViewModel;
    private final OccludedToLockscreenTransitionViewModel mOccludedToLockscreenTransitionViewModel;
    private final LockscreenToDreamingTransitionViewModel mLockscreenToDreamingTransitionViewModel;
@@ -1045,6 +1051,12 @@ public final class NotificationPanelViewController implements Dumpable {
                    requestScrollerTopPaddingUpdate(false /* animate */);
                }
            }

            @Override
            public void onDelayedDozeAmountAnimationRunning(boolean running) {
                // On running OR finished, the animation is no longer waiting to play
                setWillPlayDelayedDozeAmountAnimation(false);
            }
        });

        mView.setRtlChangeListener(layoutDirection -> {
@@ -1641,11 +1653,28 @@ public final class NotificationPanelViewController implements Dumpable {
            // Pulsing notification appears on the right. Move clock left to avoid overlap.
            return false;
        }
        if (mWillPlayDelayedDozeAmountAnimation) {
            return true;
        }
        // "Visible" notifications are actually not visible on AOD (unless pulsing), so it is safe
        // to center the clock without overlap.
        return isOnAod();
    }

    /**
     * Notify us that {@link NotificationWakeUpCoordinator} is going to play the doze wakeup
     * animation after a delay. If so, we'll keep the clock centered until that animation starts.
     */
    public void setWillPlayDelayedDozeAmountAnimation(boolean willPlay) {
        if (mWillPlayDelayedDozeAmountAnimation == willPlay) return;

        mWillPlayDelayedDozeAmountAnimation = willPlay;
        mWakeUpCoordinator.logDelayingClockWakeUpAnimation(willPlay);

        // Once changing this value, see if we should move the clock.
        positionClockAndNotifications();
    }

    private boolean isOnAod() {
        return mDozing && mDozeParameters.getAlwaysOn();
    }
+21 −5
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController.OnBypassSta
import com.android.systemui.statusbar.phone.ScreenOffAnimationController
import com.android.systemui.statusbar.policy.HeadsUpManager
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener
import com.android.systemui.util.doOnCancel
import com.android.systemui.util.doOnEnd
import com.android.systemui.util.doOnStart
import java.io.PrintWriter
import javax.inject.Inject
import kotlin.math.max
@@ -357,6 +357,11 @@ constructor(
     * [requestDelayedAnimation] is used to request that we delay the start of the wakeup animation
     * in order to wait for a potential fingerprint authentication to arrive, since unlocking during
     * the wakeup animation looks chaotic.
     *
     * If called with [wakingUp] and [requestDelayedAnimation] both `true`, the [WakeUpListener]s
     * are guaranteed to receive at least one [WakeUpListener.onDelayedDozeAmountAnimationRunning]
     * call with `false` at some point in the near future. A call with `true` before that will
     * happen if the animation is not already running.
     */
    fun setWakingUp(
        wakingUp: Boolean,
@@ -379,8 +384,13 @@ constructor(
                interpolator = InterpolatorsAndroidX.LINEAR
                duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP.toLong()
                startDelay = WAKEUP_ANIMATION_DELAY_MS.toLong()
                doOnEnd { delayedDozeAmountAnimator = null }
                doOnCancel { delayedDozeAmountAnimator = null }
                doOnStart {
                    wakeUpListeners.forEach { it.onDelayedDozeAmountAnimationRunning(true) }
                }
                doOnEnd {
                    delayedDozeAmountAnimator = null
                    wakeUpListeners.forEach { it.onDelayedDozeAmountAnimationRunning(false) }
                }
                start()
            }
    }
@@ -597,8 +607,8 @@ constructor(
        pw.println("canShowPulsingHuns: $canShowPulsingHuns")
    }

    fun logClockTransitionAnimationStarting(delayWakeUpAnimation: Boolean) {
        logger.logClockTransitionAnimationStarting(delayWakeUpAnimation)
    fun logDelayingClockWakeUpAnimation(delayingAnimation: Boolean) {
        logger.logDelayingClockWakeUpAnimation(delayingAnimation)
    }

    interface WakeUpListener {
@@ -611,6 +621,12 @@ constructor(
         * @param expandingChanged if the user has started or stopped expanding
         */
        @JvmDefault fun onPulseExpansionChanged(expandingChanged: Boolean) {}

        /**
         * Called when the animator started by [scheduleDelayedDozeAmountAnimation] begins running
         * after the start delay, or after it ends/is cancelled.
         */
        @JvmDefault fun onDelayedDozeAmountAnimationRunning(running: Boolean) {}
    }

    companion object {
+3 −3
Original line number Diff line number Diff line
@@ -193,12 +193,12 @@ constructor(@NotificationLockscreenLog private val buffer: LogBuffer) {
        )
    }

    fun logClockTransitionAnimationStarting(delayWakeUpAnimation: Boolean) {
    fun logDelayingClockWakeUpAnimation(delayingAnimation: Boolean) {
        buffer.log(
            TAG,
            DEBUG,
            { bool1 = delayWakeUpAnimation },
            { "clockTransitionAnimationStarting() withDelay=$bool1" }
            { bool1 = delayingAnimation },
            { "logDelayingClockWakeUpAnimation($bool1)" }
        )
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -3564,6 +3564,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
                    }
                }

                mNotificationPanelViewController.setWillPlayDelayedDozeAmountAnimation(
                        mShouldDelayWakeUpAnimation);
                mWakeUpCoordinator.setWakingUp(
                        /* wakingUp= */ true,
                        mShouldDelayWakeUpAnimation);
+28 −0
Original line number Diff line number Diff line
@@ -436,6 +436,34 @@ public class NotificationPanelViewControllerTest extends NotificationPanelViewCo
        assertKeyguardStatusViewCentered();
    }

    @Test
    public void keyguardStatusView_willPlayDelayedDoze_isCentered_thenNot() {
        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(2);
        mStatusBarStateController.setState(KEYGUARD);
        enableSplitShade(/* enabled= */ true);

        mNotificationPanelViewController.setWillPlayDelayedDozeAmountAnimation(true);
        setDozing(/* dozing= */ false, /* dozingAlwaysOn= */ false);
        assertKeyguardStatusViewCentered();

        mNotificationPanelViewController.setWillPlayDelayedDozeAmountAnimation(false);
        assertKeyguardStatusViewNotCentered();
    }

    @Test
    public void keyguardStatusView_willPlayDelayedDoze_isCentered_thenStillCenteredIfNoNotifs() {
        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(0);
        mStatusBarStateController.setState(KEYGUARD);
        enableSplitShade(/* enabled= */ true);

        mNotificationPanelViewController.setWillPlayDelayedDozeAmountAnimation(true);
        setDozing(/* dozing= */ false, /* dozingAlwaysOn= */ false);
        assertKeyguardStatusViewCentered();

        mNotificationPanelViewController.setWillPlayDelayedDozeAmountAnimation(false);
        assertKeyguardStatusViewCentered();
    }

    @Test
    public void testCanCollapsePanelOnTouch_trueForKeyGuard() {
        mStatusBarStateController.setState(KEYGUARD);
Loading