Skip to content

Commit

Permalink
Track scoped storage migration attempts and results
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel authored and grzesiek2010 committed Mar 4, 2020
1 parent 4561d42 commit d96714f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ private AnalyticsEvents() {
* be a hash of the form definition.
*/
public static final String LAUNCH_FORM_WITH_BG_LOCATION = "LaunchFormWithBGLocation";

/**
* Track scoped storage migration attempts. The action should be the result of the attempt.
*/
public static final String SCOPED_STORAGE_MIGRATION = "ScopedStorageMigration";
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ public StorageMigrationRepository providesStorageMigrationRepository() {
}

@Provides
StorageMigrator providesStorageMigrator(StoragePathProvider storagePathProvider, StorageStateProvider storageStateProvider, StorageMigrationRepository storageMigrationRepository, ReferenceManager referenceManager, BackgroundWorkManager backgroundWorkManager) {
StorageMigrator providesStorageMigrator(StoragePathProvider storagePathProvider, StorageStateProvider storageStateProvider, StorageMigrationRepository storageMigrationRepository, ReferenceManager referenceManager, BackgroundWorkManager backgroundWorkManager, Analytics analytics) {
StorageEraser storageEraser = new StorageEraser(storagePathProvider);

return new StorageMigrator(storagePathProvider, storageStateProvider, storageEraser, storageMigrationRepository, GeneralSharedPreferences.getInstance(), referenceManager, backgroundWorkManager);
return new StorageMigrator(storagePathProvider, storageStateProvider, storageEraser, storageMigrationRepository, GeneralSharedPreferences.getInstance(), referenceManager, backgroundWorkManager, analytics);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.apache.commons.io.FileUtils;
import org.javarosa.core.reference.ReferenceManager;
import org.odk.collect.android.analytics.Analytics;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.dao.InstancesDao;
import org.odk.collect.android.preferences.GeneralSharedPreferences;
Expand All @@ -22,6 +23,7 @@
import timber.log.Timber;

import static android.provider.BaseColumns._ID;
import static org.odk.collect.android.analytics.AnalyticsEvents.SCOPED_STORAGE_MIGRATION;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_REFERENCE_LAYER;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.FORM_FILE_PATH;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.FORM_MEDIA_PATH;
Expand All @@ -40,22 +42,30 @@ public class StorageMigrator {
private final StorageMigrationRepository storageMigrationRepository;
private final BackgroundWorkManager backgroundWorkManager;

private final Analytics analytics;

public StorageMigrator(StoragePathProvider storagePathProvider, StorageStateProvider storageStateProvider,
StorageEraser storageEraser, StorageMigrationRepository storageMigrationRepository,
GeneralSharedPreferences generalSharedPreferences, ReferenceManager referenceManager, BackgroundWorkManager workManager) {
GeneralSharedPreferences generalSharedPreferences, ReferenceManager referenceManager,
BackgroundWorkManager workManager, Analytics analytics) {

this.storagePathProvider = storagePathProvider;
this.storageStateProvider = storageStateProvider;
this.storageEraser = storageEraser;
this.storageMigrationRepository = storageMigrationRepository;
this.generalSharedPreferences = generalSharedPreferences;
this.referenceManager = referenceManager;
this.backgroundWorkManager = workManager;
this.analytics = analytics;
}

void performStorageMigration() {
storageMigrationRepository.markMigrationStart();
storageMigrationRepository.setResult(migrate());
StorageMigrationResult result = migrate();
storageMigrationRepository.setResult(result);
storageMigrationRepository.markMigrationEnd();

analytics.logEvent(SCOPED_STORAGE_MIGRATION, result.toString());
}

public StorageMigrationResult migrate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.javarosa.core.reference.ReferenceManager;
import org.junit.Before;
import org.junit.Test;
import org.odk.collect.android.analytics.Analytics;
import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.storage.StoragePathProvider;
import org.odk.collect.android.storage.StorageStateProvider;
Expand Down Expand Up @@ -32,6 +33,7 @@ public class StorageMigratorTest {
private final GeneralSharedPreferences generalSharedPreferences = mock(GeneralSharedPreferences.class);
private final ReferenceManager referenceManager = mock(ReferenceManager.class);
private final BackgroundWorkManager backgroundWorkManager = mock(BackgroundWorkManager.class);
private final Analytics analytics = mock(Analytics.class);

@Before
public void setup() {
Expand All @@ -42,7 +44,7 @@ public void setup() {
doNothing().when(storageEraser).deleteOdkDirFromUnscopedStorage();
doReturn("/sdcard/odk/layers/countries/countries-raster.mbtiles").when(generalSharedPreferences).get(KEY_REFERENCE_LAYER);

storageMigrator = spy(new StorageMigrator(storagePathProvider, storageStateProvider, storageEraser, storageMigrationRepository, generalSharedPreferences, referenceManager, backgroundWorkManager));
storageMigrator = spy(new StorageMigrator(storagePathProvider, storageStateProvider, storageEraser, storageMigrationRepository, generalSharedPreferences, referenceManager, backgroundWorkManager, analytics));

doNothing().when(storageMigrator).reopenDatabases();
}
Expand Down

0 comments on commit d96714f

Please sign in to comment.