Skip to content

Commit a6951e6

Browse files
committed
Cleaned up isPastOnSessionTime logic
* Added new shouldStartNewSession method to encapsulate foreground check * Added for foreground check to attemptSessionUpgrade * Added appEntryState logging to doSessionInit
1 parent bb41ce8 commit a6951e6

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -824,21 +824,19 @@ private static void handleAmazonPurchase() {
824824
// If we don't have a OneSignal player_id yet make the call to create it regardless of focus
825825
private static void doSessionInit() {
826826
// Check session time to determine whether to start a new session or not
827-
if (isPastOnSessionTime()) {
828-
if (inForeground) {
829-
logger.debug("Starting new session");
830-
831-
OneSignalStateSynchronizer.setNewSession();
832-
outcomeEventsController.cleanOutcomes();
833-
sessionManager.restartSessionIfNeeded(getAppEntryState());
834-
getInAppMessageController().resetSessionLaunchTime();
835-
setLastSessionTime(time.getCurrentTimeMillis());
836-
}
837-
} else {
838-
logger.debug("Continue on same session");
839-
827+
if (shouldStartNewSession()) {
828+
logger.debug("Starting new session with appEntryState: " + getAppEntryState());
829+
830+
OneSignalStateSynchronizer.setNewSession();
831+
outcomeEventsController.cleanOutcomes();
832+
sessionManager.restartSessionIfNeeded(getAppEntryState());
833+
getInAppMessageController().resetSessionLaunchTime();
834+
setLastSessionTime(time.getCurrentTimeMillis());
835+
} else if (isInForeground()) {
836+
logger.debug("Continue on same session with appEntryState: " + getAppEntryState());
840837
sessionManager.attemptSessionUpgrade(getAppEntryState());
841838
}
839+
842840
getInAppMessageController().initWithCachedInAppMessages();
843841

844842
// We still want register the user to OneSignal if the SDK was initialized
@@ -2914,6 +2912,16 @@ static boolean isAppActive() {
29142912
return initDone && isInForeground();
29152913
}
29162914

2915+
private static boolean shouldStartNewSession() {
2916+
if (!isInForeground())
2917+
return false;
2918+
2919+
if (!isPastOnSessionTime())
2920+
return false;
2921+
2922+
return true;
2923+
}
2924+
29172925
private static boolean isPastOnSessionTime() {
29182926
long currentTimeMillis = OneSignal.getTime().getCurrentTimeMillis();
29192927
long lastSessionTime = getLastSessionTime();

0 commit comments

Comments
 (0)