From 561447920cdea9f7f06b23e26c239aaeb966c6b9 Mon Sep 17 00:00:00 2001 From: Liviu Timar <65943217+liviu-timar@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:41:39 +0200 Subject: [PATCH] Clean up --- .../api/stream-video-android-core.api | 2 +- .../video/android/core/StreamVideoBuilder.kt | 1 - .../internal/service/CallService.kt | 2 +- .../android/core/sounds/CallSoundPlayer.kt | 2 +- .../android/core/telecom/TelecomCompat.kt | 94 +++++++++++-------- .../android/core/telecom/TelecomHandler.kt | 2 +- 6 files changed, 57 insertions(+), 46 deletions(-) diff --git a/stream-video-android-core/api/stream-video-android-core.api b/stream-video-android-core/api/stream-video-android-core.api index 56f2ffbd68..25caf4921e 100644 --- a/stream-video-android-core/api/stream-video-android-core.api +++ b/stream-video-android-core/api/stream-video-android-core.api @@ -5337,7 +5337,7 @@ public final class io/getstream/video/android/core/socket/sfu/state/SfuSocketSta public final class io/getstream/video/android/core/sounds/CallSoundPlayer { public fun (Landroid/content/Context;)V - public final fun cleanAudioResources ()V + public final fun cleanUpAudioResources ()V public final fun playCallSound (Landroid/net/Uri;)V public final fun stopCallSound ()V } diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt index 9579f1bd2b..3bdac9e901 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt @@ -41,7 +41,6 @@ import io.getstream.video.android.core.socket.common.token.TokenProvider import io.getstream.video.android.core.sounds.Sounds import io.getstream.video.android.core.sounds.defaultResourcesRingingConfig import io.getstream.video.android.core.sounds.toSounds -import io.getstream.video.android.core.telecom.TelecomHandler import io.getstream.video.android.model.ApiKey import io.getstream.video.android.model.User import io.getstream.video.android.model.UserToken diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt index fb6771ac65..960b6087ec 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt @@ -691,7 +691,7 @@ internal open class CallService : Service() { unregisterToggleCameraBroadcastReceiver() // Call sounds - callSoundPlayer?.cleanAudioResources() + callSoundPlayer?.cleanUpAudioResources() // Stop any jobs serviceScope.cancel() diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/CallSoundPlayer.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/CallSoundPlayer.kt index 0549e22b90..7926766a87 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/CallSoundPlayer.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/CallSoundPlayer.kt @@ -151,7 +151,7 @@ class CallSoundPlayer(private val context: Context) { } } - fun cleanAudioResources() { + fun cleanUpAudioResources() { synchronized(this) { logger.d { "[cleanAudioResources] Cleaning audio resources" } diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomCompat.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomCompat.kt index 9874038618..733a0997dc 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomCompat.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomCompat.kt @@ -30,6 +30,7 @@ import io.getstream.video.android.core.audio.StreamAudioDevice import io.getstream.video.android.core.notifications.internal.NoOpNotificationHandler.getRingingCallNotification import io.getstream.video.android.core.notifications.internal.service.CallService import io.getstream.video.android.core.notifications.internal.service.CallServiceConfig +import io.getstream.video.android.core.utils.safeCall import io.getstream.video.android.model.StreamCallId import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -52,20 +53,22 @@ internal object TelecomCompat { }, onNotSupported = { if (isIncomingCall) { - CallService.showIncomingCall( - context.applicationContext, - StreamCallId.fromCallCid(streamCall.cid), - callInfo, - callServiceConfiguration = callConfig, - notification = callId?.let { - getRingingCallNotification( - RingingState.Incoming(), - callId, - callInfo, - shouldHaveContentIntent = true, - ) - }, - ) + safeCall { + CallService.showIncomingCall( + context.applicationContext, + StreamCallId.fromCallCid(streamCall.cid), + callInfo, + callServiceConfiguration = callConfig, + notification = callId?.let { + getRingingCallNotification( + RingingState.Incoming(), + callId, + callInfo, + shouldHaveContentIntent = true, + ) + }, + ) + } } }, ) @@ -121,7 +124,12 @@ internal object TelecomCompat { if (callConfig.runCallServiceInForeground) onEnabled() } - fun changeCallState(context: Context, newState: TelecomCallState, call: StreamCall? = null, callId: StreamCallId? = null) { + fun changeCallState( + context: Context, + newState: TelecomCallState, + call: StreamCall? = null, + callId: StreamCallId? = null, + ) { withCall(call, callId) { streamCall, callConfig -> checkTelecomSupport( context = context, @@ -131,19 +139,21 @@ internal object TelecomCompat { onNotSupported = { if (newState == TelecomCallState.OUTGOING || newState == TelecomCallState.ONGOING) { ifForegroundServiceEnabled(callConfig) { - ContextCompat.startForegroundService( - context, - CallService.buildStartIntent( + safeCall { + ContextCompat.startForegroundService( context, - StreamCallId.fromCallCid(streamCall.cid), - if (newState == TelecomCallState.OUTGOING) { - CallService.TRIGGER_OUTGOING_CALL - } else { - CallService.TRIGGER_ONGOING_CALL - }, - callServiceConfiguration = callConfig, - ), - ) + CallService.buildStartIntent( + context, + StreamCallId.fromCallCid(streamCall.cid), + if (newState == TelecomCallState.OUTGOING) { + CallService.TRIGGER_OUTGOING_CALL + } else { + CallService.TRIGGER_ONGOING_CALL + }, + callServiceConfiguration = callConfig, + ), + ) + } } } }, @@ -164,19 +174,21 @@ internal object TelecomCompat { }, onNotSupported = { ifForegroundServiceEnabled(callConfig) { - if (isIncomingCall) { - CallService.removeIncomingCall( - context, - StreamCallId.fromCallCid(call.cid), - callServiceConfiguration = callConfig, - ) - } else { - context.stopService( - CallService.buildStopIntent( - context = context.applicationContext, + safeCall { + if (isIncomingCall) { + CallService.removeIncomingCall( + context, + StreamCallId.fromCallCid(call.cid), callServiceConfiguration = callConfig, - ), - ) + ) + } else { + context.stopService( + CallService.buildStopIntent( + context = context.applicationContext, + callServiceConfiguration = callConfig, + ), + ) + } } } }, @@ -229,12 +241,12 @@ internal object TelecomCompat { CallService.buildStopIntent( context = context.applicationContext, callServiceConfiguration = callConfig, - ) + ), ) } } } - } + }, ) } } diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomHandler.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomHandler.kt index a8a46aa5b4..b373a38113 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomHandler.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/telecom/TelecomHandler.kt @@ -291,7 +291,7 @@ internal class TelecomHandler private constructor( calls.forEach { unregisterCall(it.value.streamCall) } telecomHandlerScope.cancel() - callSoundPlayer.cleanAudioResources() + callSoundPlayer.cleanUpAudioResources() instance = null }