Skip to content

Commit 66b0ce8

Browse files
author
markvdouw
committed
Adding feature flag for identity caching feature
Pending read from it, as of know is disabled.
1 parent c22df1d commit 66b0ce8

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

android-core/src/androidTest/kotlin/com.mparticle/identity/IdentityApiStartTest.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,18 @@ class IdentityApiStartTest : BaseCleanInstallEachTest() {
6363
@Test
6464
@Throws(Exception::class)
6565
fun testNoInitialIdentity() {
66+
val currentMpid = ran.nextLong()
67+
val identities = mRandomUtils.randomUserIdentities
6668
startMParticle()
67-
TestCase.assertEquals(mServer.Requests().identify.size, 1)
69+
MParticle.getInstance()?.Internal()?.configManager?.setMpid(currentMpid, ran.nextBoolean())
70+
for ((key, value) in identities) {
71+
AccessUtils.setUserIdentity(value, key, currentMpid)
72+
}
73+
com.mparticle.internal.AccessUtils.awaitMessageHandler()
6874
mServer = MockServer.getNewInstance(mContext)
6975
startMParticle()
70-
// Due to caching
71-
TestCase.assertEquals(mServer.Requests().identify.size, 0)
76+
TestCase.assertEquals(mServer.Requests().identify.size, 1)
77+
assertIdentitiesMatch(mServer.Requests().identify[0], identities, false)
7278
}
7379

7480
/**

android-core/src/main/java/com/mparticle/identity/IdentityApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ private void reset() {
364364
}
365365

366366
private boolean shouldMakeRequest(IdentityApiRequest identityRequest, boolean acceptCachedResponse, long lastIdentityCall) {
367-
if (!acceptCachedResponse) {
367+
if (!acceptCachedResponse || !mConfigManager.isIdentityCachingEnabled()) {
368368
return true;
369369
}
370370
boolean hasTimedOut = lastIdentityCall == -1L || (lastIdentityCall + (timeoutSeconds * 1000) > System.currentTimeMillis());

android-core/src/main/java/com/mparticle/internal/ConfigManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class ConfigManager {
7272
static final String DATAPLAN_BLOCK_USER_IDENTITIES = "id";
7373
public static final String KIT_CONFIG_KEY = "kit_config";
7474
static final String MIGRATED_TO_KIT_SHARED_PREFS = "is_mig_kit_sp";
75+
private static final String IDENTITY_CACHING_ENABLED = "identityCachingEnabled";
7576

7677
private static final int DEVMODE_UPLOAD_INTERVAL_MILLISECONDS = 10 * 1000;
7778
private static final int DEFAULT_MAX_ALIAS_WINDOW_DAYS = 90;
@@ -90,6 +91,7 @@ public class ConfigManager {
9091
private JSONObject mProviderPersistence;
9192
private int mRampValue = -1;
9293
private int mUserBucket = -1;
94+
private boolean identityCachingEnabled = false;
9395

9496
private int mSessionTimeoutInterval = -1;
9597
private int mUploadInterval = -1;
@@ -414,6 +416,9 @@ private synchronized void updateCoreConfig(JSONObject responseJSON, boolean newC
414416
mSendOoEvents = false;
415417
}
416418

419+
//TODO Read from identityCachingEnabled feature flag
420+
editor.putBoolean(IDENTITY_CACHING_ENABLED, identityCachingEnabled);
421+
417422
if (responseJSON.has(ProviderPersistence.KEY_PERSISTENCE)) {
418423
setProviderPersistence(new ProviderPersistence(responseJSON, mContext));
419424
} else {
@@ -520,6 +525,10 @@ public long getInfluenceOpenTimeoutMillis() {
520525
return mInfluenceOpenTimeout;
521526
}
522527

528+
public boolean isIdentityCachingEnabled() {
529+
return identityCachingEnabled;
530+
}
531+
523532
private void applyConfig() {
524533
if (getLogUnhandledExceptions()) {
525534
enableUncaughtExceptionLogging(false);

testutils/src/main/java/com/mparticle/testutils/BaseAbstractTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mparticle.testutils;
22

3+
import static org.junit.Assert.assertTrue;
34
import static org.junit.Assert.fail;
45

56
import android.app.Activity;
@@ -103,6 +104,7 @@ protected void startMParticle(MParticleOptions.Builder optionsBuilder) throws In
103104
MParticle.start(optionsBuilder.build());
104105
mServer.setupHappyIdentify(mStartingMpid);
105106
latch.await();
107+
assertTrue(called.value);
106108
}
107109

108110
protected void goToBackground() {

0 commit comments

Comments
 (0)