Skip to content

Commit

Permalink
WIP integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Nov 29, 2024
1 parent a416b0c commit f5373dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
18 changes: 2 additions & 16 deletions src/main/java/io/split/android/client/SplitFactoryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.split.android.client.network.SplitHttpHeadersBuilder;
import io.split.android.client.service.ServiceFactory;
import io.split.android.client.service.SplitApiFacade;
import io.split.android.client.service.executor.SplitTaskExecutionListener;
import io.split.android.client.service.executor.SplitTaskExecutor;
import io.split.android.client.service.executor.SplitTaskFactory;
import io.split.android.client.service.http.mysegments.MySegmentsFetcherFactory;
Expand Down Expand Up @@ -70,7 +69,6 @@
import io.split.android.client.shared.ClientComponentsRegisterImpl;
import io.split.android.client.shared.UserConsent;
import io.split.android.client.storage.attributes.PersistentAttributesStorage;
import io.split.android.client.storage.cipher.EncryptionMigrationTask;
import io.split.android.client.storage.cipher.SplitCipher;
import io.split.android.client.storage.cipher.SplitCipherFactory;
import io.split.android.client.storage.cipher.SplitEncryptionLevel;
Expand Down Expand Up @@ -399,21 +397,9 @@ public ProcessStrategy getImpressionStrategy(SplitTaskExecutor splitTaskExecutor
.getStrategy(config.impressionsMode());
}

