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

Commit 2f019322 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Waiting for a new display state when tracking display switch latency" into main

parents 84fedfd2 055512db
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import com.android.systemui.unfold.data.repository.UnfoldTransitionRepositoryImp
import com.android.systemui.unfold.domain.interactor.UnfoldTransitionInteractor
import com.android.systemui.unfoldedDeviceState
import com.android.systemui.util.animation.data.repository.fakeAnimationStatusRepository
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
@@ -79,8 +78,10 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyNoMoreInteractions

@RunWith(AndroidJUnit4::class)
@SmallTest
@@ -603,12 +604,39 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
        }
    }

    @Test
    fun foldingStarted_screenStillOn_eventSentOnlyAfterScreenSwitches() {
        // can happen for both folding and unfolding (with animations off) but it's more likely to
        // happen when folding as waiting for screen on is the default case then
        testScope.runTest {
            startInUnfoldedState(displaySwitchLatencyTracker)
            setDeviceState(FOLDED)
            powerInteractor.setScreenPowerState(SCREEN_ON)
            runCurrent()

            verifyNoMoreInteractions(displaySwitchLatencyLogger)

            powerInteractor.setScreenPowerState(SCREEN_OFF)
            runCurrent()
            powerInteractor.setScreenPowerState(SCREEN_ON)
            runCurrent()

            verify(displaySwitchLatencyLogger).log(any())
        }
    }

    private suspend fun TestScope.startInFoldedState(tracker: DisplaySwitchLatencyTracker) {
        setDeviceState(FOLDED)
        tracker.start()
        runCurrent()
    }

    private suspend fun TestScope.startInUnfoldedState(tracker: DisplaySwitchLatencyTracker) {
        setDeviceState(UNFOLDED)
        tracker.start()
        runCurrent()
    }

    private suspend fun TestScope.startUnfolding() {
        setDeviceState(HALF_FOLDED)
        powerInteractor.setScreenPowerState(SCREEN_OFF)
+6 −1
Original line number Diff line number Diff line
@@ -214,7 +214,12 @@ constructor(

    private suspend fun waitForScreenTurnedOn() {
        traceAsync(TAG, "waitForScreenTurnedOn()") {
            powerInteractor.screenPowerState.filter { it == ScreenPowerState.SCREEN_ON }.first()
            // dropping first as it's stateFlow and will always emit latest value but we're
            // only interested in new states
            powerInteractor.screenPowerState
                .drop(1)
                .filter { it == ScreenPowerState.SCREEN_ON }
                .first()
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
@@ -160,7 +161,12 @@ constructor(

    private suspend fun waitForScreenTurnedOn() {
        traceAsync(TAG, "waitForScreenTurnedOn()") {
            powerInteractor.screenPowerState.filter { it == ScreenPowerState.SCREEN_ON }.first()
            // dropping first as it's stateFlow and will always emit latest value but we're
            // only interested in new states
            powerInteractor.screenPowerState
                .drop(1)
                .filter { it == ScreenPowerState.SCREEN_ON }
                .first()
        }
    }