feat: Migrate PreferencesManager to DataStore with Encrypted Storage#477
Conversation
|
Thanks for the pull request, @PavloNetrebchuk! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
d65fbc3 to
aa018a7
Compare
RawanMatar89
left a comment
There was a problem hiding this comment.
@PavloNetrebchuk Will you please mention how this PR manage the migration for old user preferences ?
|
|
||
| private fun getString(key: String, defValue: String = ""): String { | ||
| return sharedPreferences.getString(key, defValue) ?: defValue | ||
| private fun <T> getValue(key: Preferences.Key<T>, defaultValue: T): T = runBlocking { |
There was a problem hiding this comment.
dataStore is async, so calling getValue on the main thread with runBlocking and dataStore could cause UI freeze.
| val encrypted = getValue(key, "") | ||
| if (encrypted.isEmpty()) return defaultValue | ||
| val decrypted = encryption.decrypt(encrypted) | ||
| return decrypted.ifEmpty { defaultValue } |
There was a problem hiding this comment.
all fun calls use "" as 'default value'.
keystore key can be invalidated if the user change device security settings or the system updated. so I think we should handle this senecio to prevent the case of using the app with an empty access token which will lead to bad user experience
app/src/main/java/org/openedx/app/data/storage/SharedPrefsToDataStoreMigration.kt
Fixed
Show fixed
Hide fixed
|
Hi @RawanMatar89 Fix 1: runBlocking → runBlocking(Dispatchers.IO) Fix 2: Keystore invalidation handling
Fix 3: SharedPreferences → DataStore migration
|
f095314 to
a0b2e74
Compare
RawanMatar89
left a comment
There was a problem hiding this comment.
@PavloNetrebchuk, great efforts 👏🏻 LGTM 👍🏻
Migrates PreferencesManager from SharedPreferences to Jetpack DataStore Preferences with AES-256-GCM encryption for sensitive data using Android Keystore.
DataStore Migration:
Encryption Implementation:
Security Details:
Motivation
SharedPreferences limitations:
New implementation advantages: