Skip to content

refactor: Migrate from SharedPreferences to DataStore#3

Open
941kjw wants to merge 4 commits intohyunnnchoi:mainfrom
941kjw:refactor/2-store-method-replace
Open

refactor: Migrate from SharedPreferences to DataStore#3
941kjw wants to merge 4 commits intohyunnnchoi:mainfrom
941kjw:refactor/2-store-method-replace

Conversation

@941kjw
Copy link

@941kjw 941kjw commented Mar 5, 2026

Migrate from SharedPreferences to DataStore

Summary

Replaces EncryptedSharedPreferences with DataStore Preferences plus value-level encryption (Android KeyStore AES-256-GCM), aligning with current Android recommendations and improving async safety.

What changed

  • Storage: All secure preferences (credentials, refresh interval, notifications, reset times) now use DataStore Preferences. Sensitive values are encrypted via a new ValueEncryption helper backed by Android KeyStore.
  • API: Load/save/delete are suspend; hasCredential, getRefreshInterval, isNotificationsEnabled remain sync and are backed by an in-memory cache.
  • Call sites: SettingsViewModel and QuotaRefreshWorker updated to use suspend APIs; Repositories and Tile unchanged.
  • Dependencies: Removed androidx.security:security-crypto (EncryptedSharedPreferences).

Checklist

  • ValueEncryption (KeyStore AES-256-GCM) added
  • EncryptedPrefsManager migrated to DataStore
  • DI (SecurityModule) updated
  • SettingsViewModel, QuotaRefreshWorker updated
  • Unit tests updated (suspend stub with runBlocking)
  • README security line updated
  • No EncryptedSharedPreferences / security-crypto usage

How to test

  1. Fresh install: Add credentials (Claude/Codex/Gemini) in Settings, set refresh interval and notifications, confirm quota fetch and tile work.
  2. After upgrade: Existing EncryptedSharedPreferences data is not migrated; re-entering credentials once may be required.
  3. Run unit tests: ./gradlew testDebugUnitTest --tests "com.codexbar.android.core.data.*"

Related

Notes

  • Encryption key: single AES-256 key in Android KeyStore (alias codexbar_datastore_aes_key), generated on first use; no hardcoded secrets.
  • DataStore file name kept as codexbar_secure_prefs; format differs from old prefs, so no automatic migration.

941kjw added 4 commits March 5, 2026 10:20
KeyStore-backed value encryption for DataStore
Replace EncryptedSharedPreferences with DataStore Preferences.
Sensitive values encrypted via ValueEncryption; in-memory cache
for hasCredential/getRefreshInterval/isNotificationsEnabled.
SettingsViewModel: launch for load/save/settings; QuotaRefreshWorker:
make checkForResets suspend for loadResetTimes/saveResetTimes.
Drop EncryptedSharedPreferences dependency. Stub suspend
loadCredential in tests with runBlocking; update README security line.
@941kjw 941kjw changed the title chore: remove security-crypto, fix DataStore tests and README refactor: Migrate from SharedPreferences to DataStore Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant