Skip to content

Commit 52bb3c5

Browse files
committed
Fix testAppOnFocus_wontContainOutcomeData_withOutcomeEventFlagsDisabled
* focusTimeController was carrying over from test to test so turned it into a lazy loaded getter to fix this. * The failure of this test consistently happened when running the following tests in order: - testAndroidParamsProjectNumberOverridesLocal - testAppDoesNotCrashIfContextIsSetupViaEventButInitWasNotCalled - testAppOnFocus_wontContainOutcomeData_withOutcomeEventFlagsDisabled
1 parent 4df7b32 commit 52bb3c5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,15 @@ public static String getSdkVersionRaw() {
404404
}
405405

406406
private static OSLogger logger = new OSLogWrapper();
407-
private static FocusTimeController focusTimeController = new FocusTimeController(new OSFocusTimeProcessorFactory(), logger);
407+
private static FocusTimeController focusTimeController;
408408
private static OSSessionManager.SessionListener sessionListener = new OSSessionManager.SessionListener() {
409409
@Override
410410
public void onSessionEnding(@NonNull List<OSInfluence> lastInfluences) {
411411
if (outcomeEventsController == null)
412412
OneSignal.Log(LOG_LEVEL.WARN, "OneSignal onSessionEnding called before init!");
413413
if (outcomeEventsController != null)
414414
outcomeEventsController.cleanOutcomes();
415-
focusTimeController.onSessionEnded(lastInfluences);
415+
getFocusTimeController().onSessionEnded(lastInfluences);
416416
}
417417
};
418418

@@ -891,7 +891,7 @@ private static void handleActivityLifecycleHandler(Context context) {
891891
activityLifecycleHandler.setNextResumeIsFirstActivity(true);
892892
}
893893
OSNotificationRestoreWorkManager.beginEnqueueingWork(context, false);
894-
focusTimeController.appForegrounded();
894+
getFocusTimeController().appForegrounded();
895895
} else if (activityLifecycleHandler != null) {
896896
activityLifecycleHandler.setNextResumeIsFirstActivity(true);
897897
}
@@ -1289,7 +1289,7 @@ static void backgroundSyncLogic() {
12891289
if (trackAmazonPurchase != null)
12901290
trackAmazonPurchase.checkListener();
12911291

1292-
focusTimeController.appBackgrounded();
1292+
getFocusTimeController().appBackgrounded();
12931293

12941294
scheduleSyncService();
12951295
}
@@ -1337,7 +1337,7 @@ private static void onAppFocusLogic() {
13371337
if (shouldLogUserPrivacyConsentErrorMessageForMethodName("onAppFocus"))
13381338
return;
13391339

1340-
focusTimeController.appForegrounded();
1340+
getFocusTimeController().appForegrounded();
13411341

13421342
doSessionInit();
13431343

@@ -3172,6 +3172,10 @@ static OSTaskController getTaskController() {
31723172
}
31733173

31743174
static FocusTimeController getFocusTimeController() {
3175+
if (focusTimeController == null) {
3176+
focusTimeController = new FocusTimeController(new OSFocusTimeProcessorFactory(), logger);
3177+
}
3178+
31753179
return focusTimeController;
31763180
}
31773181
/*

0 commit comments

Comments
 (0)