diff options
3 files changed, 42 insertions, 3 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt index 354edac75452..36e18e653f20 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt @@ -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) diff --git a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt index cd401d5deb6e..e1640cd4ce7a 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt @@ -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() } } diff --git a/packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt b/packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt index 6ac0bb168f18..91f142646c3d 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/NoCooldownDisplaySwitchLatencyTracker.kt @@ -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() } } |