File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
main/kotlin/com/google/firebase/sessions
test/kotlin/com/google/firebase/sessions Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,14 @@ internal constructor(
78
78
" Registering Sessions SDK subscriber with name: ${subscriber.sessionSubscriberName} , " +
79
79
" data collection enabled: ${subscriber.isDataCollectionEnabled} "
80
80
)
81
+
82
+ // Immediately call the callback if Sessions generated a session before the
83
+ // subscriber subscribed, otherwise subscribers might miss the first session.
84
+ if (sessionGenerator.hasGenerateSession) {
85
+ subscriber.onSessionChanged(
86
+ SessionSubscriber .SessionDetails (sessionGenerator.currentSession.sessionId)
87
+ )
88
+ }
81
89
}
82
90
83
91
private fun initiateSessionStart () {
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ internal class SessionGenerator(
46
46
lateinit var currentSession: SessionDetails
47
47
private set
48
48
49
+ /* * Returns if a session has been generated. */
50
+ val hasGenerateSession: Boolean
51
+ get() = ::currentSession.isInitialized
52
+
49
53
/* * Generates a new session. The first session's sessionId will match firstSessionId. */
50
54
fun generateNewSession (): SessionDetails {
51
55
sessionIndex++
Original file line number Diff line number Diff line change @@ -43,6 +43,22 @@ class SessionGeneratorTest {
43
43
sessionGenerator.currentSession
44
44
}
45
45
46
+ @Test
47
+ fun hasGenerateSession_beforeGenerate_returnsFalse () {
48
+ val sessionGenerator = SessionGenerator (collectEvents = false )
49
+
50
+ assertThat(sessionGenerator.hasGenerateSession).isFalse()
51
+ }
52
+
53
+ @Test
54
+ fun hasGenerateSession_afterGenerate_returnsTrue () {
55
+ val sessionGenerator = SessionGenerator (collectEvents = false )
56
+
57
+ sessionGenerator.generateNewSession()
58
+
59
+ assertThat(sessionGenerator.hasGenerateSession).isTrue()
60
+ }
61
+
46
62
@Test
47
63
fun generateNewSession_generatesValidSessionIds () {
48
64
val sessionGenerator = SessionGenerator (collectEvents = true ) // defaults to UUID::randomUUID
You can’t perform that action at this time.
0 commit comments