diff options
3 files changed, 92 insertions, 11 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadStatsInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadStatsInteractorTest.kt index cd0c58feebed..c4fc13227eef 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadStatsInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadStatsInteractorTest.kt @@ -19,12 +19,15 @@ package com.android.systemui.education.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.contextualeducation.GestureType.ALL_APPS import com.android.systemui.contextualeducation.GestureType.BACK +import com.android.systemui.coroutines.collectLastValue import com.android.systemui.education.data.repository.contextualEducationRepository import com.android.systemui.education.data.repository.fakeEduClock +import com.android.systemui.keyboard.data.repository.keyboardRepository import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos +import com.android.systemui.touchpad.data.repository.touchpadRepository import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest import org.junit.Test @@ -36,22 +39,62 @@ class KeyboardTouchpadStatsInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val underTest = kosmos.keyboardTouchpadEduStatsInteractor + private val keyboardRepository = kosmos.keyboardRepository + private val touchpadRepository = kosmos.touchpadRepository + private val repository = kosmos.contextualEducationRepository @Test - fun dataUpdatedOnIncrementSignalCount() = + fun dataUpdatedOnIncrementSignalCountWhenTouchpadConnected() = testScope.runTest { - val model by - collectLastValue(kosmos.contextualEducationRepository.readGestureEduModelFlow(BACK)) + touchpadRepository.setIsAnyTouchpadConnected(true) + + val model by collectLastValue(repository.readGestureEduModelFlow(BACK)) val originalValue = model!!.signalCount underTest.incrementSignalCount(BACK) + assertThat(model?.signalCount).isEqualTo(originalValue + 1) } @Test + fun dataUnchangedOnIncrementSignalCountWhenTouchpadDisconnected() = + testScope.runTest { + touchpadRepository.setIsAnyTouchpadConnected(false) + + val model by collectLastValue(repository.readGestureEduModelFlow(BACK)) + val originalValue = model!!.signalCount + underTest.incrementSignalCount(BACK) + + assertThat(model?.signalCount).isEqualTo(originalValue) + } + + @Test + fun dataUpdatedOnIncrementSignalCountWhenKeyboardConnected() = + testScope.runTest { + keyboardRepository.setIsAnyKeyboardConnected(true) + + val model by collectLastValue(repository.readGestureEduModelFlow(ALL_APPS)) + val originalValue = model!!.signalCount + underTest.incrementSignalCount(ALL_APPS) + + assertThat(model?.signalCount).isEqualTo(originalValue + 1) + } + + @Test + fun dataUnchangedOnIncrementSignalCountWhenKeyboardDisconnected() = + testScope.runTest { + keyboardRepository.setIsAnyKeyboardConnected(false) + + val model by collectLastValue(repository.readGestureEduModelFlow(ALL_APPS)) + val originalValue = model!!.signalCount + underTest.incrementSignalCount(ALL_APPS) + + assertThat(model?.signalCount).isEqualTo(originalValue) + } + + @Test fun dataAddedOnUpdateShortcutTriggerTime() = testScope.runTest { - val model by - collectLastValue(kosmos.contextualEducationRepository.readGestureEduModelFlow(BACK)) + val model by collectLastValue(repository.readGestureEduModelFlow(BACK)) assertThat(model?.lastShortcutTriggeredTime).isNull() underTest.updateShortcutTriggerTime(BACK) assertThat(model?.lastShortcutTriggeredTime).isEqualTo(kosmos.fakeEduClock.instant()) diff --git a/packages/SystemUI/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduStatsInteractor.kt b/packages/SystemUI/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduStatsInteractor.kt index 3223433568b9..eb4eee204834 100644 --- a/packages/SystemUI/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduStatsInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduStatsInteractor.kt @@ -16,11 +16,17 @@ package com.android.systemui.education.domain.interactor +import com.android.systemui.contextualeducation.GestureType +import com.android.systemui.contextualeducation.GestureType.ALL_APPS import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background -import com.android.systemui.contextualeducation.GestureType +import com.android.systemui.inputdevice.data.repository.UserInputDeviceRepository +import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType +import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.KEYBOARD +import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.TOUCHPAD import javax.inject.Inject import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch /** @@ -39,12 +45,17 @@ class KeyboardTouchpadEduStatsInteractorImpl @Inject constructor( @Background private val backgroundScope: CoroutineScope, - private val contextualEducationInteractor: ContextualEducationInteractor + private val contextualEducationInteractor: ContextualEducationInteractor, + private val inputDeviceRepository: UserInputDeviceRepository, ) : KeyboardTouchpadEduStatsInteractor { override fun incrementSignalCount(gestureType: GestureType) { - // Todo: check if keyboard/touchpad is connected before update - backgroundScope.launch { contextualEducationInteractor.incrementSignalCount(gestureType) } + backgroundScope.launch { + val targetDevice = getTargetDevice(gestureType) + if (isTargetDeviceConnected(targetDevice)) { + contextualEducationInteractor.incrementSignalCount(gestureType) + } + } } override fun updateShortcutTriggerTime(gestureType: GestureType) { @@ -52,4 +63,24 @@ constructor( contextualEducationInteractor.updateShortcutTriggerTime(gestureType) } } + + private suspend fun isTargetDeviceConnected(deviceType: DeviceType): Boolean { + if (deviceType == KEYBOARD) { + return inputDeviceRepository.isAnyKeyboardConnectedForUser.first().isConnected + } else if (deviceType == TOUCHPAD) { + return inputDeviceRepository.isAnyTouchpadConnectedForUser.first().isConnected + } + return false + } + + /** + * Keyboard shortcut education would be provided for All Apps. Touchpad gesture education would + * be provided for the rest of the gesture types (i.e. Home, Overview, Back). This method maps + * gesture to its target education device. + */ + private fun getTargetDevice(gestureType: GestureType) = + when (gestureType) { + ALL_APPS -> KEYBOARD + else -> TOUCHPAD + } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorKosmos.kt index 811c6533c656..251a6b10a0da 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorKosmos.kt @@ -50,6 +50,13 @@ var Kosmos.keyboardTouchpadEduStatsInteractor by Kosmos.Fixture { KeyboardTouchpadEduStatsInteractorImpl( backgroundScope = testScope.backgroundScope, - contextualEducationInteractor = contextualEducationInteractor + contextualEducationInteractor = contextualEducationInteractor, + inputDeviceRepository = + UserInputDeviceRepository( + testDispatcher, + keyboardRepository, + touchpadRepository, + userRepository + ) ) } |