From 19f3c493456ead540fe4482a5b82c5d49ddca8be Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 20:52:15 +0600 Subject: [PATCH 1/9] [FSSDK-10758] implement vuid configuration independent of odp --- .../ab/android/sdk/OptimizelyManager.java | 22 ++++-- .../sdk/OptimizelyManagerBuilderTest.java | 79 +++++++++++++++++-- .../sdk/OptimizelyManagerIntervalTest.java | 19 ++++- .../ab/android/odp/VuidManagerTest.kt | 64 +++++++++++++-- .../optimizely/ab/android/odp/VuidManager.kt | 26 ++++-- .../ab/android/shared/OptlyStorage.java | 4 + 6 files changed, 184 insertions(+), 30 deletions(-) diff --git a/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java b/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java index 57e4cdaf..ac43c8e6 100644 --- a/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java +++ b/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java @@ -48,11 +48,7 @@ import com.optimizely.ab.event.BatchEventProcessor; import com.optimizely.ab.event.EventHandler; import com.optimizely.ab.event.EventProcessor; -import com.optimizely.ab.event.internal.BuildVersionInfo; -import com.optimizely.ab.event.internal.ClientEngineInfo; -import com.optimizely.ab.event.internal.payload.EventBatch; import com.optimizely.ab.notification.NotificationCenter; -import com.optimizely.ab.notification.UpdateConfigNotification; import com.optimizely.ab.odp.ODPApiManager; import com.optimizely.ab.odp.ODPEventManager; import com.optimizely.ab.odp.ODPManager; @@ -65,7 +61,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -792,6 +787,7 @@ public static class Builder { private int timeoutForODPSegmentFetchInSecs = 10; private int timeoutForODPEventDispatchInSecs = 10; private boolean odpEnabled = true; + private boolean vuidEnabled = false; private String vuid = null; private String customSdkName = null; @@ -1031,6 +1027,15 @@ public Builder withODPDisabled() { return this; } + /** + * Enable Vuid + * @return this {@link Builder} instance + */ + public Builder withVuidEnabled() { + this.vuidEnabled = true; + return this; + } + /** * Override the default (SDK-generated and persistent) vuid. * @param vuid a user-defined vuid value @@ -1120,8 +1125,11 @@ public OptimizelyManager build(Context context) { } - if (vuid == null) { - vuid = VuidManager.Companion.getShared(context).getVuid(); + VuidManager vuidManager = VuidManager.Companion.getInstance(); + vuidManager.configure(vuidEnabled, context); + + if (vuid == null && vuidEnabled) { + vuid = vuidManager.getVuid(); } ODPManager odpManager = null; diff --git a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java index b9f5f276..d6384321 100644 --- a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java +++ b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java @@ -17,9 +17,7 @@ package com.optimizely.ab.android.sdk; import android.content.Context; -import android.graphics.Path; -import com.optimizely.ab.Optimizely; import com.optimizely.ab.android.datafile_handler.DatafileHandler; import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler; import com.optimizely.ab.android.event_handler.DefaultEventHandler; @@ -28,7 +26,6 @@ import com.optimizely.ab.android.odp.ODPSegmentClient; import com.optimizely.ab.android.odp.VuidManager; import com.optimizely.ab.android.shared.DatafileConfig; -import com.optimizely.ab.android.shared.WorkerScheduler; import com.optimizely.ab.android.user_profile.DefaultUserProfileService; import com.optimizely.ab.bucketing.UserProfileService; import com.optimizely.ab.error.ErrorHandler; @@ -36,22 +33,24 @@ import com.optimizely.ab.event.EventHandler; import com.optimizely.ab.event.EventProcessor; import com.optimizely.ab.notification.NotificationCenter; -import com.optimizely.ab.odp.ODPApiManager; import com.optimizely.ab.odp.ODPEventManager; import com.optimizely.ab.odp.ODPManager; import com.optimizely.ab.odp.ODPSegmentManager; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.runners.MockitoJUnitRunner; +import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; import org.slf4j.Logger; import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.anyLong; @@ -63,25 +62,27 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.verifyNew; import static org.powermock.api.mockito.PowerMockito.whenNew; -import java.sql.Time; import java.util.Map; import java.util.concurrent.TimeUnit; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") -@PrepareForTest({OptimizelyManager.class, BatchEventProcessor.class, DefaultEventHandler.class, ODPManager.class, ODPSegmentManager.class, ODPEventManager.class}) +@PrepareForTest({OptimizelyManager.class, BatchEventProcessor.class, DefaultEventHandler.class, ODPManager.class, ODPSegmentManager.class, ODPEventManager.class, VuidManager.class}) public class OptimizelyManagerBuilderTest { private String testProjectId = "7595190003"; private String testSdkKey = "1234"; private Logger logger; + private VuidManager mockVuidManager; + private String minDatafile = "{\n" + "experiments: [ ],\n" + "version: \"2\",\n" + @@ -101,6 +102,19 @@ public class OptimizelyManagerBuilderTest { public void setup() throws Exception { mockContext = mock(Context.class); mockDatafileHandler = mock(DefaultDatafileHandler.class); + + mockStatic(VuidManager.class); + VuidManager.Companion mockCompanion = PowerMockito.mock(VuidManager.Companion.class); + mockVuidManager = PowerMockito.mock(VuidManager.class); + PowerMockito.doReturn(mockVuidManager).when(mockCompanion).getInstance(); + Whitebox.setInternalState( + VuidManager.class, "Companion", + mockCompanion + ); + } + + @After + public void cleanUp() { } /** @@ -400,4 +414,55 @@ public void testBuildWithODP_defaultCommonDataAndIdentifiers() throws Exception assertEquals(identifiers.size(), 1); } + ODPManager.Builder getMockODPManagerBuilder() { + ODPManager.Builder mockBuilder = PowerMockito.mock(ODPManager.Builder.class); + when(mockBuilder.withApiManager(any())).thenReturn(mockBuilder); + when(mockBuilder.withSegmentCacheSize(any())).thenReturn(mockBuilder); + when(mockBuilder.withSegmentCacheTimeout(any())).thenReturn(mockBuilder); + when(mockBuilder.withSegmentManager(any())).thenReturn(mockBuilder); + when(mockBuilder.withEventManager(any())).thenReturn(mockBuilder); + when(mockBuilder.withUserCommonData(any())).thenReturn(mockBuilder); + when(mockBuilder.withUserCommonIdentifiers(any())).thenReturn(mockBuilder); + return mockBuilder; + } + @Test + public void testBuildWithVuidDisabled() throws Exception { + mockStatic(ODPManager.class); + ODPManager.Builder mockBuilder = getMockODPManagerBuilder(); + when(mockBuilder.build()).thenReturn(mock(ODPManager.class)); + when(ODPManager.builder()).thenReturn(mockBuilder); + + OptimizelyManager manager = OptimizelyManager.builder() + .withSDKKey(testSdkKey) + .build(mockContext); + + verify(mockVuidManager, times(1)).configure(eq(false), any(Context.class)); + + ArgumentCaptor> identifiersCaptor = ArgumentCaptor.forClass(Map.class); + verify(mockBuilder).withUserCommonIdentifiers(identifiersCaptor.capture()); + Map identifiers = identifiersCaptor.getValue(); + assertFalse(identifiers.containsKey("vuid")); + } + + @Test + public void testBuildWithVuidEnabled() throws Exception { + mockStatic(ODPManager.class); + ODPManager.Builder mockBuilder = getMockODPManagerBuilder(); + when(mockBuilder.build()).thenReturn(mock(ODPManager.class)); + when(ODPManager.builder()).thenReturn(mockBuilder); + + when(mockVuidManager.getVuid()).thenReturn("vuid_test"); + + OptimizelyManager manager = OptimizelyManager.builder() + .withSDKKey(testSdkKey) + .withVuidEnabled() + .build(mockContext); + + verify(mockVuidManager, times(1)).configure(eq(true), any(Context.class)); + + ArgumentCaptor> identifiersCaptor = ArgumentCaptor.forClass(Map.class); + verify(mockBuilder).withUserCommonIdentifiers(identifiersCaptor.capture()); + Map identifiers = identifiersCaptor.getValue(); + assertEquals(identifiers.get("vuid"), "vuid_test"); + } } diff --git a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerIntervalTest.java b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerIntervalTest.java index 45fceb29..f707c61a 100644 --- a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerIntervalTest.java +++ b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerIntervalTest.java @@ -18,13 +18,14 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyList; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.doReturn; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.verifyNew; import static org.powermock.api.mockito.PowerMockito.whenNew; @@ -33,9 +34,9 @@ import com.optimizely.ab.android.datafile_handler.DatafileHandler; import com.optimizely.ab.android.event_handler.DefaultEventHandler; +import com.optimizely.ab.android.odp.VuidManager; import com.optimizely.ab.android.shared.DatafileConfig; import com.optimizely.ab.bucketing.UserProfileService; -import com.optimizely.ab.error.ErrorHandler; import com.optimizely.ab.event.BatchEventProcessor; import com.optimizely.ab.event.EventHandler; import com.optimizely.ab.event.EventProcessor; @@ -45,11 +46,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.powermock.core.PowerMockUtils; +import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; import org.slf4j.Logger; import java.util.concurrent.BlockingQueue; @@ -59,7 +61,7 @@ @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") -@PrepareForTest({OptimizelyManager.class, BatchEventProcessor.class, DefaultEventHandler.class}) +@PrepareForTest({OptimizelyManager.class, BatchEventProcessor.class, DefaultEventHandler.class, VuidManager.class}) public class OptimizelyManagerIntervalTest { private Logger logger; @@ -76,6 +78,15 @@ public void setup() throws Exception { mockEventHandler = mock(DefaultEventHandler.class); mockStatic(DefaultEventHandler.class); when(DefaultEventHandler.getInstance(any())).thenReturn(mockEventHandler); + + mockStatic(VuidManager.class); + VuidManager.Companion mockCompanion = PowerMockito.mock(VuidManager.Companion.class); + VuidManager mockVuidManager = PowerMockito.mock(VuidManager.class); + doReturn(mockVuidManager).when(mockCompanion).getInstance(); + Whitebox.setInternalState( + VuidManager.class, "Companion", + mockCompanion + ); } // DatafileDownloadInterval diff --git a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt index cbbbfcfe..cd75ec3a 100644 --- a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt +++ b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt @@ -22,6 +22,8 @@ import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test @@ -40,7 +42,8 @@ class VuidManagerTest { // remove a singleton instance VuidManager.removeSharedForTesting() - vuidManager = VuidManager.getShared(context) + vuidManager = VuidManager.getInstance() + vuidManager.configure(true, context) } @After @@ -51,6 +54,16 @@ class VuidManagerTest { editor.commit() } + fun saveInSharedPrefs(key: String, value: String) { + val sharedPreferences = context.getSharedPreferences("optly", Context.MODE_PRIVATE).edit() + sharedPreferences.putString(key, value) + sharedPreferences.apply() + } + + fun getFromSharedPrefs(key: String): String? { + return context.getSharedPreferences("optly", Context.MODE_PRIVATE).getString(key, null) + } + @Test fun makeVuid() { val vuid = vuidManager.makeVuid() @@ -90,16 +103,22 @@ class VuidManagerTest { @Test fun autoLoaded() { - val vuid1 = VuidManager.getShared(context).vuid + val vuidManager1 = VuidManager.getInstance() + vuidManager1.configure(true, context) + val vuid1 = vuidManager1.vuid assertTrue("vuid should be auto loaded when constructed", vuid1.startsWith("vuid_")) - val vuid2 = VuidManager.getShared(context).vuid + val vuidManager2 = VuidManager.getInstance() + vuidManager2.configure(true, context) + val vuid2 = vuidManager2.vuid assertEquals("the same vuid should be returned when getting a singleton", vuid1, vuid2) // remove shared instance, so will be re-instantiated VuidManager.removeSharedForTesting() - val vuid3 = VuidManager.getShared(context).vuid + val vuidManager3 = VuidManager.getInstance() + vuidManager3.configure(true, context) + val vuid3 = vuidManager3.vuid assertEquals("the saved vuid should be returned when instantiated again", vuid2, vuid3) // remove saved vuid @@ -107,8 +126,43 @@ class VuidManagerTest { // remove shared instance, so will be re-instantiated VuidManager.removeSharedForTesting() - val vuid4 = VuidManager.getShared(context).vuid + val vuidManager4 = VuidManager.getInstance() + vuidManager4.configure(true, context) + val vuid4 = vuidManager4.vuid assertNotEquals("a new vuid should be returned when storage cleared and re-instantiated", vuid3, vuid4) assertTrue(vuid4.startsWith("vuid_")) } + + @Test + fun configureWithVuidDisabled() { + cleanSharedPrefs() + saveInSharedPrefs("vuid", "vuid_test") + VuidManager.removeSharedForTesting() + vuidManager = VuidManager.getInstance() + vuidManager.configure(false, context) + assertNull(getFromSharedPrefs("vuid")) + assertEquals(vuidManager.vuid, "") + } + + @Test + fun configureWithVuidEnabledWhenVuidAlreadyExists() { + cleanSharedPrefs() + saveInSharedPrefs("vuid", "vuid_test") + VuidManager.removeSharedForTesting() + vuidManager = VuidManager.getInstance() + vuidManager.configure(true, context) + assertEquals(vuidManager.vuid, "vuid_test") + } + + @Test + fun configureWithVuidEnabledWhenVuidDoesNotExist() { + cleanSharedPrefs() + VuidManager.removeSharedForTesting() + vuidManager = VuidManager.getInstance() + vuidManager.configure(true, context) + assertTrue(vuidManager.vuid.startsWith("vuid_")) + assertNotNull(getFromSharedPrefs("vuid")) + getFromSharedPrefs("vuid")?.let { assertTrue(it.startsWith("vuid_")) } + assertEquals(getFromSharedPrefs("vuid"), vuidManager.vuid) + } } diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt index 5077141b..34be989b 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt @@ -19,20 +19,17 @@ import androidx.annotation.VisibleForTesting import com.optimizely.ab.android.shared.OptlyStorage import java.util.UUID -class VuidManager private constructor(context: Context) { +class VuidManager private constructor() { var vuid = "" private val keyForVuid = "vuid" // stored in the private "optly" storage - init { - this.vuid = load(context) - } - companion object { @Volatile private var INSTANCE: VuidManager? = null @Synchronized - fun getShared(context: Context): VuidManager = INSTANCE ?: VuidManager(context).also { INSTANCE = it } + fun getInstance(): VuidManager = INSTANCE ?: + VuidManager().also { INSTANCE = it } fun isVuid(visitorId: String): Boolean { return visitorId.startsWith("vuid_", ignoreCase = true) @@ -44,6 +41,14 @@ class VuidManager private constructor(context: Context) { } } + fun configure(enableVuid: Boolean, context: Context) { + if (!enableVuid) { + removeVuid(context); + } else { + this.vuid = load(context) + } + } + @VisibleForTesting fun makeVuid(): String { val maxLength = 32 // required by ODP server @@ -57,7 +62,9 @@ class VuidManager private constructor(context: Context) { fun load(context: Context): String { val storage = OptlyStorage(context) val oldVuid = storage.getString(keyForVuid, null) - if (oldVuid != null) return oldVuid + if (oldVuid != null) { + return oldVuid + } val vuid = makeVuid() save(context, vuid) @@ -69,4 +76,9 @@ class VuidManager private constructor(context: Context) { val storage = OptlyStorage(context) storage.saveString(keyForVuid, vuid) } + + fun removeVuid(context: Context) { + val storage = OptlyStorage(context) + storage.remove(keyForVuid); + } } diff --git a/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java b/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java index 260acbb7..f726491c 100644 --- a/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java +++ b/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java @@ -91,4 +91,8 @@ private SharedPreferences.Editor getWritablePrefs() { private SharedPreferences getReadablePrefs() { return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); } + + public void remove(String key) { + getWritablePrefs().remove(key); + } } From b230ce6d2c8dec0f4c3af64caf819b4074996e7b Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 22:17:39 +0600 Subject: [PATCH 2/9] fix --- .../ab/android/sdk/OptimizelyManagerBuilderTest.java | 4 ++++ .../java/com/optimizely/ab/android/odp/VuidManagerTest.kt | 4 ++++ .../java/com/optimizely/ab/android/shared/OptlyStorage.java | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java index d6384321..81309a72 100644 --- a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java +++ b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java @@ -442,6 +442,8 @@ public void testBuildWithVuidDisabled() throws Exception { verify(mockBuilder).withUserCommonIdentifiers(identifiersCaptor.capture()); Map identifiers = identifiersCaptor.getValue(); assertFalse(identifiers.containsKey("vuid")); + + when(ODPManager.builder()).thenCallRealMethod(); } @Test @@ -464,5 +466,7 @@ public void testBuildWithVuidEnabled() throws Exception { verify(mockBuilder).withUserCommonIdentifiers(identifiersCaptor.capture()); Map identifiers = identifiersCaptor.getValue(); assertEquals(identifiers.get("vuid"), "vuid_test"); + + when(ODPManager.builder()).thenCallRealMethod(); } } diff --git a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt index cd75ec3a..1a3c9f15 100644 --- a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt +++ b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt @@ -18,6 +18,7 @@ import android.content.Context import android.content.SharedPreferences import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation +import com.optimizely.ab.android.shared.OptlyStorage import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -138,9 +139,11 @@ class VuidManagerTest { cleanSharedPrefs() saveInSharedPrefs("vuid", "vuid_test") VuidManager.removeSharedForTesting() + vuidManager = VuidManager.getInstance() vuidManager.configure(false, context) assertNull(getFromSharedPrefs("vuid")) + assertEquals(vuidManager.vuid, "") } @@ -158,6 +161,7 @@ class VuidManagerTest { fun configureWithVuidEnabledWhenVuidDoesNotExist() { cleanSharedPrefs() VuidManager.removeSharedForTesting() + assertNull(getFromSharedPrefs("vuid")) vuidManager = VuidManager.getInstance() vuidManager.configure(true, context) assertTrue(vuidManager.vuid.startsWith("vuid_")) diff --git a/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java b/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java index f726491c..83e22d09 100644 --- a/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java +++ b/shared/src/main/java/com/optimizely/ab/android/shared/OptlyStorage.java @@ -93,6 +93,6 @@ private SharedPreferences getReadablePrefs() { } public void remove(String key) { - getWritablePrefs().remove(key); + getWritablePrefs().remove(key).apply(); } } From 70db4c1e625151cc24b46b0874c56729e61a482c Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 22:26:16 +0600 Subject: [PATCH 3/9] upd --- .../ab/android/sdk/OptimizelyManagerBuilderTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java index 81309a72..6753c327 100644 --- a/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java +++ b/android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java @@ -113,10 +113,6 @@ public void setup() throws Exception { ); } - @After - public void cleanUp() { - } - /** * Verify that building the {@link OptimizelyManager} with a polling interval greater than 60 * seconds is properly registered. @@ -425,6 +421,7 @@ ODPManager.Builder getMockODPManagerBuilder() { when(mockBuilder.withUserCommonIdentifiers(any())).thenReturn(mockBuilder); return mockBuilder; } + @Test public void testBuildWithVuidDisabled() throws Exception { mockStatic(ODPManager.class); From 29a6a2df0db6a5e49d3ec1da4ebbba49a84a4b66 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 22:29:20 +0600 Subject: [PATCH 4/9] up --- .../java/com/optimizely/ab/android/odp/VuidManagerTest.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt index 1a3c9f15..58cb94a3 100644 --- a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt +++ b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt @@ -142,8 +142,8 @@ class VuidManagerTest { vuidManager = VuidManager.getInstance() vuidManager.configure(false, context) - assertNull(getFromSharedPrefs("vuid")) + assertNull(getFromSharedPrefs("vuid")) assertEquals(vuidManager.vuid, "") } @@ -152,8 +152,10 @@ class VuidManagerTest { cleanSharedPrefs() saveInSharedPrefs("vuid", "vuid_test") VuidManager.removeSharedForTesting() + vuidManager = VuidManager.getInstance() vuidManager.configure(true, context) + assertEquals(vuidManager.vuid, "vuid_test") } @@ -162,8 +164,10 @@ class VuidManagerTest { cleanSharedPrefs() VuidManager.removeSharedForTesting() assertNull(getFromSharedPrefs("vuid")) + vuidManager = VuidManager.getInstance() vuidManager.configure(true, context) + assertTrue(vuidManager.vuid.startsWith("vuid_")) assertNotNull(getFromSharedPrefs("vuid")) getFromSharedPrefs("vuid")?.let { assertTrue(it.startsWith("vuid_")) } From c0fef2665658c2860ee0eceb71c7f280252a838a Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 22:46:44 +0600 Subject: [PATCH 5/9] syc --- odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt index 34be989b..4af6dd80 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt @@ -41,6 +41,7 @@ class VuidManager private constructor() { } } + @Synchronized fun configure(enableVuid: Boolean, context: Context) { if (!enableVuid) { removeVuid(context); From 87f8ce4b8e889800e710191579c6f956c572db57 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Thu, 31 Oct 2024 23:07:11 +0600 Subject: [PATCH 6/9] fix --- .../java/com/optimizely/ab/android/odp/VuidManagerTest.kt | 1 - .../main/java/com/optimizely/ab/android/odp/VuidManager.kt | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt index 58cb94a3..3151bf2c 100644 --- a/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt +++ b/odp/src/androidTest/java/com/optimizely/ab/android/odp/VuidManagerTest.kt @@ -18,7 +18,6 @@ import android.content.Context import android.content.SharedPreferences import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation -import com.optimizely.ab.android.shared.OptlyStorage import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt index 4af6dd80..40d7fcf0 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt @@ -28,8 +28,7 @@ class VuidManager private constructor() { private var INSTANCE: VuidManager? = null @Synchronized - fun getInstance(): VuidManager = INSTANCE ?: - VuidManager().also { INSTANCE = it } + fun getInstance(): VuidManager = INSTANCE ?: VuidManager().also { INSTANCE = it } fun isVuid(visitorId: String): Boolean { return visitorId.startsWith("vuid_", ignoreCase = true) @@ -44,7 +43,7 @@ class VuidManager private constructor() { @Synchronized fun configure(enableVuid: Boolean, context: Context) { if (!enableVuid) { - removeVuid(context); + removeVuid(context) } else { this.vuid = load(context) } @@ -80,6 +79,6 @@ class VuidManager private constructor() { fun removeVuid(context: Context) { val storage = OptlyStorage(context) - storage.remove(keyForVuid); + storage.remove(keyForVuid) } } From a71ae66316c2c3798f77e90f19081ea96a8a9a1f Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 1 Nov 2024 00:44:41 +0600 Subject: [PATCH 7/9] update --- .../java/com/optimizely/ab/android/sdk/OptimizelyClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java b/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java index 2332868d..8c3a6265 100644 --- a/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java +++ b/android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java @@ -80,7 +80,7 @@ public class OptimizelyClient { So, we start with an empty map of default attributes until the manager is initialized. */ - if (isValid()) { + if (isValid() && vuid != null) { // identifiers are empty here since vuid will be inserted by java-sdk core sendODPEvent(null, "client_initialized", null, null); } From e12cc9e258600beab7314920ece8cbca77b56634 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 1 Nov 2024 17:24:13 +0600 Subject: [PATCH 8/9] fix --- odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt index 40d7fcf0..a9b0ae76 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt @@ -44,6 +44,7 @@ class VuidManager private constructor() { fun configure(enableVuid: Boolean, context: Context) { if (!enableVuid) { removeVuid(context) + this.vuid = ""; } else { this.vuid = load(context) } From 366cc2d582cd9e6ff1b4e89aabede1f857b64e9a Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 1 Nov 2024 18:12:58 +0600 Subject: [PATCH 9/9] fix --- odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt index a9b0ae76..391b413c 100644 --- a/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt +++ b/odp/src/main/java/com/optimizely/ab/android/odp/VuidManager.kt @@ -44,7 +44,7 @@ class VuidManager private constructor() { fun configure(enableVuid: Boolean, context: Context) { if (!enableVuid) { removeVuid(context) - this.vuid = ""; + this.vuid = "" } else { this.vuid = load(context) }