[PM-19952] Provide SharedPreference from the data module (#5006)

This commit is contained in:
Patrick Honkonen
2025-04-08 15:46:16 -04:00
committed by GitHub
parent 6ebece1b1e
commit 622d68e40c
2 changed files with 1 additions and 53 deletions

View File

@@ -1,50 +0,0 @@
package com.bitwarden.authenticator.data.platform.datasource.di
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import com.bitwarden.data.datasource.disk.di.EncryptedPreferences
import com.bitwarden.data.datasource.disk.di.UnencryptedPreferences
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
/**
* Provides dependencies related to encryption / decryption / secure generation.
*/
@Module
@InstallIn(SingletonComponent::class)
object PreferenceModule {
@Provides
@Singleton
@UnencryptedPreferences
fun provideUnencryptedSharedPreferences(
application: Application,
): SharedPreferences =
application.getSharedPreferences(
"${application.packageName}_preferences",
Context.MODE_PRIVATE,
)
@Provides
@Singleton
@EncryptedPreferences
fun provideEncryptedSharedPreferences(
application: Application,
): SharedPreferences =
EncryptedSharedPreferences
.create(
application,
"${application.packageName}_encrypted_preferences",
MasterKey.Builder(application)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
)
}