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

[MOB-10624] add anonymous user id to keychain #868

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ public static class Builder {
private IterableDataRegion dataRegion = IterableDataRegion.US;
private boolean useInMemoryStorageForInApps = false;
private IterableDecryptionFailureHandler decryptionFailureHandler;

private boolean encryptionEnforced = false;
private boolean enableAnonActivation = false;
private boolean enableEmbeddedMessaging = false;
private int eventThresholdLimit = 100;
private IterableIdentityResolution identityResolution = new IterableIdentityResolution();
private IterableAnonUserHandler iterableAnonUserHandler;
private IterableDecryptionFailureHandler decryptionFailureHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a duplicate. See line 157. I added two by accident in the merge conflict.

Choose a reason for hiding this comment

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

right i didnt notice the one on top my bad
]


@NonNull
public Builder setIterableAnonUserHandler(@NonNull IterableAnonUserHandler iterableAnonUserHandler) {
Expand Down Expand Up @@ -357,6 +355,8 @@ public Builder setEnableEmbeddedMessaging(boolean enableEmbeddedMessaging) {

public Builder setIdentityResolution(IterableIdentityResolution identityResolution) {
this.identityResolution = identityResolution;
return this;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it necessary to return this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I am just following the other config values. It was deleted when resolving the merge conflicts for some reason.

Choose a reason for hiding this comment

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

makes sense if other config values are also doing it

}

/**
* Set a handler for decryption failures that can be used to handle data recovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class IterableKeychain {
private const val TAG = "IterableKeychain"
const val KEY_EMAIL = "iterable-email"
const val KEY_USER_ID = "iterable-user-id"
const val KEY_ANON_USER_ID = "iterable-anon-user-id"
const val KEY_AUTH_TOKEN = "iterable-auth-token"
}

Expand Down Expand Up @@ -39,7 +40,7 @@ class IterableKeychain {
}
}
dataMigrator.attemptMigration()
IterableLogger.v(TAG, "Migration completed")
IterableLogger.v(TAG, "Migration completed")
}
} catch (e: Exception) {
IterableLogger.w(TAG, "Migration failed, clearing data", e)
Expand All @@ -52,6 +53,7 @@ class IterableKeychain {
sharedPrefs.edit()
.remove(KEY_EMAIL)
.remove(KEY_USER_ID)
.remove(KEY_ANON_USER_ID)
.remove(KEY_AUTH_TOKEN)
.apply()

Expand Down Expand Up @@ -96,4 +98,7 @@ class IterableKeychain {

fun getAuthToken() = secureGet(KEY_AUTH_TOKEN)
fun saveAuthToken(authToken: String?) = secureSave(KEY_AUTH_TOKEN, authToken)

fun getUserIdAnon() = secureGet(KEY_ANON_USER_ID)
fun saveUserIdAnon(userIdAnon: String?) = secureSave(KEY_ANON_USER_ID, userIdAnon)
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ class IterableKeychainEncryptedDataMigrator(
IterableLogger.w(TAG, "No user ID found to migrate.")
}

// Fetch and migrate anonymous user ID
val anonUserId = encryptedPrefs.getString(IterableKeychain.KEY_ANON_USER_ID, null)
if (userId != null) {
keychain.saveUserIdAnon(anonUserId)
editor.remove(IterableKeychain.KEY_ANON_USER_ID)
IterableLogger.d(TAG, "Anonymous User ID migrated: $anonUserId")
} else {
IterableLogger.w(TAG, "No anon user ID found to migrate.")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there was no KEY_ANON_USER_ID stored in encrypted shared prefs before we dont need to migrate it either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm good point I will remove.

// Fetch and migrate auth token
val authToken = encryptedPrefs.getString(IterableKeychain.KEY_AUTH_TOKEN, null)
if (authToken != null) {
Expand Down
Loading