1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.datastore.core
18 
19 /**
20  * CorruptionHandlers allow recovery from corruption that prevents reading data from the file (as
21  * indicated by a CorruptionException).
22  */
23 internal interface CorruptionHandler<T> {
24     /**
25      * This function will be called by DataStore when it encounters corruption. If the
26      * implementation of this function throws an exception, it will be propagated to the original
27      * call to DataStore. Otherwise, the returned data will be written to disk.
28      *
29      * This function should not interact with any DataStore API - doing so can result in a deadlock.
30      *
31      * @param ex is the exception encountered when attempting to deserialize data from disk.
32      * @return The value that DataStore should attempt to write to disk.
33      */
handleCorruptionnull34     public suspend fun handleCorruption(ex: CorruptionException): T
35 }
36