diff --git a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt index d23b9759b..63b48ded5 100644 --- a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt +++ b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt @@ -96,11 +96,10 @@ class AudioRouteUtils { types: List, skipTelecom: Boolean = false ) { - val currentCall = call ?: coreContext.core.currentCall ?: coreContext.core.calls[0] - if ((call != null || currentCall != null) && !skipTelecom && TelecomHelper.exists()) { - val callToUse = call ?: currentCall + val currentCall = call ?: coreContext.core.currentCall ?: coreContext.core.calls.firstOrNull() + if (currentCall != null && !skipTelecom && TelecomHelper.exists()) { Log.i("[Audio Route Helper] Call provided & Telecom Helper exists, trying to dispatch audio route change through Telecom API") - val connection = TelecomHelper.get().findConnectionForCallId(callToUse.callLog.callId) + val connection = TelecomHelper.get().findConnectionForCallId(currentCall.callLog.callId) if (connection != null) { val route = when (types.first()) { AudioDevice.Type.Earpiece -> CallAudioState.ROUTE_EARPIECE @@ -114,13 +113,13 @@ class AudioRouteUtils { // but this time with skipTelecom = true if (!Compatibility.changeAudioRouteForTelecomManager(connection, route)) { Log.w("[Audio Route Helper] Connection is already using this route internally, make the change!") - applyAudioRouteChange(callToUse, types) - changeCaptureDeviceToMatchAudioRoute(callToUse, types) + applyAudioRouteChange(currentCall, types) + changeCaptureDeviceToMatchAudioRoute(currentCall, types) } } else { Log.w("[Audio Route Helper] Telecom Helper found but no matching connection!") - applyAudioRouteChange(callToUse, types) - changeCaptureDeviceToMatchAudioRoute(callToUse, types) + applyAudioRouteChange(currentCall, types) + changeCaptureDeviceToMatchAudioRoute(currentCall, types) } } else { applyAudioRouteChange(call, types)