diff --git a/app/src/main/java/org/linphone/compatibility/Api26Compatibility.kt b/app/src/main/java/org/linphone/compatibility/Api26Compatibility.kt index 59d1c0e04..f49e1bdd3 100644 --- a/app/src/main/java/org/linphone/compatibility/Api26Compatibility.kt +++ b/app/src/main/java/org/linphone/compatibility/Api26Compatibility.kt @@ -257,8 +257,14 @@ class Api26Compatibility { vibrator.vibrate(effect, audioAttrs) } - fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int) { + fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int): Boolean { + Log.i("[Telecom Helper] Changing audio route [$route] on connection ${connection.callId}") + if (connection.callAudioState.route == route) { + Log.w("[Telecom Helper] Connection is already using this route") + return false + } connection.setAudioRoute(route) + return true } fun requestTelecomManagerPermission(activity: Activity, code: Int) { diff --git a/app/src/main/java/org/linphone/compatibility/Compatibility.kt b/app/src/main/java/org/linphone/compatibility/Compatibility.kt index adf273435..e01d09c95 100644 --- a/app/src/main/java/org/linphone/compatibility/Compatibility.kt +++ b/app/src/main/java/org/linphone/compatibility/Compatibility.kt @@ -232,10 +232,11 @@ class Compatibility { } } - fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int) { + fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int): Boolean { if (Version.sdkAboveOrEqual(Version.API26_O_80)) { - Api26Compatibility.changeAudioRouteForTelecomManager(connection, route) + return Api26Compatibility.changeAudioRouteForTelecomManager(connection, route) } + return false } /* Contacts */ diff --git a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt index d3f06fda9..d23b9759b 100644 --- a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt +++ b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt @@ -112,7 +112,11 @@ class AudioRouteUtils { Log.i("[Audio Route Helper] Telecom Helper & matching connection found, dispatching audio route change through it") // We will be called here again by NativeCallWrapper.onCallAudioStateChanged() // but this time with skipTelecom = true - Compatibility.changeAudioRouteForTelecomManager(connection, route) + 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) + } } else { Log.w("[Audio Route Helper] Telecom Helper found but no matching connection!") applyAudioRouteChange(callToUse, types)