Skip to content

Conversation

@mrudatsprint
Copy link
Contributor

DataStoreStorage replaces the deprecated SharedPreferencesStorage as a way to store tokens.

@mrudatsprint mrudatsprint requested a review from Copilot December 12, 2025 01:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR deprecates SharedPreferencesStorage in favor of the new DataStoreStorage implementation for token persistence. The change aligns with modern Android development practices by adopting Jetpack DataStore.

Key Changes:

  • Introduced DataStoreStorage class using Jetpack DataStore for persistence
  • Deprecated SharedPreferencesStorage with a warning-level annotation
  • Updated sample app activities to use the new DataStoreStorage

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
SharedPreferencesStorage.kt Added deprecation annotation directing users to DataStoreStorage
DataStoreStorage.kt New storage implementation using Jetpack DataStore with synchronous API wrapping coroutines
library/build.gradle.kts Added DataStore preferences dependency (version 1.2.0)
TokenActivity.kt Replaced SharedPreferencesStorage with DataStoreStorage in initialization
LoginActivity.kt Replaced SharedPreferencesStorage with DataStoreStorage in initialization
README.md Updated documentation to reference DataStoreStorage instead of SharedPreferencesStorage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 33 to 35
return runBlocking {
context.dataStore.data.first()[prefKey]
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR (Application Not Responding) errors. Consider making the Storage interface suspend-based or providing async alternatives, as DataStore is designed to be used with coroutines asynchronously.

Copilot uses AI. Check for mistakes.
Comment on lines 47 to 51
runBlocking {
context.dataStore.edit { settings ->
settings[prefKey] = content.toString()
}
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR errors. Consider making the Storage interface suspend-based or providing async alternatives.

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 66
runBlocking {
context.dataStore.edit { settings ->
settings.remove(prefKey)
}
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR errors. Consider making the Storage interface suspend-based or providing async alternatives.

Copilot uses AI. Check for mistakes.
*/
@Deprecated(
message = "Use DataStoreStorage instead",
replaceWith = ReplaceWith("DataStoreStorage"),
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The ReplaceWith should include the full qualified name or import statement. Use ReplaceWith(\"DataStoreStorage\", \"io.fusionauth.mobilesdk.storage.DataStoreStorage\") to ensure IDEs can properly auto-import when applying the replacement.

Suggested change
replaceWith = ReplaceWith("DataStoreStorage"),
replaceWith = ReplaceWith("DataStoreStorage", "io.fusionauth.mobilesdk.storage.DataStoreStorage"),

Copilot uses AI. Check for mistakes.
return
lifecycleScope.launch {
if (AuthorizationManager.isAuthenticated()) {
Log.i(TAG, "User is already authenticated, proceeding to token activity")

Check notice

Code scanning / mobsfscan

The App logs information. Sensitive information should never be logged. Note

The App logs information. Sensitive information should never be logged.
try {
val authState: FusionAuthState = AuthorizationManager.oAuth(this@TokenActivity)
.handleRedirect(intent)
Log.i(TAG, authState.toString())

Check notice

Code scanning / mobsfscan

The App logs information. Sensitive information should never be logged. Note

The App logs information. Sensitive information should never be logged.
Log.i(TAG, authState.toString())
fetchUserInfoAndDisplayAuthorized()
} catch (ex: AuthorizationException) {
Log.e(TAG, "Failed to exchange authorization code", ex)

Check notice

Code scanning / mobsfscan

The App logs information. Sensitive information should never be logged. Note

The App logs information. Sensitive information should never be logged.
try {
val authState: FusionAuthState = AuthorizationManager.oAuth(this@TokenActivity)
.handleRedirect(intent)
Log.i(TAG, authState.toString())

Check failure

Code scanning / CodeQL

Insertion of sensitive information into log files High

This
potentially sensitive information
is written to a log file.
This
potentially sensitive information
is written to a log file.
This
potentially sensitive information
is written to a log file.

Copilot Autofix

AI about 15 hours ago

To fix this issue, we must ensure that sensitive data such as access tokens, ID tokens, and refresh tokens are not written to any log output. The problematic log statement is Log.i(TAG, authState.toString()) on line 87 of TokenActivity.kt. Rather than logging the entire object, log a generic message indicating success or relevant non-sensitive details (e.g., that the authorization state was received or exchanged), without including actual tokens or authentication credentials. No changes are needed elsewhere; tokens should not be logged anywhere.

  • Change line 87 to something like: Log.i(TAG, "Authorization state successfully obtained")
  • If you want to assist debugging, you can include non-sensitive fields (other than tokens), but based on the given code, it's safest to just log a status message.
Suggested changeset 1
app/src/main/java/io/fusionauth/sdk/TokenActivity.kt

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/src/main/java/io/fusionauth/sdk/TokenActivity.kt b/app/src/main/java/io/fusionauth/sdk/TokenActivity.kt
--- a/app/src/main/java/io/fusionauth/sdk/TokenActivity.kt
+++ b/app/src/main/java/io/fusionauth/sdk/TokenActivity.kt
@@ -84,7 +84,7 @@
                 try {
                     val authState: FusionAuthState = AuthorizationManager.oAuth(this@TokenActivity)
                         .handleRedirect(intent)
-                    Log.i(TAG, authState.toString())
+                    Log.i(TAG, "Authorization state successfully obtained")
                     fetchUserInfoAndDisplayAuthorized()
                 } catch (ex: AuthorizationException) {
                     Log.e(TAG, "Failed to exchange authorization code", ex)
EOF
@@ -84,7 +84,7 @@
try {
val authState: FusionAuthState = AuthorizationManager.oAuth(this@TokenActivity)
.handleRedirect(intent)
Log.i(TAG, authState.toString())
Log.i(TAG, "Authorization state successfully obtained")
fetchUserInfoAndDisplayAuthorized()
} catch (ex: AuthorizationException) {
Log.e(TAG, "Failed to exchange authorization code", ex)
Copilot is powered by AI and may make mistakes. Always verify output.
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.

2 participants