diff options
| author | 2025-01-06 05:07:50 -0800 | |
|---|---|---|
| committer | 2025-01-06 05:07:50 -0800 | |
| commit | 74c4087d601ede801e705748155669e4df8b49ad (patch) | |
| tree | a9d6ca7b19eb0c0dc530814ae31e993246328f36 | |
| parent | 4c48104154c87d9b25c32a65dc78141e24b39b07 (diff) | |
| parent | fcd237498c15cb24df0902765aa20cb1c621be7f (diff) | |
Merge "Record launched time" into main
4 files changed, 42 insertions, 31 deletions
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 463067465889..b9e86138529f 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 @@ -84,9 +84,11 @@ class TutorialSchedulerRepositoryTest : SysuiTestCase() { @Test fun notifyKeyboard() = runTestAndClear { - underTest.setNotified(KEYBOARD) + val now = Instant.now() + underTest.setNotifiedTime(KEYBOARD, now) assertThat(underTest.isNotified(KEYBOARD)).isTrue() + assertThat(underTest.getNotifiedTime(KEYBOARD)!!.epochSecond).isEqualTo(now.epochSecond) assertThat(underTest.isNotified(TOUCHPAD)).isFalse() } diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/model/DeviceSchedulerInfo.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/model/DeviceSchedulerInfo.kt index c436ef01deda..9a065be35ffe 100644 --- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/model/DeviceSchedulerInfo.kt +++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/data/model/DeviceSchedulerInfo.kt @@ -19,23 +19,26 @@ package com.android.systemui.inputdevice.tutorial.data.model import java.time.Instant data class DeviceSchedulerInfo( - var launchTime: Instant? = null, + var launchedTime: Instant? = null, var firstConnectionTime: Instant? = null, - var isNotified: Boolean = false, + var notifiedTime: Instant? = null, ) { constructor( launchTimeSec: Long?, firstConnectionTimeSec: Long?, - isNotified: Boolean = false, + notifyTimeSec: Long?, ) : this( launchTimeSec?.let { Instant.ofEpochSecond(it) }, firstConnectionTimeSec?.let { Instant.ofEpochSecond(it) }, - isNotified, + notifyTimeSec?.let { Instant.ofEpochSecond(it) }, ) val wasEverConnected: Boolean get() = firstConnectionTime != null val isLaunched: Boolean - get() = launchTime != null + get() = launchedTime != null + + val isNotified: Boolean + get() = notifiedTime != null } 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 526e7dbd7f57..8b0accd65d7b 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 @@ -19,7 +19,6 @@ package com.android.systemui.inputdevice.tutorial.data.repository import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences -import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.longPreferencesKey import androidx.datastore.preferences.preferencesDataStore @@ -49,35 +48,42 @@ class TutorialSchedulerRepository( preferencesDataStore(name = dataStoreName, scope = backgroundScope) suspend fun setScheduledTutorialLaunchTime(device: DeviceType, time: Instant) { - applicationContext.dataStore.edit { pref -> pref[getLaunchKey(device)] = time.epochSecond } + updateData(key = getLaunchedKey(device), value = time.epochSecond) } suspend fun isScheduledTutorialLaunched(deviceType: DeviceType): Boolean = loadData()[deviceType]!!.isLaunched suspend fun getScheduledTutorialLaunchTime(deviceType: DeviceType): Instant? = - loadData()[deviceType]!!.launchTime + loadData()[deviceType]!!.launchedTime suspend fun setFirstConnectionTime(device: DeviceType, time: Instant) { - applicationContext.dataStore.edit { pref -> pref[getConnectKey(device)] = time.epochSecond } + updateData(key = getConnectedKey(device), value = time.epochSecond) } - suspend fun setNotified(device: DeviceType) { - applicationContext.dataStore.edit { pref -> pref[getNotificationKey(device)] = true } - } - - suspend fun isNotified(deviceType: DeviceType): Boolean = loadData()[deviceType]!!.isNotified - suspend fun wasEverConnected(deviceType: DeviceType): Boolean = loadData()[deviceType]!!.wasEverConnected suspend fun getFirstConnectionTime(deviceType: DeviceType): Instant? = loadData()[deviceType]!!.firstConnectionTime + suspend fun setNotifiedTime(device: DeviceType, time: Instant) { + updateData(key = getNotifiedKey(device), value = time.epochSecond) + } + + suspend fun isNotified(deviceType: DeviceType): Boolean = loadData()[deviceType]!!.isNotified + + suspend fun getNotifiedTime(deviceType: DeviceType): Instant? = + loadData()[deviceType]!!.notifiedTime + private suspend fun loadData(): Map<DeviceType, DeviceSchedulerInfo> { return applicationContext.dataStore.data.map { pref -> getSchedulerInfo(pref) }.first() } + private suspend fun <T> updateData(key: Preferences.Key<T>, value: T) { + applicationContext.dataStore.edit { pref -> pref[key] = value } + } + private fun getSchedulerInfo(pref: Preferences): Map<DeviceType, DeviceSchedulerInfo> { return mapOf( DeviceType.KEYBOARD to getDeviceSchedulerInfo(pref, DeviceType.KEYBOARD), @@ -86,20 +92,20 @@ class TutorialSchedulerRepository( } private fun getDeviceSchedulerInfo(pref: Preferences, device: DeviceType): DeviceSchedulerInfo { - val launchTime = pref[getLaunchKey(device)] - val connectionTime = pref[getConnectKey(device)] - val isNotified = pref[getNotificationKey(device)] == true - return DeviceSchedulerInfo(launchTime, connectionTime, isNotified) + val launchedTime = pref[getLaunchedKey(device)] + val connectedTime = pref[getConnectedKey(device)] + val notifiedTime = pref[getNotifiedKey(device)] + return DeviceSchedulerInfo(launchedTime, connectedTime, notifiedTime) } - private fun getLaunchKey(device: DeviceType) = - longPreferencesKey(device.name + LAUNCH_TIME_SUFFIX) + private fun getLaunchedKey(device: DeviceType) = + longPreferencesKey(device.name + LAUNCHED_TIME_SUFFIX) - private fun getConnectKey(device: DeviceType) = - longPreferencesKey(device.name + CONNECT_TIME_SUFFIX) + private fun getConnectedKey(device: DeviceType) = + longPreferencesKey(device.name + CONNECTED_TIME_SUFFIX) - private fun getNotificationKey(device: DeviceType) = - booleanPreferencesKey(device.name + NOTIFIED_SUFFIX) + private fun getNotifiedKey(device: DeviceType) = + longPreferencesKey(device.name + NOTIFIED_TIME_SUFFIX) suspend fun clear() { applicationContext.dataStore.edit { it.clear() } @@ -107,9 +113,9 @@ class TutorialSchedulerRepository( companion object { const val DATASTORE_NAME = "TutorialScheduler" - const val LAUNCH_TIME_SUFFIX = "_LAUNCH_TIME" - const val CONNECT_TIME_SUFFIX = "_CONNECT_TIME" - const val NOTIFIED_SUFFIX = "_NOTIFIED" + const val LAUNCHED_TIME_SUFFIX = "_LAUNCHED_TIME" + const val CONNECTED_TIME_SUFFIX = "_CONNECTED_TIME" + const val NOTIFIED_TIME_SUFFIX = "_NOTIFIED_TIME" } } 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 419eefed058d..9607053f4e7f 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 @@ -111,9 +111,9 @@ constructor( val tutorialType = resolveTutorialType(it) if (tutorialType == TutorialType.KEYBOARD || tutorialType == TutorialType.BOTH) - repo.setNotified(KEYBOARD) + repo.setNotifiedTime(KEYBOARD, Instant.now()) if (tutorialType == TutorialType.TOUCHPAD || tutorialType == TutorialType.BOTH) - repo.setNotified(TOUCHPAD) + repo.setNotifiedTime(TOUCHPAD, Instant.now()) logger.logTutorialLaunched(tutorialType) tutorialType |