Skip to content

Commit 5f48f07

Browse files
authored
Merge pull request #1409 from OneSignal/fix/crash_on_unique_outcomes
Checking shouldLogUserPrivacyConsentErrorMessage for Outcomes
2 parents bc87d7d + f72f6b1 commit 5f48f07

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,10 @@ public void run() {
32383238
return;
32393239
}
32403240

3241+
if (shouldLogUserPrivacyConsentErrorMessageForMethodName("sendOutcome()")) {
3242+
return;
3243+
}
3244+
32413245
outcomeEventsController.sendOutcomeEvent(name, callback);
32423246
}
32433247

@@ -3263,6 +3267,10 @@ public void run() {
32633267
return;
32643268
}
32653269

3270+
if (shouldLogUserPrivacyConsentErrorMessageForMethodName("sendUniqueOutcome()")) {
3271+
return;
3272+
}
3273+
32663274
outcomeEventsController.sendUniqueOutcomeEvent(name, callback);
32673275
}
32683276

OneSignalSDK/unittest/src/test/java/com/test/onesignal/OutcomeEventIntegrationTests.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,55 @@ public void testDelayOutcomes() throws Exception {
11411141
assertMeasureAtIndex(1, ONESIGNAL_OUTCOME_NAME);
11421142
}
11431143

1144+
@Test
1145+
public void testSendOutcomesFailWhenRequiresUserPrivacyConsent() throws Exception {
1146+
// Enable IAM v2
1147+
preferences = new MockOSSharedPreferences();
1148+
trackerFactory = new OSTrackerFactory(preferences, logger, time);
1149+
sessionManager = new MockSessionManager(sessionListener, trackerFactory, logger);
1150+
preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
1151+
OneSignal_setSharedPreferences(preferences);
1152+
1153+
OneSignalInit();
1154+
threadAndTaskWait();
1155+
assertRestCalls(2);
1156+
OneSignal.setRequiresUserPrivacyConsent(true);
1157+
1158+
// Make sure session is UNATTRIBUTED
1159+
assertNotificationChannelUnattributedInfluence();
1160+
1161+
// Send unique outcome event
1162+
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
1163+
threadAndTaskWait();
1164+
1165+
// Check that the task has been queued until consent is given
1166+
assertRestCalls(2);
1167+
1168+
// Send outcome event
1169+
OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
1170+
threadAndTaskWait();
1171+
1172+
// Ensure still only 2 requests have been made
1173+
assertRestCalls(2);
1174+
1175+
OneSignal.provideUserConsent(true);
1176+
threadAndTaskWait();
1177+
1178+
// Send unique outcome event
1179+
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
1180+
threadAndTaskWait();
1181+
1182+
// Send outcome event
1183+
OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
1184+
threadAndTaskWait();
1185+
1186+
// Make sure session is UNATTRIBUTED
1187+
assertNotificationChannelUnattributedInfluence();
1188+
1189+
// Check measure end point was most recent request and contains received notification
1190+
assertMeasureOnV2AtIndex(3, ONESIGNAL_OUTCOME_NAME, null, null, null, null);
1191+
}
1192+
11441193
private void foregroundAppAfterClickingNotification() throws Exception {
11451194
OneSignalInit();
11461195
threadAndTaskWait();

0 commit comments

Comments
 (0)