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

Commit 887d5fb0 authored by helencheuk's avatar helencheuk
Browse files

[Contextual Edu] Check OOBE notify time when no launch time

Check notify time for calculating initial delay of education when there is no launch time yet

Bug: 387992147
Test: KeyboardTouchpadEduInteractorParameterizedTest
Flag: com.android.systemui.keyboard_touchpad_contextual_education
Change-Id: If473ca36fa73498208b22447b402044c921e2ee1
parent 5104717e
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ filegroup {
        "tests/src/**/systemui/shade/NotificationShadeWindowViewControllerTest.kt",
        "tests/src/**/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorSceneContainerTest.kt",
        "tests/src/**/systemui/statusbar/pipeline/mobile/ui/model/SignalIconModelParameterizedTest.kt",
        "tests/src/**/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorTest.kt",
        "tests/src/**/systemui/biometrics/udfps/SinglePointerTouchProcessorTest.kt",
        "tests/src/**/systemui/animation/back/FlingOnBackAnimationCallbackTest.kt",
        "tests/src/**/systemui/education/domain/ui/view/ContextualEduDialogTest.kt",
+81 −22
Original line number Diff line number Diff line
@@ -292,8 +292,7 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue + 1)
        }
@@ -306,8 +305,7 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue)
        }
@@ -321,8 +319,7 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue + 1)
        }
@@ -335,8 +332,7 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue)
        }
@@ -347,8 +343,7 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge
            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            assertThat(model?.lastShortcutTriggeredTime).isNull()

            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ true, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ true, gestureType)

            assertThat(model?.lastShortcutTriggeredTime).isEqualTo(kosmos.fakeEduClock.instant())
        }
@@ -358,15 +353,14 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge
        testScope.runTest {
            setUpForDeviceConnection()
            tutorialSchedulerRepository.setScheduledTutorialLaunchTime(
                DeviceType.TOUCHPAD,
                getTargetDevice(gestureType),
                eduClock.instant(),
            )

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            eduClock.offset(initialDelayElapsedDuration)
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue + 1)
        }
@@ -376,33 +370,92 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge
        testScope.runTest {
            setUpForDeviceConnection()
            tutorialSchedulerRepository.setScheduledTutorialLaunchTime(
                DeviceType.TOUCHPAD,
                getTargetDevice(gestureType),
                eduClock.instant(),
            )

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            // No offset to the clock to simulate update before initial delay
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue)
        }

    @Test
    fun dataUnchangedOnIncrementSignalCountWithoutOobeLaunchTime() =
    fun dataUnchangedOnIncrementSignalCountWithoutOobeLaunchOrNotifyTime() =
        testScope.runTest {
            // No update to OOBE launch/notify time to simulate no OOBE is launched yet
            setUpForDeviceConnection()

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue)
        }

    @Test
    fun dataUpdatedOnIncrementSignalCountAfterNotifyTimeDelayWithoutLaunchTime() =
        testScope.runTest {
            setUpForDeviceConnection()
            tutorialSchedulerRepository.setNotifiedTime(
                getTargetDevice(gestureType),
                eduClock.instant(),
            )

            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            eduClock.offset(initialDelayElapsedDuration)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue + 1)
        }

    @Test
    fun dataUnchangedOnIncrementSignalCountBeforeLaunchTimeDelayWithNotifyTime() =
        testScope.runTest {
            // No update to OOBE launch time to simulate no OOBE is launched yet
            setUpForDeviceConnection()
            tutorialSchedulerRepository.setNotifiedTime(
                getTargetDevice(gestureType),
                eduClock.instant(),
            )
            eduClock.offset(initialDelayElapsedDuration)

            tutorialSchedulerRepository.setScheduledTutorialLaunchTime(
                getTargetDevice(gestureType),
                eduClock.instant(),
            )
            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            val listener = getOverviewProxyListener()
            listener.updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)
            // No offset to the clock to simulate update before initial delay of launch time
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue)
        }

    @Test
    fun dataUpdatedOnIncrementSignalCountAfterLaunchTimeDelayWithNotifyTime() =
        testScope.runTest {
            setUpForDeviceConnection()
            tutorialSchedulerRepository.setNotifiedTime(
                getTargetDevice(gestureType),
                eduClock.instant(),
            )
            eduClock.offset(initialDelayElapsedDuration)

            tutorialSchedulerRepository.setScheduledTutorialLaunchTime(
                getTargetDevice(gestureType),
                eduClock.instant(),
            )
            val model by collectLastValue(repository.readGestureEduModelFlow(gestureType))
            val originalValue = model!!.signalCount
            eduClock.offset(initialDelayElapsedDuration)
            updateContextualEduStats(/* isTrackpadGesture= */ false, gestureType)

            assertThat(model?.signalCount).isEqualTo(originalValue + 1)
        }

    private suspend fun setUpForInitialDelayElapse() {
        tutorialSchedulerRepository.setScheduledTutorialLaunchTime(
            DeviceType.TOUCHPAD,
@@ -465,10 +518,16 @@ class KeyboardTouchpadEduInteractorParameterizedTest(private val gestureType: Ge
        keyboardRepository.setIsAnyKeyboardConnected(true)
    }

    private fun getOverviewProxyListener(): OverviewProxyListener {
    private fun updateContextualEduStats(isTrackpadGesture: Boolean, gestureType: GestureType) {
        val listenerCaptor = argumentCaptor<OverviewProxyListener>()
        verify(overviewProxyService).addCallback(listenerCaptor.capture())
        return listenerCaptor.firstValue
        listenerCaptor.firstValue.updateContextualEduStats(isTrackpadGesture, gestureType)
    }

    private fun getTargetDevice(gestureType: GestureType) =
        when (gestureType) {
            ALL_APPS -> DeviceType.KEYBOARD
            else -> DeviceType.TOUCHPAD
        }

    companion object {
+0 −0

File moved.

+5 −5
Original line number Diff line number Diff line
@@ -278,11 +278,11 @@ constructor(
        }

    private suspend fun hasInitialDelayElapsed(deviceType: DeviceType): Boolean {
        val oobeLaunchTime =
            tutorialRepository.getScheduledTutorialLaunchTime(deviceType) ?: return false
        return clock
            .instant()
            .isAfter(oobeLaunchTime.plusSeconds(initialDelayDuration.inWholeSeconds))
        val oobeTime =
            tutorialRepository.getScheduledTutorialLaunchTime(deviceType)
                ?: tutorialRepository.getNotifiedTime(deviceType)
                ?: return false
        return clock.instant().isAfter(oobeTime.plusSeconds(initialDelayDuration.inWholeSeconds))
    }

    private data class StatsUpdateRequest(