Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Replace SharedPreferences with DataStore Preferences #629

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

ovitrif
Copy link

@ovitrif ovitrif commented Mar 14, 2024

Closes #628

This PR replaces the usage of SharedPreferences with DataStore.

Why

Google is recommending in their official documentation to migrate to DataStore from SharedPreferences, and they also provided a very easy-to-use auto-migration tool that will move the data to the new DataStore, then clean up the entries from SharedPreferences.

Their official guide for saving simple data with SharedPreferences displays an alert about this:
Google Chrome 2024-03-14 001629

For security concerns as well, it is recommended to migrate to DataStore.

How

Calls to read and write to DataStore are forced to run synchronously based on the example provided by the Android team in Use DataStore in synchronous code.

Data Migration

SharedPreferencesMigration is used to migrate the entries stored in the RN_KEYCHAIN shared prefs file to data store. Upon completion, the SharedPreferences get removed.

Testing

  • junit test were removed from the project
  • Done manual testing via an app using React Native to verify migrations work seamlessly.

@ovitrif
Copy link
Author

ovitrif commented Mar 27, 2024

@oblador Any idea why the error about compileSdkVersion is not specified. Please add it to build.gradle in the unit tests?

Could it be a side-effect of adding Kotlin?! 🤷🏻

Copy link

@enahum enahum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good addition to the library

build.gradle.kts Outdated Show resolved Hide resolved
@DorianMazur
Copy link
Collaborator

@ovitrif Can you update this PR?

# Conflicts:
#	KeychainExample/android/build.gradle
#	README.md
#	android/build.gradle
#	android/src/main/java/com/oblador/keychain/KeychainModule.java
#	android/src/test/java/com/oblador/keychain/KeychainModuleTests.java
#	build.gradle.kts
Reimplement data store refactoring on version 9.1.0
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.

Replace SharedPreferences with DataStore Preferences on Android
3 participants