From f63aff7141913ed07e9c64664ccc24dfd123adcb Mon Sep 17 00:00:00 2001 From: yyalan Date: Tue, 29 Oct 2024 12:23:47 +0000 Subject: adb command to reset and print out TutorialSchedulerRepository info Bug: 375382622 Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial Test: adb command Change-Id: I0e30ba5a4d3e3d7bbbcb538847e6bbbd231ee34a --- .../KeyboardTouchpadEduInteractorTest.kt | 2 +- .../repository/TutorialSchedulerRepositoryTest.kt | 4 +-- .../TutorialNotificationCoordinatorTest.kt | 8 +++-- .../interactor/TutorialSchedulerInteractorTest.kt | 8 +++-- .../data/repository/TutorialSchedulerRepository.kt | 12 +++---- .../interactor/TutorialSchedulerInteractor.kt | 41 ++++++++++++++++++++++ 6 files changed, 59 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorTest.kt index 21679f960198..2a6d29c61890 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/education/domain/interactor/KeyboardTouchpadEduInteractorTest.kt @@ -427,7 +427,7 @@ class KeyboardTouchpadEduInteractorTest(private val gestureType: GestureType) : @After fun clear() { - testScope.launch { tutorialSchedulerRepository.clearDataStore() } + testScope.launch { tutorialSchedulerRepository.clear() } } private suspend fun triggerMaxEducationSignals(gestureType: GestureType) { diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/data/repository/TutorialSchedulerRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/data/repository/TutorialSchedulerRepositoryTest.kt index 1d96c4d67c77..8bb6962a2d8e 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/data/repository/TutorialSchedulerRepositoryTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/data/repository/TutorialSchedulerRepositoryTest.kt @@ -47,13 +47,13 @@ class TutorialSchedulerRepositoryTest : SysuiTestCase() { TutorialSchedulerRepository( context, testScope.backgroundScope, - "TutorialSchedulerRepositoryTest" + "TutorialSchedulerRepositoryTest", ) } @After fun clear() { - testScope.launch { underTest.clearDataStore() } + testScope.launch { underTest.clear() } } @Test diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialNotificationCoordinatorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialNotificationCoordinatorTest.kt index 38e4ae101d06..bcac086033ed 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialNotificationCoordinatorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialNotificationCoordinatorTest.kt @@ -26,10 +26,11 @@ import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedul import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger import com.android.systemui.inputdevice.tutorial.ui.TutorialNotificationCoordinator import com.android.systemui.keyboard.data.repository.FakeKeyboardRepository -import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope import com.android.systemui.res.R import com.android.systemui.settings.userTracker +import com.android.systemui.statusbar.commandline.commandRegistry +import com.android.systemui.testKosmos import com.android.systemui.touchpad.data.repository.FakeTouchpadRepository import com.google.common.truth.Truth.assertThat import kotlin.time.Duration.Companion.hours @@ -60,7 +61,7 @@ import org.mockito.kotlin.verify class TutorialNotificationCoordinatorTest : SysuiTestCase() { private lateinit var underTest: TutorialNotificationCoordinator - private val kosmos = Kosmos() + private val kosmos = testKosmos() private val testScope = kosmos.testScope private val keyboardRepository = FakeKeyboardRepository() private val touchpadRepository = FakeTouchpadRepository() @@ -85,6 +86,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() { touchpadRepository, repository, kosmos.inputDeviceTutorialLogger, + kosmos.commandRegistry, ) underTest = TutorialNotificationCoordinator( @@ -100,7 +102,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() { @After fun clear() { - runBlocking { repository.clearDataStore() } + runBlocking { repository.clear() } dataStoreScope.cancel() } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractorTest.kt index b0ffc47cbc6c..5df9b7b8d5b8 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractorTest.kt @@ -24,8 +24,9 @@ import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedul import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger import com.android.systemui.keyboard.data.repository.FakeKeyboardRepository -import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope +import com.android.systemui.statusbar.commandline.commandRegistry +import com.android.systemui.testKosmos import com.android.systemui.touchpad.data.repository.FakeTouchpadRepository import com.google.common.truth.Truth.assertThat import kotlin.time.Duration.Companion.hours @@ -49,7 +50,7 @@ import org.junit.runner.RunWith class TutorialSchedulerInteractorTest : SysuiTestCase() { private lateinit var underTest: TutorialSchedulerInteractor - private val kosmos = Kosmos() + private val kosmos = testKosmos() private val testScope = kosmos.testScope private lateinit var dataStoreScope: CoroutineScope private val keyboardRepository = FakeKeyboardRepository() @@ -71,12 +72,13 @@ class TutorialSchedulerInteractorTest : SysuiTestCase() { touchpadRepository, schedulerRepository, kosmos.inputDeviceTutorialLogger, + kosmos.commandRegistry, ) } @After fun clear() { - runBlocking { schedulerRepository.clearDataStore() } + runBlocking { schedulerRepository.clear() } dataStoreScope.cancel() } diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/repository/TutorialSchedulerRepository.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/repository/TutorialSchedulerRepository.kt index d8d4bd686f07..a89ec7076e93 100644 --- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/repository/TutorialSchedulerRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/repository/TutorialSchedulerRepository.kt @@ -17,7 +17,6 @@ package com.android.systemui.inputdevice.tutorial.data.repository import android.content.Context -import androidx.annotation.VisibleForTesting import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit @@ -37,12 +36,12 @@ import kotlinx.coroutines.flow.map class TutorialSchedulerRepository( private val applicationContext: Context, backgroundScope: CoroutineScope, - dataStoreName: String + dataStoreName: String, ) { @Inject constructor( @Application applicationContext: Context, - @Background backgroundScope: CoroutineScope + @Background backgroundScope: CoroutineScope, ) : this(applicationContext, backgroundScope, dataStoreName = DATASTORE_NAME) private val Context.dataStore: DataStore by @@ -73,7 +72,7 @@ class TutorialSchedulerRepository( private fun getSchedulerInfo(pref: Preferences): Map { return mapOf( DeviceType.KEYBOARD to getDeviceSchedulerInfo(pref, DeviceType.KEYBOARD), - DeviceType.TOUCHPAD to getDeviceSchedulerInfo(pref, DeviceType.TOUCHPAD) + DeviceType.TOUCHPAD to getDeviceSchedulerInfo(pref, DeviceType.TOUCHPAD), ) } @@ -89,8 +88,7 @@ class TutorialSchedulerRepository( private fun getConnectKey(device: DeviceType) = longPreferencesKey(device.name + CONNECT_TIME_SUFFIX) - @VisibleForTesting - suspend fun clearDataStore() { + suspend fun clear() { applicationContext.dataStore.edit { it.clear() } } @@ -103,5 +101,5 @@ class TutorialSchedulerRepository( enum class DeviceType { KEYBOARD, - TOUCHPAD + TOUCHPAD, } diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractor.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractor.kt index 3b4d00db1a74..4a369e7e849e 100644 --- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/domain/interactor/TutorialSchedulerInteractor.kt @@ -24,7 +24,10 @@ import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.KEYB import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.TOUCHPAD import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedulerRepository import com.android.systemui.keyboard.data.repository.KeyboardRepository +import com.android.systemui.statusbar.commandline.Command +import com.android.systemui.statusbar.commandline.CommandRegistry import com.android.systemui.touchpad.data.repository.TouchpadRepository +import java.io.PrintWriter import java.time.Duration import java.time.Instant import javax.inject.Inject @@ -37,6 +40,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge +import kotlinx.coroutines.runBlocking /** * When the first time a keyboard or touchpad is connected, wait for [LAUNCH_DELAY], and as soon as @@ -50,7 +54,12 @@ constructor( touchpadRepository: TouchpadRepository, private val repo: TutorialSchedulerRepository, private val logger: InputDeviceTutorialLogger, + commandRegistry: CommandRegistry, ) { + init { + commandRegistry.registerCommand(COMMAND) { TutorialCommand() } + } + private val isAnyDeviceConnected = mapOf( KEYBOARD to keyboardRepository.isAnyKeyboardConnected, @@ -118,8 +127,40 @@ constructor( return LAUNCH_DELAY.minus(elapsed).toKotlinDuration() } + inner class TutorialCommand : Command { + override fun execute(pw: PrintWriter, args: List) { + if (args.isEmpty()) { + help(pw) + return + } + when (args[0]) { + "clear" -> + runBlocking { + repo.clear() + pw.println("Tutorial scheduler reset") + } + "info" -> + runBlocking { + pw.println("Keyboard connect time = ${repo.firstConnectionTime(KEYBOARD)}") + pw.println(" launch time = ${repo.launchTime(KEYBOARD)}") + pw.println("Touchpad connect time = ${repo.firstConnectionTime(TOUCHPAD)}") + pw.println(" launch time = ${repo.launchTime(TOUCHPAD)}") + } + else -> help(pw) + } + } + + override fun help(pw: PrintWriter) { + pw.println("Usage: adb shell cmd statusbar $COMMAND ") + pw.println("Available commands:") + pw.println(" clear") + pw.println(" info") + } + } + companion object { const val TAG = "TutorialSchedulerInteractor" + const val COMMAND = "peripheral_tutorial" private val DEFAULT_LAUNCH_DELAY_SEC = 72.hours.inWholeSeconds private val LAUNCH_DELAY: Duration get() = -- cgit v1.2.3-59-g8ed1b