summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt19
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt7
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt7
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt52
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt7
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt7
6 files changed, 99 insertions, 0 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt
new file mode 100644
index 00000000..cdb0f9f1
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt
@@ -0,0 +1,19 @@
+package dev.msfjarvis.aps.injection.context
+
+import android.content.Context
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+
+@Module
+@InstallIn(SingletonComponent::class)
+class ContextModule {
+
+ @Provides
+ @FilesDirPath
+ fun providesFilesDirPath(@ApplicationContext context: Context): String {
+ return context.filesDir.path
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt b/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt
new file mode 100644
index 00000000..8bced295
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt
@@ -0,0 +1,7 @@
+package dev.msfjarvis.aps.injection.context
+
+import javax.inject.Qualifier
+
+@Qualifier
+@Retention(AnnotationRetention.RUNTIME)
+annotation class FilesDirPath \ No newline at end of file
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt
new file mode 100644
index 00000000..c07bc65e
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt
@@ -0,0 +1,7 @@
+package dev.msfjarvis.aps.injection.prefs
+
+import javax.inject.Qualifier
+
+@Qualifier
+@Retention(AnnotationRetention.RUNTIME)
+annotation class GitPreferences \ No newline at end of file
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt
new file mode 100644
index 00000000..41d2a30b
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt
@@ -0,0 +1,52 @@
+package dev.msfjarvis.aps.injection.prefs
+
+import android.content.Context
+import android.content.Context.MODE_PRIVATE
+import android.content.SharedPreferences
+import androidx.security.crypto.EncryptedSharedPreferences
+import androidx.security.crypto.MasterKey
+import dagger.Module
+import dagger.Provides
+import dagger.Reusable
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+import dev.msfjarvis.aps.BuildConfig
+
+@Module
+@InstallIn(SingletonComponent::class)
+class PreferenceModule {
+
+ private fun provideBaseEncryptedPreferences(context: Context, fileName: String): SharedPreferences {
+ val masterKeyAlias =
+ MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
+ return EncryptedSharedPreferences.create(
+ context,
+ fileName,
+ masterKeyAlias,
+ EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
+ EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
+ )
+ }
+
+ @Provides
+ @SettingsPreferences
+ @Reusable
+ fun provideSettingsPreferences(@ApplicationContext context: Context): SharedPreferences {
+ return context.getSharedPreferences("${BuildConfig.APPLICATION_ID}_preferences", MODE_PRIVATE)
+ }
+
+ @Provides
+ @GitPreferences
+ @Reusable
+ fun provideEncryptedPreferences(@ApplicationContext context: Context): SharedPreferences {
+ return provideBaseEncryptedPreferences(context, "git_operation")
+ }
+
+ @Provides
+ @ProxyPreferences
+ @Reusable
+ fun provideProxyPreferences(@ApplicationContext context: Context): SharedPreferences {
+ return provideBaseEncryptedPreferences(context, "http_proxy")
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt
new file mode 100644
index 00000000..c0b43088
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt
@@ -0,0 +1,7 @@
+package dev.msfjarvis.aps.injection.prefs
+
+import javax.inject.Qualifier
+
+@Qualifier
+@Retention(AnnotationRetention.RUNTIME)
+annotation class ProxyPreferences \ No newline at end of file
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt
new file mode 100644
index 00000000..7bd1f9b9
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt
@@ -0,0 +1,7 @@
+package dev.msfjarvis.aps.injection.prefs
+
+import javax.inject.Qualifier
+
+@Qualifier
+@Retention(AnnotationRetention.RUNTIME)
+annotation class SettingsPreferences \ No newline at end of file