@@ -422,9 +422,7 @@ private static OSSessionManager.SessionListener getNewSessionListener() {
422
422
return new OSSessionManager .SessionListener () {
423
423
@ Override
424
424
public void onSessionEnding (@ NonNull OSSessionManager .SessionResult lastSessionResult ) {
425
- if (outcomeEventsController != null )
426
- outcomeEventsController .cleanOutcomes ();
427
-
425
+ outcomeEventsController .cleanOutcomes ();
428
426
FocusTimeController .getInstance ().onSessionEnded (lastSessionResult );
429
427
}
430
428
};
@@ -597,6 +595,7 @@ public static void setAppContext(@NonNull Context context) {
597
595
598
596
if (wasAppContextNull ) {
599
597
sessionManager = new OSSessionManager (getNewSessionListener ());
598
+ outcomeEventsController = new OutcomeEventsController (sessionManager , OneSignalDbHelper .getInstance (appContext ), outcomeSettings );
600
599
// Prefs require a context to save
601
600
// If the previous state of appContext was null, kick off write in-case it was waiting
602
601
OneSignalPrefs .startDelayedWrite ();
@@ -667,7 +666,6 @@ public static void init(Context context, String googleProjectNumber, String oneS
667
666
}
668
667
669
668
mInitBuilder = createInitBuilder (notificationOpenedHandler , notificationReceivedHandler );
670
- outcomeEventsController = new OutcomeEventsController (sessionManager , OneSignalDbHelper .getInstance (appContext ), outcomeSettings );
671
669
672
670
if (!isGoogleProjectNumberRemote ())
673
671
mGoogleProjectNumber = googleProjectNumber ;
@@ -2076,7 +2074,7 @@ public static void handleNotificationOpen(Context inContext, JSONArray data, boo
2076
2074
runNotificationOpenedCallback (data , true , fromAlert );
2077
2075
2078
2076
// Check if the notification click should lead to a DIRECT session
2079
- if (sessionManager != null && shouldInitDirectSessionFromNotificationOpen (inContext , fromAlert , urlOpened , defaultOpenActionDisabled )) {
2077
+ if (shouldInitDirectSessionFromNotificationOpen (inContext , fromAlert , urlOpened , defaultOpenActionDisabled )) {
2080
2078
// We want to set the app entry state to NOTIFICATION_CLICK when coming from background
2081
2079
appEntryState = AppEntryAction .NOTIFICATION_CLICK ;
2082
2080
sessionManager .onDirectSessionFromNotificationOpen (notificationId );
@@ -3089,7 +3087,7 @@ public static void sendOutcome(@NonNull String name) {
3089
3087
}
3090
3088
3091
3089
public static void sendOutcome (@ NonNull String name , OutcomeCallback callback ) {
3092
- if (!validateOutcomeEntry (name ))
3090
+ if (!isValidOutcomeEntry (name ))
3093
3091
return ;
3094
3092
3095
3093
outcomeEventsController .sendOutcomeEvent (name , callback );
@@ -3100,7 +3098,7 @@ public static void sendUniqueOutcome(@NonNull String name) {
3100
3098
}
3101
3099
3102
3100
public static void sendUniqueOutcome (@ NonNull String name , OutcomeCallback callback ) {
3103
- if (!validateOutcomeEntry (name ))
3101
+ if (!isValidOutcomeEntry (name ))
3104
3102
return ;
3105
3103
3106
3104
outcomeEventsController .sendUniqueOutcomeEvent (name , callback );
@@ -3111,17 +3109,13 @@ public static void sendOutcomeWithValue(@NonNull String name, float value) {
3111
3109
}
3112
3110
3113
3111
public static void sendOutcomeWithValue (@ NonNull String name , float value , OutcomeCallback callback ) {
3114
- if (!validateOutcomeEntry (name ))
3112
+ if (!isValidOutcomeEntry (name ))
3115
3113
return ;
3116
3114
3117
3115
outcomeEventsController .sendOutcomeEventWithValue (name , value , callback );
3118
3116
}
3119
3117
3120
- private static boolean validateOutcomeEntry (String name ) {
3121
- if (outcomeEventsController == null ) {
3122
- OneSignal .Log (LOG_LEVEL .ERROR , "Must call OneSignal.init first" );
3123
- return false ;
3124
- }
3118
+ private static boolean isValidOutcomeEntry (String name ) {
3125
3119
if (name == null || name .isEmpty ()) {
3126
3120
OneSignal .Log (LOG_LEVEL .ERROR , "Outcome name must not be empty" );
3127
3121
return false ;
0 commit comments