Fixed crash in audio route utils

This commit is contained in:
Sylvain Berfini 2022-02-14 09:27:16 +01:00
parent 2d220dd01a
commit 9b934f8f15

View file

@ -96,11 +96,10 @@ class AudioRouteUtils {
types: List<AudioDevice.Type>,
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)