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

Commit 303fd057 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert currentFling to a SharedFlow." into main

parents ad646f08 db329c62
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.StatusBarState.KEYGUARD
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat as assertThatRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.shade.data.repository.FlingInfo
import com.android.systemui.shade.data.repository.fakeShadeRepository
@@ -47,7 +48,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.reset
import org.mockito.Mockito.spy
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat as assertThatRepository

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -55,9 +55,8 @@ import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject
class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
    private val kosmos =
        testKosmos().apply {
            this.fakeKeyguardTransitionRepository = spy(FakeKeyguardTransitionRepository(
                testScope = testScope,
            ))
            this.fakeKeyguardTransitionRepository =
                spy(FakeKeyguardTransitionRepository(testScope = testScope))
        }

    private val testScope = kosmos.testScope
@@ -181,6 +180,12 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
            underTest.start()
            assertThatRepository(transitionRepository).noTransitionsStarted()

            transitionRepository.sendTransitionSteps(
                from = KeyguardState.DOZING,
                to = KeyguardState.LOCKSCREEN,
                testScope = testScope,
            )

            keyguardRepository.setKeyguardDismissible(true)
            runCurrent()
            shadeRepository.setCurrentFling(
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class ShadeRepositoryImplTest : SysuiTestCase() {

    @Before
    fun setUp() {
        underTest = ShadeRepositoryImpl()
        underTest = ShadeRepositoryImpl(testScope)
    }

    @Test
+18 −5
Original line number Diff line number Diff line
@@ -15,11 +15,18 @@
 */
package com.android.systemui.shade.data.repository

import android.annotation.SuppressLint
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

/** Data for the shade, mostly related to expansion of the shade and quick settings. */
interface ShadeRepository {
@@ -36,7 +43,7 @@ interface ShadeRepository {
     * Information about the currently running fling animation, or null if no fling animation is
     * running.
     */
    val currentFling: StateFlow<FlingInfo?>
    val currentFling: SharedFlow<FlingInfo?>

    /**
     * The amount the lockscreen shade has dragged down by the user, [0-1]. 0 means fully collapsed,
@@ -180,7 +187,8 @@ interface ShadeRepository {

/** Business logic for shade interactions */
@SysUISingleton
class ShadeRepositoryImpl @Inject constructor() : ShadeRepository {
class ShadeRepositoryImpl @Inject constructor(@Background val backgroundScope: CoroutineScope) :
    ShadeRepository {
    private val _qsExpansion = MutableStateFlow(0f)
    @Deprecated("Use ShadeInteractor.qsExpansion instead")
    override val qsExpansion: StateFlow<Float> = _qsExpansion.asStateFlow()
@@ -193,8 +201,13 @@ class ShadeRepositoryImpl @Inject constructor() : ShadeRepository {
    override val udfpsTransitionToFullShadeProgress: StateFlow<Float> =
        _udfpsTransitionToFullShadeProgress.asStateFlow()

    private val _currentFling: MutableStateFlow<FlingInfo?> = MutableStateFlow(null)
    override val currentFling: StateFlow<FlingInfo?> = _currentFling.asStateFlow()
    /**
     * Must be a SharedFlow, since the fling is by definition an event and dropping it has extreme
     * consequences in some cases (for example, keyguard uses this to decide when to unlock).
     */
    @SuppressLint("SharedFlowCreation")
    override val currentFling: MutableSharedFlow<FlingInfo?> =
        MutableSharedFlow(replay = 2, onBufferOverflow = BufferOverflow.DROP_OLDEST)

    private val _legacyShadeExpansion = MutableStateFlow(0f)
    @Deprecated("Use ShadeInteractor.shadeExpansion instead")
@@ -294,7 +307,7 @@ class ShadeRepositoryImpl @Inject constructor() : ShadeRepository {
    }

    override fun setCurrentFling(info: FlingInfo?) {
        _currentFling.value = info
        backgroundScope.launch { currentFling.emit(info) }
    }

    @Deprecated("Should only be called by NPVC and tests")
+5 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import com.android.systemui.dagger.SysUISingleton
import dagger.Binds
import dagger.Module
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -37,8 +39,8 @@ class FakeShadeRepository @Inject constructor() : ShadeRepository {
    override val udfpsTransitionToFullShadeProgress =
        _udfpsTransitionToFullShadeProgress.asStateFlow()

    private val _currentFling: MutableStateFlow<FlingInfo?> = MutableStateFlow(null)
    override val currentFling: StateFlow<FlingInfo?> = _currentFling.asStateFlow()
    override val currentFling: MutableSharedFlow<FlingInfo?> =
        MutableSharedFlow(replay = 2, onBufferOverflow = BufferOverflow.DROP_OLDEST)

    private val _lockscreenShadeExpansion = MutableStateFlow(0f)
    override val lockscreenShadeExpansion = _lockscreenShadeExpansion.asStateFlow()
@@ -139,7 +141,7 @@ class FakeShadeRepository @Inject constructor() : ShadeRepository {
    }

    override fun setCurrentFling(info: FlingInfo?) {
        _currentFling.value = info
        currentFling.tryEmit(info)
    }

    override fun setLockscreenShadeExpansion(lockscreenShadeExpansion: Float) {