Skip to content

Commit 00f86da

Browse files
hanlde sceanrio related to unknown Identity type
1 parent 7aca94d commit 00f86da

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,13 +1523,23 @@ private void confirmEmail(
15231523
boolean hasHashedEmail = hashedEmail != null && !hashedEmail.isEmpty();
15241524

15251525
if ((hasEmail || hasHashedEmail) && user != null) {
1526+
MParticle.IdentityType selectedIdentityType = null;
1527+
try {
1528+
String identityTypeStr = (kitConfiguration != null)
1529+
? kitConfiguration.getHashedEmailUserIdentityType()
1530+
: null;
1531+
if (identityTypeStr != null && !identityTypeStr.equalsIgnoreCase("Unknown")) {
1532+
selectedIdentityType = MParticle.IdentityType.valueOf(identityTypeStr);
1533+
}
1534+
} catch (IllegalArgumentException e) {
1535+
selectedIdentityType = MParticle.IdentityType.Other; // fallback if invalid value
1536+
}
15261537
String existingEmail = user.getUserIdentities().get(MParticle.IdentityType.Email);
1527-
String existingHashedEmail = user.getUserIdentities().get(MParticle.IdentityType.Other);
1528-
1538+
String existingHashedEmail = selectedIdentityType != null ? user.getUserIdentities().get(selectedIdentityType) : null;
15291539
boolean emailMismatch = hasEmail && !email.equalsIgnoreCase(existingEmail);
15301540
boolean hashedEmailMismatch = hasHashedEmail && !hashedEmail.equalsIgnoreCase(existingHashedEmail);
15311541

1532-
if (emailMismatch || hashedEmailMismatch) {
1542+
if (emailMismatch || (hashedEmailMismatch && selectedIdentityType != null)) {
15331543
// If there's an existing email but it doesn't match the passed-in email, log a warning
15341544
if (emailMismatch && existingEmail != null) {
15351545
Logger.warning(String.format(
@@ -1553,20 +1563,8 @@ else if (hashedEmailMismatch && existingHashedEmail != null) {
15531563
if (emailMismatch) {
15541564
identityBuilder.email(email);
15551565
}
1556-
if (hashedEmailMismatch && kitConfiguration != null) {
1557-
MParticle.IdentityType type = null;
1558-
try {
1559-
String identityTypeStr = kitConfiguration.getHashedEmailUserIdentityType();
1560-
if (identityTypeStr != null && !identityTypeStr.equalsIgnoreCase("UNASSIGNED")) {
1561-
type = MParticle.IdentityType.valueOf(identityTypeStr);
1562-
}
1563-
} catch (IllegalArgumentException e) {
1564-
type = MParticle.IdentityType.Other; // fallback if invalid
1565-
}
1566-
1567-
if (type != null) {
1568-
identityBuilder.userIdentity(type, hashedEmail);
1569-
}
1566+
if (hashedEmailMismatch && selectedIdentityType != null) {
1567+
identityBuilder.userIdentity(selectedIdentityType, hashedEmail);
15701568
}
15711569

15721570
IdentityApiRequest identityRequest = identityBuilder.build();

android-kit-base/src/test/kotlin/com/mparticle/kits/KitManagerImplTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ class KitManagerImplTest {
13061306
)
13071307
method.isAccessible = true
13081308
val result = method.invoke(manager, "", "hashed_Test@gmail.com", user, identityApi, mockedKitConfig, runnable)
1309-
verify(mockTask).addSuccessListener(any())
1309+
verify(runnable).run()
13101310
}
13111311

13121312
@Test
@@ -1460,7 +1460,7 @@ class KitManagerImplTest {
14601460
}
14611461

14621462
@Test
1463-
fun testConfirmHashedEmail_When_HashedEmailUserIdentityType_Is_UNASSIGNED() {
1463+
fun testConfirmHashedEmail_When_HashedEmailUserIdentityType_Is_Unknown() {
14641464
var runnable: Runnable = mock(Runnable::class.java)
14651465
var user: MParticleUser = mock(MParticleUser::class.java)
14661466
val instance = MockMParticle()
@@ -1472,7 +1472,7 @@ class KitManagerImplTest {
14721472
}
14731473
val mockedKitConfig = KitConfiguration.createKitConfiguration(configJSONObj)
14741474

1475-
`when`(mockedKitConfig.hashedEmailUserIdentityType).thenReturn("UNASSIGNED")
1475+
`when`(mockedKitConfig.hashedEmailUserIdentityType).thenReturn("Unknown")
14761476
`when`(sideloadedKit.configuration).thenReturn(mockedKitConfig)
14771477
val identityApi = mock(IdentityApi::class.java)
14781478
val oldHashedEmail = "hashed_old@example.com"
@@ -1488,7 +1488,7 @@ class KitManagerImplTest {
14881488
// add placement attributes here if needed
14891489
]
14901490
""".trimIndent(),
1491-
"hashedEmailUserIdentityType" to "UNASSIGNED"
1491+
"hashedEmailUserIdentityType" to "Unknown"
14921492
)
14931493
val field = KitConfiguration::class.java.getDeclaredField("settings")
14941494
field.isAccessible = true
@@ -1508,7 +1508,7 @@ class KitManagerImplTest {
15081508
)
15091509
method.isAccessible = true
15101510
val result = method.invoke(manager, "", "hashed_Test@gmail.com", user, identityApi, mockedKitConfig, runnable)
1511-
verify(mockTask).addSuccessListener(any())
1511+
verify(runnable).run()
15121512
}
15131513

15141514
@Test

0 commit comments

Comments
 (0)