Loading packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt +29 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) Loading packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt +6 −1 Original line number Diff line number Diff line Loading @@ -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() } } Loading packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() } } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt +29 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) Loading
packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt +6 −1 Original line number Diff line number Diff line Loading @@ -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() } } Loading
packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() } } Loading