Skip to content

Commit 3f14418

Browse files
committed
Use SharedPreferencesProvider
1 parent d71530c commit 3f14418

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/secure/PirSecureStorageKeyStore.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
package com.duckduckgo.pir.impl.store.secure
1818

19-
import android.content.Context
2019
import android.content.SharedPreferences
2120
import androidx.core.content.edit
22-
import androidx.security.crypto.EncryptedSharedPreferences
23-
import androidx.security.crypto.MasterKey
2421
import com.duckduckgo.app.di.AppCoroutineScope
2522
import com.duckduckgo.common.utils.DispatcherProvider
23+
import com.duckduckgo.data.store.api.SharedPreferencesProvider
2624
import com.duckduckgo.di.scopes.AppScope
2725
import com.squareup.anvil.annotations.ContributesBinding
2826
import dagger.SingleInstanceIn
@@ -62,9 +60,9 @@ interface PirSecureStorageKeyStore {
6260
boundType = PirSecureStorageKeyStore::class,
6361
)
6462
class RealPirSecureStorageKeyStore @Inject constructor(
65-
private val context: Context,
6663
@AppCoroutineScope private val coroutineScope: CoroutineScope,
6764
private val dispatcherProvider: DispatcherProvider,
65+
private val sharedPreferencesProvider: SharedPreferencesProvider,
6866
) : PirSecureStorageKeyStore {
6967

7068
private val mutex: Mutex = Mutex()
@@ -108,14 +106,9 @@ class RealPirSecureStorageKeyStore @Inject constructor(
108106
private suspend fun createEncryptedPreferences(): SharedPreferences? {
109107
return try {
110108
mutex.withLock {
111-
EncryptedSharedPreferences.create(
112-
context,
113-
FILENAME,
114-
MasterKey.Builder(context)
115-
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
116-
.build(),
117-
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
118-
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
109+
sharedPreferencesProvider.getEncryptedSharedPreferences(
110+
name = FILENAME,
111+
multiprocess = true,
119112
)
120113
}
121114
} catch (_: Exception) {

0 commit comments

Comments
 (0)