From d866417c3f6a7519c654e1371a25733789f7d525 Mon Sep 17 00:00:00 2001 From: Matteo Battaglio Date: Fri, 29 May 2020 21:59:37 +0200 Subject: [PATCH] feat: remove KVStorage "state" singleton, and replace it with ad-hoc KVStorage instances (#116) --- .../ministerodellasalute/immuni/koinModule.kt | 32 +++++++++++++------ .../immuni/extensions/storage/KVStorage.kt | 8 ++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/it/ministerodellasalute/immuni/koinModule.kt b/app/src/main/java/it/ministerodellasalute/immuni/koinModule.kt index 1949f44d9..f45b73452 100755 --- a/app/src/main/java/it/ministerodellasalute/immuni/koinModule.kt +++ b/app/src/main/java/it/ministerodellasalute/immuni/koinModule.kt @@ -66,12 +66,6 @@ import org.koin.dsl.module * Dependency Injection Koin module. */ val appModule = module { - - /** - * KVStorage to store generic non-database data encrypted using AES256. - */ - single { KVStorage("state", androidContext(), encrypted = true, moshi = get()) } - /** * App Configuration Service APIs */ @@ -132,7 +126,12 @@ val appModule = module { single { ConfigurationSettingsStoreRepository( - get(), + KVStorage( + name = "ConfigurationSettingsStoreRepository", + context = androidContext(), + encrypted = true, + moshi = get() + ), defaultSettings ) } @@ -174,7 +173,14 @@ val appModule = module { } single { - UploadDisablerStore(get()) + UploadDisablerStore( + KVStorage( + name = "UploadDisablerStore", + context = androidContext(), + encrypted = true, + moshi = get() + ) + ) } single { @@ -229,7 +235,15 @@ val appModule = module { } single { - UserRepository(get()) + UserRepository( + KVStorage( + name = "UserRepository", + context = androidContext(), + encrypted = true, + moshi = immuniMoshi + ) + + ) } single { diff --git a/extensions/src/main/java/it/ministerodellasalute/immuni/extensions/storage/KVStorage.kt b/extensions/src/main/java/it/ministerodellasalute/immuni/extensions/storage/KVStorage.kt index 215b6bc6f..17a5f2867 100644 --- a/extensions/src/main/java/it/ministerodellasalute/immuni/extensions/storage/KVStorage.kt +++ b/extensions/src/main/java/it/ministerodellasalute/immuni/extensions/storage/KVStorage.kt @@ -52,7 +52,7 @@ class KVStorage( val name: String, context: Context?, val cacheInMemory: Boolean = true, - val encrypted: Boolean, + val encrypted: Boolean = true, val moshi: Moshi, // The following two properties should be private but are not, because they're used in public // inline methods, thus the underscore prefix. @@ -67,7 +67,7 @@ class KVStorage( mutableMapOf() /** - * Checks if the storage contains the given key. + * Checks if the storage contains the given [key]. */ fun contains(key: Key): Boolean = synchronized(this) { _cache.contains(key) || _sharedPrefs.contains(key.name) @@ -85,8 +85,8 @@ class KVStorage( } /** - * Saves value for the given key. If value's type is not one of the supported primitive types - * (Boolean, Int, Long, Float, String), it first serializes value to Json with Moshi + * Saves [value] for the given [key]. If value's type is not one of the supported primitive types + * (Boolean, Int, Long, Float, String), it first serializes value to Json with [Moshi] * and then saves it as a String. */ inline operator fun set(key: Key, value: T) = synchronized(this) {