This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 307
Refactor preferences to decouple framework dependency #1417
Merged
msfjarvis
merged 13 commits into
android-password-store:develop
from
SphericalKat:develop
May 22, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f377510
chore(build): add mock shared preference dependency
SphericalKat bd09190
refactor(extension): remove PreferenceManager dependency for getting …
SphericalKat 49d8183
fix(tests): return null/default values from faked android sdk
SphericalKat 9fcbde2
chore(format): format code using spotless
SphericalKat 47099c7
di: add context and preferences module
Skrilltrax c3f8de9
app: refactor GitSettings and ProxyUtils and inject them using hilt
Skrilltrax d45bb75
test: update MigrationsTest to run on JVM
Skrilltrax 521f477
spotless: fix formatting
Skrilltrax 1ae961e
test: remove context parameter
Skrilltrax 1583c4c
app: lazily initialize hiltEntryPoint to make sure that activity is a…
Skrilltrax d9d1806
ci: remove instrumentationTest step and run action on ubuntu-latest
Skrilltrax a2741cd
docs: Document qualifiers
Skrilltrax f66652c
Tweak documentation and drop unused import
msfjarvis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 0 additions & 124 deletions
124
app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/dev/msfjarvis/aps/injection/context/ContextModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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 { | ||
|
|
||
| /** | ||
| * We inject [Context.getFilesDir] to break the dependency on [Context], allowing tests to run on | ||
| * the JVM. The principle here is identical to why [dev.msfjarvis.aps.util.totp.TotpFinder] | ||
| * exists. | ||
| * | ||
| * @param context [ApplicationContext] | ||
| * @return the path of app-specific files directory. | ||
| */ | ||
| @Provides | ||
| @FilesDirPath | ||
| fun providesFilesDirPath(@ApplicationContext context: Context): String { | ||
| return context.filesDir.path | ||
| } | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
app/src/main/java/dev/msfjarvis/aps/injection/context/FilesDirPath.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package dev.msfjarvis.aps.injection.context | ||
|
|
||
| import android.content.Context | ||
| import javax.inject.Qualifier | ||
|
|
||
| /** Qualifies a [String] representing the absolute path of [Context.getFilesDir]. */ | ||
| @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class FilesDirPath | ||
Skrilltrax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
9 changes: 9 additions & 0 deletions
9
app/src/main/java/dev/msfjarvis/aps/injection/prefs/GitPreferences.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package dev.msfjarvis.aps.injection.prefs | ||
|
|
||
| import android.content.SharedPreferences | ||
| import javax.inject.Qualifier | ||
|
|
||
| /** | ||
| * Qualifies a [SharedPreferences] instance specifically used for encrypted Git-related settings. | ||
| */ | ||
| @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class GitPreferences | ||
Skrilltrax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
55 changes: 55 additions & 0 deletions
55
app/src/main/java/dev/msfjarvis/aps/injection/prefs/PreferenceModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 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") | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/dev/msfjarvis/aps/injection/prefs/ProxyPreferences.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package dev.msfjarvis.aps.injection.prefs | ||
|
|
||
| import android.content.SharedPreferences | ||
| import javax.inject.Qualifier | ||
|
|
||
| /** | ||
| * Qualifies a [SharedPreferences] instance specifically used for encrypted proxy-related settings. | ||
| */ | ||
| @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class ProxyPreferences | ||
Skrilltrax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
5 changes: 5 additions & 0 deletions
5
app/src/main/java/dev/msfjarvis/aps/injection/prefs/SettingsPreferences.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package dev.msfjarvis.aps.injection.prefs | ||
|
|
||
| import javax.inject.Qualifier | ||
|
|
||
| @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class SettingsPreferences |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.