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

Commit fd7a90de authored by yyalan's avatar yyalan
Browse files

[OOBE] Add corruptionHandler to handle file corruption

Bug: 393371979
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: see ag/31154470
Change-Id: Ie732cbab915573f8693ca3ddc83a25e044a96cbf
parent 11611d23
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -18,8 +18,10 @@ package com.android.systemui.inputdevice.tutorial.data.repository

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.android.systemui.dagger.SysUISingleton
@@ -45,7 +47,12 @@ class TutorialSchedulerRepository(
    ) : this(applicationContext, backgroundScope, dataStoreName = DATASTORE_NAME)

    private val Context.dataStore: DataStore<Preferences> by
        preferencesDataStore(name = dataStoreName, scope = backgroundScope)
        preferencesDataStore(
            name = dataStoreName,
            corruptionHandler =
                ReplaceFileCorruptionHandler(produceNewData = { emptyPreferences() }),
            scope = backgroundScope,
        )

    suspend fun setScheduledTutorialLaunchTime(device: DeviceType, time: Instant) {
        updateData(key = getLaunchedKey(device), value = time.epochSecond)