Skip to content

Commit

Permalink
Merge pull request #2212 from OneSignal/NPE-getScheduleBackgroundRunIn
Browse files Browse the repository at this point in the history
[Fix] NPE by getScheduleBackgroundRunIn
  • Loading branch information
jinliu9508 authored Nov 7, 2024
2 parents 4f0191f + 2c16b3c commit 04cfe9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.onesignal.session
import com.onesignal.common.modules.IModule
import com.onesignal.common.services.ServiceBuilder
import com.onesignal.core.internal.background.IBackgroundService
import com.onesignal.core.internal.startup.IBootstrapService
import com.onesignal.core.internal.startup.IStartableService
import com.onesignal.session.internal.SessionManager
import com.onesignal.session.internal.influence.IInfluenceManager
Expand Down Expand Up @@ -39,6 +40,7 @@ internal class SessionModule : IModule {
.provides<ISessionService>()
.provides<IStartableService>()
.provides<IBackgroundService>()
.provides<IBootstrapService>()
builder.register<SessionListener>().provides<IStartableService>()
builder.register<SessionManager>().provides<ISessionManager>()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.onesignal.core.internal.application.IApplicationService
import com.onesignal.core.internal.background.IBackgroundService
import com.onesignal.core.internal.config.ConfigModel
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.startup.IBootstrapService
import com.onesignal.core.internal.startup.IStartableService
import com.onesignal.core.internal.time.ITime
import com.onesignal.debug.LogLevel
Expand All @@ -32,7 +33,7 @@ internal class SessionService(
private val _configModelStore: ConfigModelStore,
private val _sessionModelStore: SessionModelStore,
private val _time: ITime,
) : ISessionService, IStartableService, IBackgroundService, IApplicationLifecycleHandler {
) : ISessionService, IBootstrapService, IStartableService, IBackgroundService, IApplicationLifecycleHandler {
override val startTime: Long
get() = session!!.startTime

Expand All @@ -50,9 +51,12 @@ internal class SessionService(
// True if app has been foregrounded at least once since the app started
private var hasFocused = false

override fun start() {
override fun bootstrap() {
session = _sessionModelStore.model
config = _configModelStore.model
}

override fun start() {
_applicationService.addApplicationLifecycleHandler(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ private class Mocks {
return mockSessionModelStore
}

val sessionService = SessionService(MockHelper.applicationService(), MockHelper.configModelStore(), mockSessionModelStore, MockHelper.time(currentTime))
val sessionService =
SessionService(MockHelper.applicationService(), MockHelper.configModelStore(), mockSessionModelStore, MockHelper.time(currentTime))

val spyCallback = spyk<ISessionLifecycleHandler>()
}
Expand All @@ -29,6 +30,7 @@ class SessionServiceTests : FunSpec({
val mocks = Mocks()
val sessionService = mocks.sessionService

sessionService.bootstrap()
sessionService.start()
val sessionModelStore = mocks.sessionModelStore { it.isValid = false }
sessionService.subscribe(mocks.spyCallback)
Expand All @@ -50,6 +52,7 @@ class SessionServiceTests : FunSpec({
val sessionModelStore = mocks.sessionModelStore()

// When
sessionService.bootstrap()
sessionService.start()
sessionService.onFocus(true)
sessionService.subscribe(mocks.spyCallback)
Expand All @@ -73,6 +76,7 @@ class SessionServiceTests : FunSpec({
val mocks = Mocks()
val sessionService = mocks.sessionService

sessionService.bootstrap()
sessionService.start()
val sessionModelStore =
mocks.sessionModelStore {
Expand Down Expand Up @@ -101,6 +105,7 @@ class SessionServiceTests : FunSpec({
val mocks = Mocks()
val sessionService = mocks.sessionService

sessionService.bootstrap()
sessionService.start()
val sessionModelStore =
mocks.sessionModelStore {
Expand All @@ -125,6 +130,7 @@ class SessionServiceTests : FunSpec({
val mocks = Mocks()
val sessionService = mocks.sessionService

sessionService.bootstrap()
sessionService.start()
val sessionModelStore =
mocks.sessionModelStore {
Expand All @@ -147,6 +153,7 @@ class SessionServiceTests : FunSpec({
mocks.sessionModelStore { it.isValid = false }
val sessionService = mocks.sessionService
sessionService.subscribe(mocks.spyCallback)
sessionService.bootstrap()
sessionService.start()

// When
Expand Down

0 comments on commit 04cfe9b

Please sign in to comment.