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

Commit a7d50cbb authored by Nick Chameyev's avatar Nick Chameyev
Browse files

[Unfold transition] Ensure that we start fold animation after half-folded state

Currently, lastHingeAngleBeforeTransition could be stuck
in '0' degrees or some low angle if user rotates the device
after unfolding or if stopped in half-folded state.

If then user unfolded the device further and started folding
the device, the fold animation won't kick-in before we reach
this angle.

Added updating of this angle when we unfold past it
after a threshold.

Bug: 365706412
Test: atest DeviceFoldStateProviderTest
Flag: EXEMPT bugfix
Change-Id: I9e706d74fcb021b8381ca7ef5b43afa00aeaebf9
parent aa4939bd
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) {