Skip to content

Commit 56bb1b7

Browse files
committed
Impl
1 parent 12ddf99 commit 56bb1b7

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.sessions
18+
19+
import com.google.android.datatransport.Encoding
20+
import com.google.android.datatransport.Event
21+
import com.google.android.datatransport.TransportFactory
22+
23+
internal class EventGDTLogger(private val transportFactory: TransportFactory) {
24+
25+
fun log(sessionEvent: SessionEvent) {
26+
transportFactory
27+
.getTransport(
28+
EventGDTLogger.AQS_LOG_SOURCE,
29+
SessionEvent::class.java,
30+
Encoding.of("json"),
31+
this::apply,
32+
)
33+
.send(Event.ofData(sessionEvent))
34+
}
35+
36+
private fun apply(value: SessionEvent): ByteArray {
37+
return SessionEvents.SESSION_EVENT_ENCODER.encode(value).toByteArray()
38+
}
39+
40+
companion object {
41+
// TODO AQS Log Source
42+
private const val AQS_LOG_SOURCE = "AQS_LOG_SOURCE"
43+
}
44+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ internal constructor(
3434
transportFactory: TransportFactory,
3535
) {
3636
private val sessionGenerator = SessionGenerator(collectEvents = true)
37+
private val eventGDTLogger = EventGDTLogger(transportFactory)
3738
private val sessionCoordinator =
38-
SessionCoordinator(firebaseInstallations, backgroundDispatcher, transportFactory)
39+
SessionCoordinator(firebaseInstallations, backgroundDispatcher, eventGDTLogger)
3940

4041
init {
4142
val sessionInitiator = SessionInitiator(WallClock::elapsedRealtime, this::initiateSessionStart)

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
package com.google.firebase.sessions
1818

1919
import android.util.Log
20+
import com.google.android.datatransport.Encoding
21+
import com.google.android.datatransport.Event
2022
import com.google.android.datatransport.TransportFactory
2123
import com.google.firebase.installations.FirebaseInstallationsApi
2224
import kotlinx.coroutines.CoroutineDispatcher
2325
import kotlinx.coroutines.CoroutineScope
2426
import kotlinx.coroutines.launch
2527
import kotlinx.coroutines.tasks.await
26-
import sun.jvm.hotspot.debugger.win32.coff.DebugVC50X86RegisterEnums.TAG
27-
28-
2928

3029

3130
/**
@@ -37,7 +36,7 @@ import sun.jvm.hotspot.debugger.win32.coff.DebugVC50X86RegisterEnums.TAG
3736
internal class SessionCoordinator(
3837
private val firebaseInstallations: FirebaseInstallationsApi,
3938
backgroundDispatcher: CoroutineDispatcher,
40-
private val transportFactory: TransportFactory,
39+
private val eventGDTLogger: EventGDTLogger,
4140
) {
4241
private val scope = CoroutineScope(backgroundDispatcher)
4342

@@ -55,20 +54,7 @@ internal class SessionCoordinator(
5554
Log.i(TAG, "Initiate session start: $sessionEvent")
5655

5756
try {
58-
transportFactory
59-
.getTransport(
60-
FirelogAnalytics.FCM_LOG_SOURCE,
61-
MessagingClientEventExtension::class.java,
62-
Encoding.of("proto"),
63-
MessagingClientEventExtension::toByteArray
64-
)
65-
.send(
66-
Event.ofData(
67-
MessagingClientEventExtension.newBuilder()
68-
.setMessagingClientEvent(clientEvent)
69-
.build()
70-
)
71-
)
57+
eventGDTLogger.log(sessionEvent)
7258
} catch (e: RuntimeException) {
7359
Log.w(TAG, "Failed to log Session Start event: ", e)
7460
}

0 commit comments

Comments
 (0)