SplitCipher migrateEncryption(String apiKey,
SplitRoomDatabase splitDatabase,
SplitTaskExecutor splitTaskExecutor,
final boolean encryptionEnabled,
SplitTaskExecutionListener executionListener) {

SplitCipher toCipher = SplitCipherFactory.create(apiKey, encryptionEnabled ? SplitEncryptionLevel.AES_128_CBC :
@Nullable SplitCipher getCipher(String apiKey, boolean encryptionEnabled) {
return SplitCipherFactory.create(apiKey, encryptionEnabled ? SplitEncryptionLevel.AES_128_CBC :
SplitEncryptionLevel.NONE);
splitTaskExecutor.submit(new EncryptionMigrationTask(apiKey,
splitDatabase,
encryptionEnabled,
toCipher),
executionListener);

return toCipher;
}

@Nullable
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/io/split/android/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
import io.split.android.client.network.HttpClientImpl;
import io.split.android.client.service.SplitApiFacade;
import io.split.android.client.service.executor.SplitSingleThreadTaskExecutor;
import io.split.android.client.service.executor.SplitTaskExecutionInfo;
import io.split.android.client.service.executor.SplitTaskExecutionListener;
import io.split.android.client.service.executor.SplitTaskExecutor;
import io.split.android.client.service.executor.SplitTaskExecutorImpl;
import io.split.android.client.service.executor.SplitTaskFactory;
import io.split.android.client.service.executor.SplitTaskFactoryImpl;
import io.split.android.client.service.impressions.ImpressionManager;
import io.split.android.client.service.impressions.StrategyImpressionManager;
import io.split.android.client.service.sseclient.sseclient.StreamingComponents;
import io.split.android.client.service.synchronizer.RolloutCacheManagerImpl;
import io.split.android.client.service.synchronizer.SyncManager;
import io.split.android.client.service.synchronizer.Synchronizer;
import io.split.android.client.service.synchronizer.SynchronizerImpl;
Expand All @@ -49,6 +48,7 @@
import io.split.android.client.shared.SplitClientContainer;
import io.split.android.client.shared.SplitClientContainerImpl;
import io.split.android.client.shared.UserConsent;
import io.split.android.client.storage.cipher.EncryptionMigrationTask;
import io.split.android.client.storage.cipher.SplitCipher;
import io.split.android.client.storage.common.SplitStorageContainer;
import io.split.android.client.storage.db.SplitRoomDatabase;
Expand Down Expand Up @@ -84,9 +84,6 @@ public class SplitFactoryImpl implements SplitFactory {
private final SplitClientContainer mClientContainer;
private final UserConsentManager mUserConsentManager;

@SuppressWarnings("FieldCanBeLocal") // keeping the reference on purpose
private final SplitTaskExecutionListener mMigrationExecutionListener;

public SplitFactoryImpl(@NonNull String apiToken, @NonNull Key key, @NonNull SplitClientConfig config, @NonNull Context context)
throws URISyntaxException {
this(apiToken, key, config, context,
Expand Down Expand Up @@ -163,20 +160,11 @@ private SplitFactoryImpl(@NonNull String apiToken, @NonNull Key key, @NonNull Sp
defaultHttpClient.addStreamingHeaders(factoryHelper.buildStreamingHeaders(apiToken));

SplitTaskExecutor splitTaskExecutor = new SplitTaskExecutorImpl();
splitTaskExecutor.pause();

EventsManagerCoordinator mEventsManagerCoordinator = new EventsManagerCoordinator();

mMigrationExecutionListener = new SplitTaskExecutionListener() {
@Override
public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) {
mEventsManagerCoordinator.notifyInternalEvent(SplitInternalEvent.ENCRYPTION_MIGRATION_DONE);
}
};
SplitCipher splitCipher = factoryHelper.migrateEncryption(mApiKey,
splitDatabase,
splitTaskExecutor,
config.encryptionEnabled(),
mMigrationExecutionListener);
SplitCipher splitCipher = factoryHelper.getCipher(apiToken, config.encryptionEnabled());

ScheduledThreadPoolExecutor impressionsObserverExecutor = new ScheduledThreadPoolExecutor(1,
new ThreadPoolExecutor.CallerRunsPolicy());
Expand All @@ -200,6 +188,7 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) {
cleanUpDabase(splitTaskExecutor, splitTaskFactory);
WorkManagerWrapper workManagerWrapper = factoryHelper.buildWorkManagerWrapper(context, config, apiToken, databaseName, filters);
SplitSingleThreadTaskExecutor splitSingleThreadTaskExecutor = new SplitSingleThreadTaskExecutor();
splitSingleThreadTaskExecutor.pause();

ImpressionManager impressionManager = new StrategyImpressionManager(factoryHelper.getImpressionStrategy(splitTaskExecutor, splitTaskFactory, mStorageContainer, config));
final RetryBackoffCounterTimerFactory retryBackoffCounterTimerFactory = new RetryBackoffCounterTimerFactory();
Expand Down Expand Up @@ -254,8 +243,6 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) {
mLifecycleManager = testLifecycleManager;
}

mLifecycleManager.register(mSyncManager);

ExecutorService impressionsLoggingTaskExecutor = factoryHelper.getImpressionsLoggingTaskExecutor();
final ImpressionListener splitImpressionListener
= new SyncImpressionListener(mSyncManager, impressionsLoggingTaskExecutor);
Expand Down Expand Up @@ -335,14 +322,28 @@ public void run() {
mStorageContainer.getSplitsStorage(),
new SplitValidatorImpl(), mSplitParser);

mSyncManager.start();
Runnable initializer = new Runnable() {
@Override
public void run() {
Logger.v("Running initialization thread");
new RolloutCacheManagerImpl(config, splitTaskExecutor, mStorageContainer).execute();
new EncryptionMigrationTask(apiToken, splitDatabase, config.encryptionEnabled(), splitCipher).execute();
mEventsManagerCoordinator.notifyInternalEvent(SplitInternalEvent.ENCRYPTION_MIGRATION_DONE);
splitTaskExecutor.resume();
splitSingleThreadTaskExecutor.resume();
mSyncManager.start();
mLifecycleManager.register(mSyncManager);

Logger.i("Android SDK initialized!");
}
};
new Thread(initializer).start();

if (config.shouldRecordTelemetry()) {
int activeFactoriesCount = mFactoryMonitor.count(mApiKey);
mStorageContainer.getTelemetryStorage().recordActiveFactories(activeFactoriesCount);
mStorageContainer.getTelemetryStorage().recordRedundantFactories(activeFactoriesCount - 1);
}

Logger.i("Android SDK initialized!");
}

private static String getFlagsSpec(@Nullable TestingConfig testingConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public SplitTaskExecutionInfo execute() {
mSplitDatabase.runInTransaction(new Runnable() {
@Override
public void run() {
updateAttributes(mSplitDatabase.attributesDao());
updateSplits(mSplitDatabase.splitDao());
updateSegments(mSplitDatabase.mySegmentDao());
updateLargeSegments(mSplitDatabase.myLargeSegmentDao());
updateImpressions(mSplitDatabase.impressionDao());
updateEvents(mSplitDatabase.eventDao());
updateImpressionsCount(mSplitDatabase.impressionsCountDao());
updateUniqueKeys(mSplitDatabase.uniqueKeysDao());
updateAttributes(mSplitDatabase.attributesDao());
}
});

Expand Down Expand Up @@ -87,7 +87,6 @@ private void updateAttributes(AttributesDao attributesDao) {

private void updateUniqueKeys(UniqueKeysDao uniqueKeysDao) {
List<UniqueKeyEntity> items = uniqueKeysDao.getAll();

for (UniqueKeyEntity item : items) {
String fromUserKey = mFromCipher.decrypt(item.getUserKey());
String fromFeatureList = mFromCipher.decrypt(item.getFeatureList());
Expand Down
16 changes: 0 additions & 16 deletions src/test/java/io/split/android/client/SplitFactoryHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ class SplitFactoryHelperTest {
mocks.close()
}

@Test
fun migrateEncryption() {

helper.migrateEncryption(
"abcdedfghijklmnopqrstuvwxyz",
splitRoomDatabase,
splitTaskExecutor,
true,
taskListener,
)

verify(splitTaskExecutor).submit(
argThat { it is EncryptionMigrationTask },
argThat { it?.equals(taskListener) == true })
}

@Test
fun generateDatabaseNameWithoutPrefixAndKeyLongerThan4() {
val path = mock(File::class.java)
Expand Down

0 comments on commit f5373dc

Please sign in to comment.