Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
* Still send likely erroneous session time. This way the server can be aware of any issues.
* Simplify state when firing subscribers of the Application Service
  • Loading branch information
nan-li committed Jun 12, 2024
1 parent 5aa61f7 commit 32fec1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On
private val activityLifecycleNotifier = EventProducer<IActivityLifecycleHandler>()
private val applicationLifecycleNotifier = EventProducer<IApplicationLifecycleHandler>()
private val systemConditionNotifier = EventProducer<ISystemConditionHandler>()
private var shouldFireOnFocusOnSubscribing = false

override val isInForeground: Boolean
get() = entryState.isAppOpen || entryState.isNotificationClick
Expand Down Expand Up @@ -73,7 +72,6 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On

/**
* Call to "start" this service, expected to be called during initialization of the SDK.
* Detects if this service should fire subscribers' onFocus() callbacks immediately on subscribing.
*
* @param context The context the SDK has been initialized under.
*/
Expand Down Expand Up @@ -112,8 +110,6 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On
activityReferences = 1
nextResumeIsFirstActivity = false
}
// Once listeners subscribe, fire their callbacks
shouldFireOnFocusOnSubscribing = true
} else {
nextResumeIsFirstActivity = true
entryState = AppEntryAction.APP_CLOSE
Expand All @@ -124,7 +120,9 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On

override fun addApplicationLifecycleHandler(handler: IApplicationLifecycleHandler) {
applicationLifecycleNotifier.subscribe(handler)
if (shouldFireOnFocusOnSubscribing) {
if (current != null) {
// When a listener subscribes, fire its callback
// The listener is too late to receive the earlier onFocus call
handler.onFocus(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ internal class SessionListener(
override fun onSessionEnded(duration: Long) {
val durationInSeconds = duration / 1000

// Time is invalid if below 1 second or over a day
// Time is erroneous if below 1 second or over a day
if (durationInSeconds < 1L || durationInSeconds > SECONDS_IN_A_DAY) {
return
Logging.error("SessionListener.onSessionEnded sending duration of $durationInSeconds seconds")

Check failure on line 53 in OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/session/impl/SessionListener.kt

View workflow job for this annotation

GitHub Actions / build

Unresolved reference: Logging
}

_operationRepo.enqueue(
Expand Down

0 comments on commit 32fec1b

Please sign in to comment.