From b8b04ee2338fc6f9e9c5c81d281bf06e962d0a86 Mon Sep 17 00:00:00 2001 From: Jamie Rothfeder Date: Thu, 19 Oct 2023 11:11:42 -0400 Subject: [PATCH 1/3] Looper on a different thread for the `SessionLifecycleClient`'s callbacks --- .../com/google/firebase/sessions/SessionLifecycleClient.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt index bbdcd3e55d27..4c51a536c65f 100644 --- a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt +++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.os.Handler +import android.os.HandlerThread import android.os.IBinder import android.os.Looper import android.os.Message @@ -54,13 +55,14 @@ internal object SessionLifecycleClient { private var serviceBound: Boolean = false private val queuedMessages = LinkedBlockingDeque(MAX_QUEUED_MESSAGES) private var curSessionId: String = "" + private var handlerThread: HandlerThread = HandlerThread("FirebaseSessionsClient_HandlerThread") /** * The callback class that will be used to receive updated session events from the * [SessionLifecycleService]. */ // TODO(rothbutter) should we use the main looper or is there one available in this SDK? - internal class ClientUpdateHandler : Handler(Looper.getMainLooper()) { + internal class ClientUpdateHandler : Handler(handlerThread.looper) { override fun handleMessage(msg: Message) { when (msg.what) { SessionLifecycleService.SESSION_UPDATED -> From 54cffa0e23d747fba09e0f15ae50980dfdcd3f43 Mon Sep 17 00:00:00 2001 From: Jamie Rothfeder Date: Thu, 19 Oct 2023 11:28:07 -0400 Subject: [PATCH 2/3] Start the looper thread --- .../com/google/firebase/sessions/SessionLifecycleClient.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt index 4c51a536c65f..72755946c9f1 100644 --- a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt +++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt @@ -57,6 +57,10 @@ internal object SessionLifecycleClient { private var curSessionId: String = "" private var handlerThread: HandlerThread = HandlerThread("FirebaseSessionsClient_HandlerThread") + init { + handlerThread.start() + } + /** * The callback class that will be used to receive updated session events from the * [SessionLifecycleService]. From ab462aee211214eb31688b4a538bc316f3b87ff4 Mon Sep 17 00:00:00 2001 From: jrothfeder Date: Thu, 19 Oct 2023 11:32:30 -0400 Subject: [PATCH 3/3] Start the looper thread --- .../com/google/firebase/sessions/SessionLifecycleClient.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt index 4c51a536c65f..72755946c9f1 100644 --- a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt +++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt @@ -57,6 +57,10 @@ internal object SessionLifecycleClient { private var curSessionId: String = "" private var handlerThread: HandlerThread = HandlerThread("FirebaseSessionsClient_HandlerThread") + init { + handlerThread.start() + } + /** * The callback class that will be used to receive updated session events from the * [SessionLifecycleService].