This module provides a small abstraction for storing key/value data that can survive app reinstall and device restore flows. On Play/Internal builds it is backed by Google Play Block Store, and on F-Droid it is backed by a dummy implementation that reports unavailability.
persistent-storage-api: public contract (PersistentStorage, availability model, and key abstraction)persistent-storage-impl: real implementation using Block Store (playandinternalflavors)persistent-storage-dummy-impl: fallback implementation forfdroidflavor
- Consumers inject
PersistentStoragefrompersistent-storage-api - Keys are module-owned subclasses of
PersistentStorageKeywith a globally uniquekeystring checkAvailability()should be called before read/write operations when a feature depends on persistence being availablestore,retrieve, andclearreturnResultand fail withPersistentStorageUnavailableExceptionwhen unsupportedshouldBackupToCloudcontrols whether stored values are eligible for cloud backup
object MyFeatureKeys {
object SessionSeed : PersistentStorageKey(
key = "com.duckduckgo.myfeature.session.seed",
shouldBackupToCloud = false,
)
}
class MyFeatureRepository @Inject constructor(
private val persistentStorage: PersistentStorage,
) {
suspend fun save(seed: ByteArray): Result<Unit> {
return persistentStorage.store(MyFeatureKeys.SessionSeed, seed)
}
}## Who can help you better understand this feature?
- Craig Russell