Status Update
Comments
to...@gmail.com <to...@gmail.com> #2
lp...@google.com <lp...@google.com>
mo...@google.com <mo...@google.com> #3
to...@gmail.com <to...@gmail.com> #4
mo...@google.com <mo...@google.com> #5
In our case, we have b2b app running on dedicated devices.
After 1.1.0 DataStore update we had 6 terminals reported 30k androidx.datastore.core.CorruptionException
fatal crashes on app start.
We use DataStore in WorkManager jobs and on regular Activity starts. Seems that after the application gets this state it will never will succeed to start successfully again. I am afraid that data is being corrupted.
Can't reproduce. But same as OP, we have very vanilla usage of DataStore Preferences. No multiple processes, just simple read/write key-values in a single process single Activity.
to...@gmail.com <to...@gmail.com> #6
Hi, thanks for the feedback, noticed the number of +1s, I'll prioritize an investigation.
To facilitate the process, could you please share how you create the DataStore instance?
mo...@google.com <mo...@google.com> #7
Here is how we are creating our DataStore<Preferences>
instances:
PreferenceDataStoreFactory.create(
produceFile = { context.preferencesDataStoreFile(filename) }, // filename is [a-zA-Z]
scope = scope, // CoroutineScope(Dispatchers.IO + SupervisorJob())
migrations = listOf(
SharedPreferencesMigration(
context = context,
sharedPreferencesName = sharedPrefFile, // we are using our package name here
keysToMigrate = keysToMigrate, // a Set<String>, sometimes empty if nothing to be migrated
),
),
corruptionHandler = ReplaceFileCorruptionHandler {
// logging step omitted
emptyPreferences()
},
)
And these methods are called in Hilt @Provides
methods in a @InstallIn(SingletonComponent::class) @Module
for each preferences we use in our app.
to...@gmail.com <to...@gmail.com> #8
@Module
@InstallIn(SingletonComponent::class)
class PreferencesDataStoreModule {
@Provides
@Singleton
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> =
PreferenceDataStoreFactory.create(
produceFile = {
context.preferencesDataStoreFile(PREFERENCES_FILE_NAME)
},
)
}
mo...@google.com <mo...@google.com> #9
to...@gmail.com <to...@gmail.com> #10
mo...@google.com <mo...@google.com> #11
Re corruptionHandler
to handle the corrupted data file, like in
to...@gmail.com <to...@gmail.com> #12
Re
Question1:
Why these corruptions started appearing only after 1.1.0 version? We were using DataStore forever with such config and everything worked fine.
Question2:
the library doesn't proactively fix the data corruption.
Why is that? Our expectation was that datastore-preferences would work as drop-in replacement for shared-preferences. And users of shared-preferences never had to care about such issues...
to...@gmail.com <to...@gmail.com> #13
to...@gmail.com <to...@gmail.com> #14
to...@gmail.com <to...@gmail.com> #15
Hi I'm looking into it again, I think
Re
Why is that? Our expectation was that datastore-preferences would work as drop-in replacement for shared-preferences. And users of shared-preferences never had to care about such issues...
You didn't have to care such issues of shared preferences because SP just silently fails in such cases, so you won't know the failures. And that's one of the reason why we encouraged people to use Jetpack DataStore than SharedPreferences.
I understand that you would prefer to have the default corruption handler here to replace the file automatically, and it's reasonable to some extent. Unfortunately, we designed the API following a slightly different principle, where people need to "opt-in" this behavior, because their data could be sensitive and they would want to have some ad-hoc logic before the file just disappears and gets replaced automatically. Also you'll need to provide the value for the replacement anyways, right? As far as I can tell, that's not too much different from providing the corruption handler specifications, because you need to pass a param anyways.
ap...@google.com <ap...@google.com> #16
Small update. We downgraded datastore-preferences
1.1.0 -> 1.0.0 and have the apps in production for some time. All CorruptionException
issues stopped.
Re
people need to "opt-in" this behavior, because their data could be sensitive and they would want to have some ad-hoc logic before the file just disappears and gets replaced automatically.
Yes, exactly. I do not understand this. You consider that it's important that developers add logic to handle the corruption case, but at the same time it's exposed via API as an optional opt-in.
There are three possibilities, how datastore-preferences
initialization API behaves:
- Have default behavior, to silently reset prefs on corrupted files (match SharedPreferences). On file corruption event: user silently loses data, the application continues to run with default values.
- Have a mandatory
corruptHandler
parameter on preferences initialization.public fun preferencesDataStore(corruptionHandler:ReplaceFileCorruptionHandler<Preferences>,<..>)
. On file corruption event: Developers are forced to decide what should happen. - Have an optional/opt-in
corruptHandler
parameter [current default variant]. On file corruption event: Application is rendered as completely unusable. RuntimeExection is thrown. The only way end-users can use the app again, is to go and do ClearAppData in the App Settings.
The default behavior is the one that will be used by most developers (not opt-in version).
// At the top level of your kotlin file:
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
Meaning: application will be crashing until the end-user goes to Android app settings and clear data.
So for me ether one of 1.
or 2.
options sounds better then the current 3.
one
to...@gmail.com <to...@gmail.com> #17
Re
For the possibilities you've mentioned, we cannot switch to 3 to 1 directly as it would surprise the existing users who build their app based on the contract that DataStore doesn't automatically replace the file as default behavior.
I think 2 is the right way to go as I discussed with some other folks (cc'ed). Unfortunately, as it is a non-backwards-compatible API change, we can only introduce it in DataStore 2.0 release, for which we don't have a concrete timeline yet. I created a feature request to track this in
to...@gmail.com <to...@gmail.com> #18
Re
Why these corruptions started appearing only after 1.1.0 version?
We restructured the library to be KMP (Kotlin multi-platform) which introduced the dependency of okio as the IO entrypoint instead of java.io.File
. It is not clear to me why does it trigger more CorruptionException
s stemmed from com.google.protobuf.InvalidProtoBufferException
s.
pr...@google.com <pr...@google.com> #19
Hi community, please let me know if you only see this issue for DataStore<Preferences>
, but not the DataStore with other types (especially a protobuf)? In other words, do you also see the same exceptions for DataStore instances of types that are not a Preferences
? This would greatly help us narrow the scope to triage, thanks!
de...@gmail.com <de...@gmail.com> #20
We only use DataStore<Preferences>
, but that is what we are seeing this issue with if that helps.
Description
Jetpack Compose version: 1.8 SNAPSHOT : 12425984
The CLhttps://android-review.googlesource.com/c/platform/frameworks/support/+/3272334 have broken dialogs shown from BottomSheets on Samsung Android 14 devices at least.
Snapshot 12425888 does not exhibit this behavior.
Repo: Show a Dialog/AlertDialog from a ModalBottomSheet from a recent M3 (So after the popup rewrite).
While this is probably a Samsung Bug (See the SAF confirmation screenshot that have the dialog at the bottom too), this is problematic as the M3 alert dialogs does not allow to pass a modifier to at least set contentSafePadding().
So if you consider that this is fully Samsung bug, it would be nice that this was reaffected to M3 to ensure the dialog can have safe paddings.