diff --git a/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt b/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt index eac6083a6..ee8ab250a 100644 --- a/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt +++ b/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt @@ -72,8 +72,8 @@ class UserConsentModeNoneTest { mKeysLatch?.await(10, TimeUnit.SECONDS) mCountLatch?.await(10, TimeUnit.SECONDS) - Assert.assertTrue(mKeysPosted) Assert.assertTrue(mCountPosted) + Assert.assertTrue(mKeysPosted) } @Test @@ -207,6 +207,7 @@ class UserConsentModeNoneTest { .impressionsRefreshRate(3) .eventFlushInterval(3) .mtkRefreshRate(3) + .enableDebug() .userConsent(userConsent) .build() @@ -228,7 +229,7 @@ class UserConsentModeNoneTest { return HttpStreamResponseMock(200, null) } - override fun getResponse(uri: URI, method: HttpMethod, body: String): HttpResponseMock { + override fun getResponse(uri: URI, method: HttpMethod, body: String?): HttpResponseMock { println(uri.path) return if (uri.path.contains("/" + IntegrationHelper.ServicePath.MEMBERSHIPS)) { HttpResponseMock(200, IntegrationHelper.emptyAllSegments()) diff --git a/src/main/java/io/split/android/client/service/impressions/StrategyImpressionManager.java b/src/main/java/io/split/android/client/service/impressions/StrategyImpressionManager.java index c970f0182..5eb2a104e 100644 --- a/src/main/java/io/split/android/client/service/impressions/StrategyImpressionManager.java +++ b/src/main/java/io/split/android/client/service/impressions/StrategyImpressionManager.java @@ -1,7 +1,11 @@ package io.split.android.client.service.impressions; +import static io.split.android.client.utils.Utils.checkNotNull; + import androidx.core.util.Pair; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import io.split.android.client.impressions.Impression; @@ -14,16 +18,18 @@ public class StrategyImpressionManager implements ImpressionManager, PeriodicTra private final AtomicBoolean isTrackingEnabled = new AtomicBoolean(true); private final ProcessStrategy mProcessStrategy; private final ProcessStrategy mNoneStrategy; - private final PeriodicTracker[] mPeriodicTracker; + private final Set mPeriodicTrackers; public StrategyImpressionManager(Pair noneComponents, Pair strategy) { this(noneComponents.first, noneComponents.second, strategy.first, strategy.second); } StrategyImpressionManager(ProcessStrategy noneStrategy, PeriodicTracker noneTracker, ProcessStrategy strategy, PeriodicTracker strategyTracker) { - mProcessStrategy = strategy; - mNoneStrategy = noneStrategy; - mPeriodicTracker = new PeriodicTracker[]{noneTracker, strategyTracker}; + mProcessStrategy = checkNotNull(strategy); + mNoneStrategy = checkNotNull(noneStrategy); + mPeriodicTrackers = new HashSet<>(); + mPeriodicTrackers.add(noneTracker); + mPeriodicTrackers.add(strategyTracker); } @Override @@ -47,21 +53,21 @@ public void enableTracking(boolean enable) { @Override public void flush() { - for (PeriodicTracker tracker : mPeriodicTracker) { + for (PeriodicTracker tracker : mPeriodicTrackers) { tracker.flush(); } } @Override public void startPeriodicRecording() { - for (PeriodicTracker tracker : mPeriodicTracker) { + for (PeriodicTracker tracker : mPeriodicTrackers) { tracker.startPeriodicRecording(); } } @Override public void stopPeriodicRecording() { - for (PeriodicTracker tracker : mPeriodicTracker) { + for (PeriodicTracker tracker : mPeriodicTrackers) { tracker.stopPeriodicRecording(); } } diff --git a/src/main/java/io/split/android/client/service/impressions/strategy/ImpressionStrategyProvider.java b/src/main/java/io/split/android/client/service/impressions/strategy/ImpressionStrategyProvider.java index 691209838..c331ee61f 100644 --- a/src/main/java/io/split/android/client/service/impressions/strategy/ImpressionStrategyProvider.java +++ b/src/main/java/io/split/android/client/service/impressions/strategy/ImpressionStrategyProvider.java @@ -26,6 +26,8 @@ public class ImpressionStrategyProvider { private final ImpressionStrategyConfig mImpressionStrategyConfig; private final ImpressionsCounter mImpressionsCounter; private final ImpressionManagerRetryTimerProviderImpl mImpressionManagerRetryTimerProvider; + private final NoneStrategy mNoneStrategy; + private final NoneTracker mNoneTracker; public ImpressionStrategyProvider(SplitTaskExecutor splitTaskExecutor, SplitStorageContainer storageContainer, @@ -39,64 +41,15 @@ public ImpressionStrategyProvider(SplitTaskExecutor splitTaskExecutor, mImpressionStrategyConfig = config; mImpressionsCounter = new ImpressionsCounter(mImpressionStrategyConfig.getDedupeTimeIntervalInMs()); mImpressionManagerRetryTimerProvider = new ImpressionManagerRetryTimerProviderImpl(mSplitTaskExecutor); - } - - public Pair getStrategy(ImpressionsMode mode) { - ImpressionsObserverImpl impressionsObserver = new ImpressionsObserverImpl(mStorageContainer.getImpressionsObserverCachePersistentStorage(), ServiceConstants.LAST_SEEN_IMPRESSION_CACHE_SIZE); - RecorderSyncHelperImpl impressionsSyncHelper = new RecorderSyncHelperImpl<>( - SplitTaskType.IMPRESSIONS_RECORDER, - mStorageContainer.getImpressionsStorage(), - mImpressionStrategyConfig.getImpressionsQueueSize(), - mImpressionStrategyConfig.getImpressionsChunkSize(), - mSplitTaskExecutor); - if (mode == ImpressionsMode.DEBUG) { - DebugTracker tracker = new DebugTracker( - impressionsObserver, - impressionsSyncHelper, - mSplitTaskExecutor, - mSplitTaskFactory, - mImpressionManagerRetryTimerProvider.getImpressionsTimer(), - mImpressionStrategyConfig.getImpressionsRefreshRate()); - DebugStrategy debugStrategy = new DebugStrategy( - impressionsObserver, - impressionsSyncHelper, - mSplitTaskExecutor, - mSplitTaskFactory, - mTelemetryStorage); - return new Pair<>(debugStrategy, tracker); - } else if (mode == ImpressionsMode.NONE) { - return new Pair<>(null, null); - } else { - OptimizedStrategy optimizedStrategy = new OptimizedStrategy( - impressionsObserver, - mImpressionsCounter, - impressionsSyncHelper, - mSplitTaskExecutor, - mSplitTaskFactory, - mTelemetryStorage, - mImpressionStrategyConfig.getDedupeTimeIntervalInMs()); - OptimizedTracker optimizedTracker = new OptimizedTracker( - impressionsObserver, - impressionsSyncHelper, - mSplitTaskExecutor, - mSplitTaskFactory, - mImpressionManagerRetryTimerProvider.getImpressionsTimer(), - mImpressionStrategyConfig.getImpressionsRefreshRate(), - mImpressionStrategyConfig.isUserConsentGranted() - ); - return new Pair<>(optimizedStrategy, optimizedTracker); - } - } - public Pair getNoneComponents() { UniqueKeysTracker uniqueKeysTracker = new UniqueKeysTrackerImpl(); - NoneStrategy noneStrategy = new NoneStrategy( + mNoneStrategy = new NoneStrategy( mSplitTaskExecutor, mSplitTaskFactory, mImpressionsCounter, uniqueKeysTracker, mImpressionStrategyConfig.isUserConsentGranted()); - NoneTracker noneTracker = new NoneTracker( + mNoneTracker = new NoneTracker( mSplitTaskExecutor, mSplitTaskFactory, mImpressionsCounter, @@ -106,6 +59,57 @@ public Pair getNoneComponents() { mImpressionStrategyConfig.getImpressionsCounterRefreshRate(), mImpressionStrategyConfig.getUniqueKeysRefreshRate(), mImpressionStrategyConfig.isUserConsentGranted()); - return new Pair<>(noneStrategy, noneTracker); + } + + public Pair getStrategy(ImpressionsMode mode) { + ImpressionsObserverImpl impressionsObserver = new ImpressionsObserverImpl(mStorageContainer.getImpressionsObserverCachePersistentStorage(), ServiceConstants.LAST_SEEN_IMPRESSION_CACHE_SIZE); + RecorderSyncHelperImpl impressionsSyncHelper = new RecorderSyncHelperImpl<>( + SplitTaskType.IMPRESSIONS_RECORDER, + mStorageContainer.getImpressionsStorage(), + mImpressionStrategyConfig.getImpressionsQueueSize(), + mImpressionStrategyConfig.getImpressionsChunkSize(), + mSplitTaskExecutor); + switch (mode) { + case DEBUG: + DebugTracker tracker = new DebugTracker( + impressionsObserver, + impressionsSyncHelper, + mSplitTaskExecutor, + mSplitTaskFactory, + mImpressionManagerRetryTimerProvider.getImpressionsTimer(), + mImpressionStrategyConfig.getImpressionsRefreshRate()); + DebugStrategy debugStrategy = new DebugStrategy( + impressionsObserver, + impressionsSyncHelper, + mSplitTaskExecutor, + mSplitTaskFactory, + mTelemetryStorage); + return new Pair<>(debugStrategy, tracker); + case NONE: + return getNoneComponents(); + default: + OptimizedStrategy optimizedStrategy = new OptimizedStrategy( + impressionsObserver, + mImpressionsCounter, + impressionsSyncHelper, + mSplitTaskExecutor, + mSplitTaskFactory, + mTelemetryStorage, + mImpressionStrategyConfig.getDedupeTimeIntervalInMs()); + OptimizedTracker optimizedTracker = new OptimizedTracker( + impressionsObserver, + impressionsSyncHelper, + mSplitTaskExecutor, + mSplitTaskFactory, + mImpressionManagerRetryTimerProvider.getImpressionsTimer(), + mImpressionStrategyConfig.getImpressionsRefreshRate(), + mImpressionStrategyConfig.isUserConsentGranted() + ); + return new Pair<>(optimizedStrategy, optimizedTracker); + } + } + + public Pair getNoneComponents() { + return new Pair<>(mNoneStrategy, mNoneTracker); } }