Skip to content

Commit 21ddec3

Browse files
authored
send session event based on data collection and setting config (#6852)
send session event based on data collection and setting config
1 parent 2b1e056 commit 21ddec3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionFirelogPublisher.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import kotlinx.coroutines.launch
3434
internal fun interface SessionFirelogPublisher {
3535

3636
/** Asynchronously logs the session represented by the given [SessionDetails] to Firelog. */
37-
fun logSession(sessionDetails: SessionDetails)
37+
fun mayLogSession(sessionDetails: SessionDetails)
3838

3939
companion object {
4040
val instance: SessionFirelogPublisher
@@ -64,7 +64,7 @@ constructor(
6464
* This will pull all the necessary information about the device in order to create a full
6565
* [SessionEvent], and then upload that through the Firelog interface.
6666
*/
67-
override fun logSession(sessionDetails: SessionDetails) {
67+
override fun mayLogSession(sessionDetails: SessionDetails) {
6868
CoroutineScope(backgroundDispatcher).launch {
6969
if (shouldLogSession()) {
7070
val installationId = InstallationId.create(firebaseInstallations)
@@ -94,13 +94,16 @@ constructor(
9494

9595
/** Determines if the SDK should log a session to Firelog. */
9696
private suspend fun shouldLogSession(): Boolean {
97-
Log.d(TAG, "Data Collection is enabled for at least one Subscriber")
98-
97+
val subscribers = FirebaseSessionsDependencies.getRegisteredSubscribers()
98+
if (subscribers.values.none { it.isDataCollectionEnabled }) {
99+
Log.d(TAG, "Sessions SDK disabled through data collection. Events will not be sent.")
100+
return false
101+
}
99102
// This will cause remote settings to be fetched if the cache is expired.
100103
sessionSettings.updateSettings()
101104

102105
if (!sessionSettings.sessionsEnabled) {
103-
Log.d(TAG, "Sessions SDK disabled. Events will not be sent.")
106+
Log.d(TAG, "Sessions SDK disabled through settings API. Events will not be sent.")
104107
return false
105108
}
106109

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SharedSessionRepository.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ constructor(
103103
}
104104
}
105105
}
106-
107-
// TODO(mrober): If data collection is enabled for at least one subscriber...
108-
// https://github.com/firebase/firebase-android-sdk/blob/a53ab64150608c2eb3eafb17d81dfe217687d955/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/FirebaseSessions.kt#L110
109-
sessionFirelogPublisher.logSession(sessionDetails = newSessionDetails)
106+
sessionFirelogPublisher.mayLogSession(sessionDetails = newSessionDetails)
110107
}
111108
}
112109

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/SessionFirelogPublisherTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SessionFirelogPublisherTest {
7575
)
7676

7777
// Construct an event with no fid set.
78-
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
78+
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)
7979

8080
runCurrent()
8181

@@ -105,7 +105,7 @@ class SessionFirelogPublisherTest {
105105
)
106106

107107
// Construct an event with no fid set.
108-
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
108+
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)
109109

110110
runCurrent()
111111

@@ -134,7 +134,7 @@ class SessionFirelogPublisherTest {
134134
)
135135

136136
// Construct an event with no fid set.
137-
publisher.logSession(TestSessionEventData.TEST_SESSION_DETAILS)
137+
publisher.mayLogSession(TestSessionEventData.TEST_SESSION_DETAILS)
138138

139139
runCurrent()
140140

0 commit comments

Comments
 (0)