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

Commit 0d9b17ae authored by Bharat Singh's avatar Bharat Singh
Browse files

Revert "[SysUI][Floaty] Move power button pressed and long pressed to StateFlow"

This reverts commit ee354c9b.

Reason for revert: Cleanup, not needed anymore

Bug: 399263897
Test: NONE revert
Flag: NONE revert
Change-Id: Ica545f3074fbf8ea06d6192dc08ee8aa6b8dee7c
parent b17b6a34
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -41,10 +41,7 @@ class KeyEventInteractorTest : SysuiTestCase() {
    @Before
    fun setup() {
        repository = FakeKeyEventRepository()
        underTest =
            KeyEventInteractor(
                repository,
            )
        underTest = KeyEventInteractor(repository)
    }

    @Test
+4 −17
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.flow.launchIn
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -50,10 +49,7 @@ class KeyEventRepositoryTest : SysuiTestCase() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        testScope = TestScope()
        underTest = KeyEventRepositoryImpl(
            commandQueue = commandQueue,
            applicationScope = testScope.backgroundScope
        )
        underTest = KeyEventRepositoryImpl(commandQueue)
    }

    @Test
@@ -67,26 +63,17 @@ class KeyEventRepositoryTest : SysuiTestCase() {
    @Test
    fun isPowerButtonDown_onChange() =
        testScope.runTest {
            underTest.isPowerButtonDown.launchIn(testScope.backgroundScope)

            val isPowerButtonDown by collectLastValue(underTest.isPowerButtonDown)
            runCurrent()

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

            commandQueueCallbacks.value.handleSystemKey(
                KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER)
            )

            runCurrent()

            assertThat(underTest.isPowerButtonDown.value).isTrue()
            assertThat(isPowerButtonDown).isTrue()

            commandQueueCallbacks.value.handleSystemKey(
                KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_POWER)
            )

            runCurrent()

            assertThat(underTest.isPowerButtonDown.value).isFalse()
            assertThat(isPowerButtonDown).isFalse()
        }
}
+13 −27
Original line number Diff line number Diff line
@@ -19,15 +19,11 @@ package com.android.systemui.keyevent.data.repository
import android.view.KeyEvent
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
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.stateIn

/** Defines interface for classes that encapsulate application state for key event presses. */
interface KeyEventRepository {
@@ -36,19 +32,14 @@ interface KeyEventRepository {
}

@SysUISingleton
class KeyEventRepositoryImpl
@Inject
constructor(
    private val commandQueue: CommandQueue,
    @Application applicationScope: CoroutineScope
) : KeyEventRepository {
    override val isPowerButtonDown =
        conflatedCallbackFlow {
            val callback = object : CommandQueue.Callbacks {
class KeyEventRepositoryImpl @Inject constructor(private val commandQueue: CommandQueue) :
    KeyEventRepository {
    override val isPowerButtonDown: Flow<Boolean> = conflatedCallbackFlow {
        val callback =
            object : CommandQueue.Callbacks {
                override fun handleSystemKey(event: KeyEvent) {
                    if (event.keyCode == KeyEvent.KEYCODE_POWER) {
                            trySendWithFailureLogging(event.action == KeyEvent.ACTION_DOWN,
                                TAG, "updated isPowerButtonDown")
                        trySendWithFailureLogging(event.isDown, TAG, "updated isPowerButtonDown")
                    }
                }
            }
@@ -56,11 +47,6 @@ constructor(
        commandQueue.addCallback(callback)
        awaitClose { commandQueue.removeCallback(callback) }
    }
        .stateIn(
            scope = applicationScope,
            started = SharingStarted.WhileSubscribed(),
            initialValue = false
        )

    companion object {
        private const val TAG = "KeyEventRepositoryImpl"
+1 −5
Original line number Diff line number Diff line
@@ -26,10 +26,6 @@ import javax.inject.Inject
 * For key events that SysUI wants to properly handle, see [SysUIKeyEventHandler].
 */
@SysUISingleton
class KeyEventInteractor
@Inject
constructor(
    repository: KeyEventRepository,
) {
class KeyEventInteractor @Inject constructor(repository: KeyEventRepository) {
    val isPowerButtonDown = repository.isPowerButtonDown
}
+3 −3
Original line number Diff line number Diff line
@@ -18,14 +18,14 @@ package com.android.systemui.keyevent.data.repository

import dagger.Binds
import dagger.Module
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

class FakeKeyEventRepository @Inject constructor() : KeyEventRepository {
    private val _isPowerButtonDown = MutableStateFlow(false)
    override val isPowerButtonDown: StateFlow<Boolean> = _isPowerButtonDown.asStateFlow()
    override val isPowerButtonDown: Flow<Boolean> = _isPowerButtonDown.asStateFlow()

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