Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sift/src/main/java/siftscience/android/Sift.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ public static void open(@NonNull Context context,
appStateCollector = new AppStateCollector(instance, c);
unboundUserId = null;
hasUnboundUserId = false;
} else {
if (config != null) {
instance.setConfig(config);
}
}
}

appStateCollector.setActivityName(activityName == null ?
context.getClass().getSimpleName() : activityName);

}

public static void open(@NonNull Context context, String activityName) {
Expand Down
12 changes: 6 additions & 6 deletions sift/src/main/java/siftscience/android/SiftImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,19 @@ public UnarchiveTask(boolean hasUnboundUserId) {
public void run() {
String archive;

// Unarchive Sift config
archive = archives.getString(ArchiveKey.CONFIG.key, null);
config = unarchiveConfig(archive);
Log.d(TAG, String.format("Unarchived Sift.Config: %s", archive));
// Unarchive Sift config if we don't have one
if (config == null) {
archive = archives.getString(ArchiveKey.CONFIG.key, null);
config = unarchiveConfig(archive);
Log.d(TAG, String.format("Unarchived Sift.Config: %s", archive));
}

// Unarchive User ID if we didn't have an unbound one from the Sift class
if (!this.hasUnboundUserId) {
userId = archives.getString(ArchiveKey.USER_ID.key, null);
Log.d(TAG, String.format("Unarchived User ID: %s", userId));
}



// Unarchive Queues
for (Map.Entry<String, ?> entry : archives.getAll().entrySet()) {
String identifier = ArchiveKey.getQueueIdentifier(entry.getKey());
Expand Down
37 changes: 37 additions & 0 deletions sift/src/test/java/siftscience/android/SiftTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ public void testSift() throws Exception {
assertTrue(preferences.fields.isEmpty());
}

@Test
public void testConfigPrecedence() {
MemorySharedPreferences preferences = new MemorySharedPreferences();

Sift.Config c1 = new Sift.Config.Builder().withAccountId("sandbox").build();
Sift.Config c2 = new Sift.Config.Builder().withAccountId("prod").build();

MemorySharedPreferences.Editor editor = preferences.edit();
editor.putString("config", Sift.GSON.toJson(c1));
editor.apply();

SiftImpl sift = new SiftImpl(
mockContext(preferences), c2, "", false, mockTaskManager());

assertEquals(c2.accountId, sift.getConfig().accountId);

sift.setConfig(c1);

assertEquals(c1.accountId, sift.getConfig().accountId);
}

@Test
public void testConfigFallback() {
MemorySharedPreferences preferences = new MemorySharedPreferences();

Sift.Config c1 = new Sift.Config.Builder().withAccountId("sandbox").build();

MemorySharedPreferences.Editor editor = preferences.edit();
editor.putString("config", Sift.GSON.toJson(c1));
editor.apply();

SiftImpl sift = new SiftImpl(
mockContext(preferences), null, "", false, mockTaskManager());

assertEquals(c1.accountId, sift.getConfig().accountId);
}

@Test
public void testUnarchiveUnknownProperty() throws IOException {
String jsonAsString =
Expand Down