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

Commit b17b6a34 authored by Bharat Singh's avatar Bharat Singh
Browse files

Revert "[SysUI][Floaty] Add flow to detect lpp in sysui"

This reverts commit 4ff5ee1c.

Reason for revert: Cleanup, not needed anymore

Bug: 399263897
Test: NONE revert
Flag: NONE revert
Change-Id: I6bb40ec9b24a61d633c2783e829c4821674f24a1
parent 914ac9af
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -57,17 +57,4 @@ class KeyEventInteractorTest : SysuiTestCase() {
            repository.setPowerButtonDown(true)
            assertThat(isPowerDown).isTrue()
        }

    @Test
    fun testPowerButtonBeingLongPressedInteractor() =
        runTest {
            val isPowerButtonLongPressed by collectLastValue(
                underTest.isPowerButtonLongPressed)

            repository.setPowerButtonLongPressed(false)
            assertThat(isPowerButtonLongPressed).isFalse()

            repository.setPowerButtonLongPressed(true)
            assertThat(isPowerButtonLongPressed).isTrue()
        }
}
+0 −63
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyevent.data.repository.KeyEventRepositoryImpl
import com.android.systemui.statusbar.CommandQueue
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
@@ -39,7 +38,6 @@ import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class KeyEventRepositoryTest : SysuiTestCase() {
@@ -66,14 +64,6 @@ class KeyEventRepositoryTest : SysuiTestCase() {
            assertThat(isPowerButtonDown).isFalse()
        }

    @Test
    fun isPowerButtonBeingLongPressed_initialValueFalse() =
        testScope.runTest {
            val isPowerButtonLongPressed by collectLastValue(underTest.isPowerButtonLongPressed)
            runCurrent()
            assertThat(isPowerButtonLongPressed).isFalse()
        }

    @Test
    fun isPowerButtonDown_onChange() =
        testScope.runTest {
@@ -99,57 +89,4 @@ class KeyEventRepositoryTest : SysuiTestCase() {

            assertThat(underTest.isPowerButtonDown.value).isFalse()
        }


    @Test
    fun isPowerButtonBeingLongPressed_onPowerButtonDown() =
        testScope.runTest {
            underTest.isPowerButtonLongPressed.launchIn(testScope.backgroundScope)

            runCurrent()

            verify(commandQueue).addCallback(commandQueueCallbacks.capture())

            val keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER)
            commandQueueCallbacks.value.handleSystemKey(keyEvent)

            runCurrent()

            assertThat(underTest.isPowerButtonLongPressed.value).isFalse()
        }

    @Test
    fun isPowerButtonBeingLongPressed_onPowerButtonUp() =
        testScope.runTest {
            underTest.isPowerButtonLongPressed.launchIn(testScope.backgroundScope)

            runCurrent()

            verify(commandQueue).addCallback(commandQueueCallbacks.capture())

            val keyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_POWER)
            commandQueueCallbacks.value.handleSystemKey(keyEvent)

            runCurrent()

            assertThat(underTest.isPowerButtonLongPressed.value).isFalse()
        }

    @Test
    fun isPowerButtonBeingLongPressed_onPowerButtonDown_longPressFlagSet() =
        testScope.runTest {
            underTest.isPowerButtonLongPressed.launchIn(testScope.backgroundScope)

            runCurrent()

            verify(commandQueue).addCallback(commandQueueCallbacks.capture())

            val keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER)
            keyEvent.setFlags(KeyEvent.FLAG_LONG_PRESS)
            commandQueueCallbacks.value.handleSystemKey(keyEvent)

            runCurrent()

            assertThat(underTest.isPowerButtonLongPressed.value).isTrue()
        }
}
+3 −26
Original line number Diff line number Diff line
@@ -22,20 +22,17 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

/** Defines interface for classes that encapsulate application state for key event presses. */
interface KeyEventRepository {
    /** Observable for whether the power button key is pressed/down or not. */
    val isPowerButtonDown: StateFlow<Boolean>

    /** Observable for when the power button is being pressed but till the duration of long press */
    val isPowerButtonLongPressed: StateFlow<Boolean>
    val isPowerButtonDown: Flow<Boolean>
}

@SysUISingleton
@@ -65,26 +62,6 @@ constructor(
            initialValue = false
        )

    override val isPowerButtonLongPressed =
        conflatedCallbackFlow {
            val callback = object : CommandQueue.Callbacks {
                    override fun handleSystemKey(event: KeyEvent) {
                        if (event.keyCode == KeyEvent.KEYCODE_POWER) {
                            trySendWithFailureLogging(event.action == KeyEvent.ACTION_DOWN
                                    && event.isLongPress, TAG, "updated isPowerButtonLongPressed")
                        }
                    }
                }
            trySendWithFailureLogging(false, TAG, "init isPowerButtonLongPressed")
            commandQueue.addCallback(callback)
            awaitClose { commandQueue.removeCallback(callback) }
        }
        .stateIn(
            scope = applicationScope,
            started = SharingStarted.WhileSubscribed(),
            initialValue = false
        )

    companion object {
        private const val TAG = "KeyEventRepositoryImpl"
    }
+0 −1
Original line number Diff line number Diff line
@@ -32,5 +32,4 @@ constructor(
    repository: KeyEventRepository,
) {
    val isPowerButtonDown = repository.isPowerButtonDown
    val isPowerButtonLongPressed = repository.isPowerButtonLongPressed
}
+0 −7
Original line number Diff line number Diff line
@@ -27,16 +27,9 @@ class FakeKeyEventRepository @Inject constructor() : KeyEventRepository {
    private val _isPowerButtonDown = MutableStateFlow(false)
    override val isPowerButtonDown: StateFlow<Boolean> = _isPowerButtonDown.asStateFlow()

    private val _isPowerButtonLongPressed = MutableStateFlow(false)
    override val isPowerButtonLongPressed = _isPowerButtonLongPressed.asStateFlow()

    fun setPowerButtonDown(isDown: Boolean) {
        _isPowerButtonDown.value = isDown
    }

    fun setPowerButtonLongPressed(isLongPressed: Boolean) {
        _isPowerButtonLongPressed.value = isLongPressed
    }
}

@Module