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

Commit d262830d authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Media TTT] Allow additional transitions from the SUCCEEDED/FAILED

states.

For the _SUCCEEDED or _FAILED states, those represent the end of a
transfer process. So, from those states, we should allow any state
that is the start of a new transfer process.

Bug: 221265848
Test: manual: verified that the new transitions are allowed when using
the adb commands
Test: atest MediaTttSenderCoordinatorTest

Change-Id: I39f63c3a9cd983714165ae2491d7ccb5a3603334
parent 41125ee8
Loading
Loading
Loading
Loading
+41 −15
Original line number Original line Diff line number Diff line
@@ -136,9 +136,9 @@ enum class ChipStateSender(
        ),
        ),
    ) {
    ) {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
            return nextState == FAR_FROM_RECEIVER ||
            // Since _SUCCEEDED is the end of a transfer sequence, we should be able to move to any
                    nextState == ALMOST_CLOSE_TO_START_CAST ||
            // state that represents the beginning of a new sequence.
                    nextState == TRANSFER_TO_THIS_DEVICE_TRIGGERED
            return stateIsStartOfSequence(nextState)
        }
        }
    },
    },


@@ -158,9 +158,9 @@ enum class ChipStateSender(
        ),
        ),
    ) {
    ) {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
            return nextState == FAR_FROM_RECEIVER ||
            // Since _SUCCEEDED is the end of a transfer sequence, we should be able to move to any
                    nextState == ALMOST_CLOSE_TO_END_CAST ||
            // state that represents the beginning of a new sequence.
                    nextState == TRANSFER_TO_RECEIVER_TRIGGERED
            return stateIsStartOfSequence(nextState)
        }
        }
    },
    },


@@ -173,9 +173,9 @@ enum class ChipStateSender(
        endItem = SenderEndItem.Error,
        endItem = SenderEndItem.Error,
    ) {
    ) {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
            return nextState == FAR_FROM_RECEIVER ||
            // Since _FAILED is the end of a transfer sequence, we should be able to move to any
                    nextState == ALMOST_CLOSE_TO_START_CAST ||
            // state that represents the beginning of a new sequence.
                    nextState == TRANSFER_TO_THIS_DEVICE_TRIGGERED
            return stateIsStartOfSequence(nextState)
        }
        }
    },
    },


@@ -188,9 +188,9 @@ enum class ChipStateSender(
        endItem = SenderEndItem.Error,
        endItem = SenderEndItem.Error,
    ) {
    ) {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
            return nextState == FAR_FROM_RECEIVER ||
            // Since _FAILED is the end of a transfer sequence, we should be able to move to any
                    nextState == ALMOST_CLOSE_TO_END_CAST ||
            // state that represents the beginning of a new sequence.
                    nextState == TRANSFER_TO_RECEIVER_TRIGGERED
            return stateIsStartOfSequence(nextState)
        }
        }
    },
    },


@@ -210,9 +210,9 @@ enum class ChipStateSender(
        }
        }


        override fun isValidNextState(nextState: ChipStateSender): Boolean {
        override fun isValidNextState(nextState: ChipStateSender): Boolean {
            return nextState == FAR_FROM_RECEIVER ||
            // When far away, we can go to any state that represents the start of a transfer
                    nextState.transferStatus == TransferStatus.NOT_STARTED ||
            // sequence.
                    nextState.transferStatus == TransferStatus.IN_PROGRESS
            return stateIsStartOfSequence(nextState)
        }
        }
    };
    };


@@ -227,6 +227,20 @@ enum class ChipStateSender(
        return Text.Loaded(context.getString(stringResId!!, otherDeviceName))
        return Text.Loaded(context.getString(stringResId!!, otherDeviceName))
    }
    }


    /**
     * Returns true if moving from this state to [nextState] is a valid transition.
     *
     * In general, we expect a media transfer go to through a sequence of states:
     * For push-to-receiver:
     *   - ALMOST_CLOSE_TO_START_CAST => TRANSFER_TO_RECEIVER_TRIGGERED =>
     *     TRANSFER_TO_RECEIVER_(SUCCEEDED|FAILED)
     *   - ALMOST_CLOSE_TO_END_CAST => TRANSFER_TO_THIS_DEVICE_TRIGGERED =>
     *     TRANSFER_TO_THIS_DEVICE_(SUCCEEDED|FAILED)
     *
     * This method should validate that the states go through approximately that sequence.
     *
     * See b/221265848 for more details.
     */
    abstract fun isValidNextState(nextState: ChipStateSender): Boolean
    abstract fun isValidNextState(nextState: ChipStateSender): Boolean


    companion object {
    companion object {
@@ -276,6 +290,18 @@ enum class ChipStateSender(


            return currentState.isValidNextState(desiredState)
            return currentState.isValidNextState(desiredState)
        }
        }

        /**
         * Returns true if [state] represents a state at the beginning of a sequence and false
         * otherwise.
         */
        private fun stateIsStartOfSequence(state: ChipStateSender): Boolean {
            return state == FAR_FROM_RECEIVER ||
                state.transferStatus == TransferStatus.NOT_STARTED ||
                // It's possible to skip the NOT_STARTED phase and go immediately into the
                // IN_PROGRESS phase.
                state.transferStatus == TransferStatus.IN_PROGRESS
        }
    }
    }
}
}


+4 −4
Original line number Original line Diff line number Diff line
@@ -622,7 +622,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun commandQueueCallback_receiverSucceededThenReceiverTriggered_invalidTransitionLogged() {
    fun commandQueueCallback_receiverSucceededThenThisDeviceSucceeded_invalidTransitionLogged() {
        displayReceiverTriggered()
        displayReceiverTriggered()
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED,
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED,
@@ -632,7 +632,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
        reset(windowManager)
        reset(windowManager)


        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED,
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED,
            routeInfo,
            routeInfo,
            null
            null
        )
        )
@@ -642,7 +642,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun commandQueueCallback_thisDeviceSucceededThenThisDeviceTriggered_invalidTransitionLogged() {
    fun commandQueueCallback_thisDeviceSucceededThenReceiverSucceeded_invalidTransitionLogged() {
        displayThisDeviceTriggered()
        displayThisDeviceTriggered()
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED,
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED,
@@ -652,7 +652,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
        reset(windowManager)
        reset(windowManager)


        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_TRIGGERED,
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED,
            routeInfo,
            routeInfo,
            null
            null
        )
        )