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

Commit a4095138 authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "[Unfold transition] Ensure that we start fold animation after half-folded state" into main

parents c9afb135 a7d50cbb
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -615,6 +615,71 @@ class DeviceFoldStateProviderTest : SysuiTestCase() {
        assertThat(foldUpdates).containsExactly(FOLD_UPDATE_START_CLOSING)
    }

    @Test
    fun angleDecreaseAfterCancelAnimation_emitsStartClosingEvent() {
        setFoldState(folded = true)
        sendHingeAngleEvent(0)
        foldUpdates.clear()

        setFoldState(folded = false)
        rotationListener.value.onRotationChanged(1)
        sendHingeAngleEvent(180)
        screenOnStatusProvider.notifyScreenTurningOn()
        screenOnStatusProvider.notifyScreenTurnedOn()

        // Start folding
        (180 downTo 60).forEach {
            sendHingeAngleEvent(it)
        }
        // Stopped folding and simulate timeout in this posture
        simulateTimeout()

        assertThat(foldUpdates)
            .containsExactly(
                FOLD_UPDATE_START_OPENING, // unfolded
                FOLD_UPDATE_FINISH_HALF_OPEN, // force-finished the animation because of rotation
                FOLD_UPDATE_START_CLOSING, // start closing the device
                FOLD_UPDATE_FINISH_HALF_OPEN, // finished closing and timed-out in this state
            )

    }

    @Test
    fun angleIncreaseDecreaseAfterHalfUnfold_emitsStartClosingEvent() {
        setFoldState(folded = true)
        sendHingeAngleEvent(0)
        foldUpdates.clear()

        setFoldState(folded = false)
        sendHingeAngleEvent(90)
        screenOnStatusProvider.notifyScreenTurningOn()
        screenOnStatusProvider.notifyScreenTurnedOn()

        // Stopped folding and simulate timeout in this posture
        simulateTimeout()

        // Unfold further
        (90 until 180).forEach {
            sendHingeAngleEvent(it)
        }
        // Start folding
        (180 downTo 90).forEach {
            sendHingeAngleEvent(it)
        }

        // Stopped folding and simulate timeout in this posture
        simulateTimeout()

        assertThat(foldUpdates)
            .containsExactly(
                FOLD_UPDATE_START_OPENING, // unfolded
                FOLD_UPDATE_FINISH_HALF_OPEN, // force-finished the animation because of rotation
                FOLD_UPDATE_START_CLOSING, // start closing the device
                FOLD_UPDATE_FINISH_HALF_OPEN, // finished closing and timed-out in this state
            )

    }

    @Test
    fun onUnfold_onSmallScreen_emitsStartOpening() {
        // the new display state might arrive later, so it shouldn't be used to decide to send the
+6 −2
Original line number Diff line number Diff line
@@ -128,7 +128,11 @@ constructor(

        val currentDirection =
            if (angle < lastHingeAngle) FOLD_UPDATE_START_CLOSING else FOLD_UPDATE_START_OPENING
        if (isTransitionInProgress && currentDirection != lastFoldUpdate) {
        val changedDirectionWhileInTransition =
            isTransitionInProgress && currentDirection != lastFoldUpdate
        val unfoldedPastThresholdSinceLastTransition =
            angle - lastHingeAngleBeforeTransition > HINGE_ANGLE_CHANGE_THRESHOLD_DEGREES
        if (changedDirectionWhileInTransition || unfoldedPastThresholdSinceLastTransition) {
            lastHingeAngleBeforeTransition = lastHingeAngle
        }

@@ -153,7 +157,7 @@ constructor(
                isOnLargeScreen // Avoids sending closing event when on small screen.
        // Start event is sent regardless due to hall sensor.
        ) {
            notifyFoldUpdate(transitionUpdate, lastHingeAngle)
            notifyFoldUpdate(transitionUpdate, angle)
        }

        if (isTransitionInProgress) {