From 3da0c50053d5a70a04c34aacd85176acf94aa605 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Sun, 20 Oct 2024 00:02:47 +0530 Subject: [PATCH] Update sourceMetadata fields and SourceService binder handling --- .../radarbase/android/auth/SourceMetadata.kt | 10 +++++----- .../radarbase/android/source/SourceService.kt | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/radar-commons-android/src/main/java/org/radarbase/android/auth/SourceMetadata.kt b/radar-commons-android/src/main/java/org/radarbase/android/auth/SourceMetadata.kt index 9fab88768..de0f4db7b 100644 --- a/radar-commons-android/src/main/java/org/radarbase/android/auth/SourceMetadata.kt +++ b/radar-commons-android/src/main/java/org/radarbase/android/auth/SourceMetadata.kt @@ -15,11 +15,11 @@ import java.util.regex.Pattern @Serializable(with = SourceMetadataSerializer::class) data class SourceMetadata( - val type: SourceType? = null, - val sourceId: String? = null, - val sourceName: String? = null, - val expectedSourceName: String? = null, - val attributes: Map = mapOf() + var type: SourceType? = null, + var sourceId: String? = null, + var sourceName: String? = null, + var expectedSourceName: String? = null, + var attributes: Map = mapOf() ) { fun deduplicateType(types: MutableCollection): SourceMetadata { val currentType = type ?: return this diff --git a/radar-commons-android/src/main/java/org/radarbase/android/source/SourceService.kt b/radar-commons-android/src/main/java/org/radarbase/android/source/SourceService.kt index 1c9f15329..8ace6c837 100644 --- a/radar-commons-android/src/main/java/org/radarbase/android/source/SourceService.kt +++ b/radar-commons-android/src/main/java/org/radarbase/android/source/SourceService.kt @@ -25,6 +25,8 @@ import androidx.lifecycle.LifecycleService import androidx.lifecycle.MutableLiveData import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.apache.avro.specific.SpecificRecord import org.radarbase.android.RadarApplication.Companion.radarApp @@ -103,6 +105,8 @@ abstract class SourceService : private var _registeredSource: SourceMetadata? = null + private var authConnectionBinder: AuthService.AuthServiceBinder? = null + var registeredSource: SourceMetadata? get() = handler.compute { _registeredSource } private set(value) { @@ -176,6 +180,15 @@ abstract class SourceService : startFuture?.runNow() } } + launch { + authConnection.state + .onEach { bindState -> + authConnectionBinder = when (bindState) { + is ManagedServiceConnection.BoundService -> bindState.binder + is ManagedServiceConnection.Unbound -> null + } + }.launchIn(this) + } radarConnection.bind() } handler = SafeHandler.getInstance("SourceService-$name", THREAD_PRIORITY_BACKGROUND) @@ -236,7 +249,7 @@ abstract class SourceService : SourceConnectFailed( this@SourceService.javaClass, name, - ) + )) } private fun broadcastSourceStatus(status: SourceStatusListener.Status) { @@ -427,7 +440,7 @@ abstract class SourceService : } } - authConnection.binder?.updateSource( + authConnectionBinder?.updateSource( source, { authState, updatedSource -> key.projectId = authState.projectId