From 622d68e40c11e1cc05a19c1dc8286a3065312079 Mon Sep 17 00:00:00 2001 From: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:46:16 -0400 Subject: [PATCH] [PM-19952] Provide SharedPreference from the `data` module (#5006) --- .../datasource/di/PreferenceModule.kt | 50 ------------------- .../datasource/disk}/di/PreferenceModule.kt | 4 +- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 authenticator/src/main/kotlin/com/bitwarden/authenticator/data/platform/datasource/di/PreferenceModule.kt rename {app/src/main/java/com/x8bit/bitwarden/data/platform/datasource => data/src/main/kotlin/com/bitwarden/data/datasource/disk}/di/PreferenceModule.kt (94%) diff --git a/authenticator/src/main/kotlin/com/bitwarden/authenticator/data/platform/datasource/di/PreferenceModule.kt b/authenticator/src/main/kotlin/com/bitwarden/authenticator/data/platform/datasource/di/PreferenceModule.kt deleted file mode 100644 index a2648d5fbe..0000000000 --- a/authenticator/src/main/kotlin/com/bitwarden/authenticator/data/platform/datasource/di/PreferenceModule.kt +++ /dev/null @@ -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, - ) -} diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/PreferenceModule.kt b/data/src/main/kotlin/com/bitwarden/data/datasource/disk/di/PreferenceModule.kt similarity index 94% rename from app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/PreferenceModule.kt rename to data/src/main/kotlin/com/bitwarden/data/datasource/disk/di/PreferenceModule.kt index 64c5b397e1..2ac1f3d45a 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/PreferenceModule.kt +++ b/data/src/main/kotlin/com/bitwarden/data/datasource/disk/di/PreferenceModule.kt @@ -1,12 +1,10 @@ -package com.x8bit.bitwarden.data.platform.datasource.di +package com.bitwarden.data.datasource.disk.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