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

Commit 5cd58a35 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Returning false when trying to set magnetic translations on IDLE.

This ensures that the caller can set the translation of a notification
without magnetic effects if the magnetic row manager is IDLE. This is an
invalid state for this call. Thus, we also log an error.

Test: MagneticRowManagerImplTest
Flag: com.android.systemui.magnetic_notification_swipes
Bug: 392752275
Change-Id: I008bab3aa39199c74f7d2efee9de0cac53c515cc
parent 25d0404d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -89,6 +89,20 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
            assertThat(underTest.currentState).isEqualTo(State.PULLING)
        }

    @Test
    fun setMagneticRowTranslation_whenIdle_doesNotSetMagneticTranslation() =
        kosmos.testScope.runTest {
            // GIVEN an IDLE state
            // WHEN setting a translation for the swiped row
            val row = children.attachedChildren[childrenNumber / 2]
            underTest.setMagneticRowTranslation(row, translation = 100f)

            // THEN no magnetic translations are set
            val canSetMagneticTranslation =
                underTest.setMagneticRowTranslation(row, translation = 100f)
            assertThat(canSetMagneticTranslation).isFalse()
        }

    @Test
    fun setMagneticRowTranslation_whenRowIsNotSwiped_doesNotSetMagneticTranslation() =
        kosmos.testScope.runTest {
+15 −0
Original line number Diff line number Diff line
@@ -219,6 +219,21 @@ constructor(
            { "Failed to set magnetic and roundable targets for $str1 on state $str2." },
        )
    }

    fun logMagneticRowTranslationNotSet(
        state: MagneticNotificationRowManagerImpl.State,
        entry: NotificationEntry,
    ) {
        buffer.log(
            TAG,
            LogLevel.ERROR,
            {
                str1 = entry.logKey
                str2 = state.name
            },
            { "Failed to set magnetic row translation for $str1 on state $str2." },
        )
    }
}

private const val TAG = "NotifRow"
+4 −1
Original line number Diff line number Diff line
@@ -112,6 +112,10 @@ constructor(
        if (!row.isSwipedTarget()) return false

        when (currentState) {
            State.IDLE -> {
                logger.logMagneticRowTranslationNotSet(currentState, row.entry)
                return false
            }
            State.TARGETS_SET -> {
                pullTargets(translation)
                currentState = State.PULLING
@@ -131,7 +135,6 @@ constructor(
                val swiped = currentMagneticListeners.swipedListener()
                swiped?.setMagneticTranslation(translation)
            }
            else -> {}
        }
        return true
    }