Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
liviu-timar committed Jan 27, 2025
1 parent 4b135a3 commit 5614479
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ internal open class CallService : Service() {
unregisterToggleCameraBroadcastReceiver()

// Call sounds
callSoundPlayer?.cleanAudioResources()
callSoundPlayer?.cleanUpAudioResources()

// Stop any jobs
serviceScope.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CallSoundPlayer(private val context: Context) {
}
}

fun cleanAudioResources() {
fun cleanUpAudioResources() {
synchronized(this) {
logger.d { "[cleanAudioResources] Cleaning audio resources" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
},
)
}
}
},
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
),
)
}
}
}
},
Expand All @@ -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,
),
)
}
}
}
},
Expand Down Expand Up @@ -229,12 +241,12 @@ internal object TelecomCompat {
CallService.buildStopIntent(
context = context.applicationContext,
callServiceConfiguration = callConfig,
)
),
)
}
}
}
}
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ internal class TelecomHandler private constructor(

calls.forEach { unregisterCall(it.value.streamCall) }
telecomHandlerScope.cancel()
callSoundPlayer.cleanAudioResources()
callSoundPlayer.cleanUpAudioResources()
instance = null
}

Expand Down

0 comments on commit 5614479

Please sign in to comment.