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

Commit 0ebc303c authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Adding corruptionHandler to all usages of DataStore

This is to prevent seemingly inevitable CorruptionException that will crash sysui process and might cause bootloop.

Fixes: 393554532
Test: see test from ag/31154470
Flag: EXEMPT Bugfix
Change-Id: I54d93950405ab6d56d2d3a4e683f5089fe5cd7ad
parent d811d8cb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.datastore.core.CorruptionException
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.core.Serializer
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.dataStoreFile
import com.android.framework.protobuf.InvalidProtocolBufferException
import com.android.internal.annotations.VisibleForTesting
@@ -48,6 +49,10 @@ constructor(private val dataStore: DataStore<WindowingEducationProto>) {
        DataStoreFactory.create(
            serializer = WindowingEducationProtoSerializer,
            produceFile = { context.dataStoreFile(APP_HANDLE_EDUCATION_DATASTORE_FILEPATH) },
            corruptionHandler =
                ReplaceFileCorruptionHandler(
                    produceNewData = { WindowingEducationProto.getDefaultInstance() }
                ),
        )
    )

+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.datastore.core.CorruptionException
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.core.Serializer
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.dataStoreFile
import com.android.framework.protobuf.InvalidProtocolBufferException
import com.android.internal.annotations.VisibleForTesting
@@ -42,6 +43,10 @@ constructor(private val dataStore: DataStore<WindowingEducationProto>) {
        DataStoreFactory.create(
            serializer = WindowingEducationProtoSerializer,
            produceFile = { context.dataStoreFile(APP_TO_WEB_EDUCATION_DATASTORE_FILEPATH) },
            corruptionHandler =
                ReplaceFileCorruptionHandler(
                    produceNewData = { WindowingEducationProto.getDefaultInstance() }
                ),
        )
    )

+9 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.datastore.core.CorruptionException
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.core.Serializer
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.dataStoreFile
import com.android.framework.protobuf.InvalidProtocolBufferException
import com.android.wm.shell.shared.annotations.ShellBackgroundThread
@@ -49,6 +50,10 @@ class DesktopPersistentRepository(private val dataStore: DataStore<DesktopPersis
            serializer = DesktopPersistentRepositoriesSerializer,
            produceFile = { context.dataStoreFile(DESKTOP_REPOSITORIES_DATASTORE_FILE) },
            scope = bgCoroutineScope,
            corruptionHandler =
                ReplaceFileCorruptionHandler(
                    produceNewData = { DesktopPersistentRepositories.getDefaultInstance() }
                ),
        )
    )

@@ -127,7 +132,10 @@ class DesktopPersistentRepository(private val dataStore: DataStore<DesktopPersis
                    .toBuilder()
                    .putDesktopRepoByUser(
                        userId,
                        currentRepository.toBuilder().putDesktop(desktopId, desktop.build()).build(),
                        currentRepository
                            .toBuilder()
                            .putDesktop(desktopId, desktop.build())
                            .build(),
                    )
                    .build()
            }