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

Commit dbfc3ce2 authored by yyalan's avatar yyalan Committed by Android Build Coastguard Worker
Browse files

[OOBE] Add corruptionHandler to handle file corruption

Bug: 393371979
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: see ag/31154470
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:fd7a90ded20ad57aea7f42d371d0d2004be9b8e3)
Merged-In: Ie732cbab915573f8693ca3ddc83a25e044a96cbf
Change-Id: Ie732cbab915573f8693ca3ddc83a25e044a96cbf
parent 6e0c448b
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 isLaunched(deviceType: DeviceType): Boolean = loadData()[deviceType]!!.isLaunched