From dae41ca1ff2f4855bd8a95b4a54fa46b9d2b2028 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 6 Apr 2026 21:40:57 +0300 Subject: [PATCH] Ensure correct communication mode when SDK is < 31 --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index b30e6707..06078fea 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -34,6 +34,7 @@ import android.net.NetworkCapabilities import android.net.NetworkRequest import android.net.Uri import android.net.wifi.WifiManager +import android.os.Build import android.os.Build.VERSION import android.os.CountDownTimer import android.os.Handler @@ -786,10 +787,12 @@ class BaresipService: Service() { } "call ringing" -> { ConnectionService.connections[callp]?.setRinging() + ensureCommunicationMode() playRingBack() return } "call progress" -> { + ensureCommunicationMode() if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0) stopMediaPlayer() else { @@ -866,6 +869,7 @@ class BaresipService: Service() { } "call answered" -> { stopMediaPlayer() + ensureCommunicationMode() if (call!!.status.value == "incoming") call.status.value = "answered" else @@ -876,6 +880,7 @@ class BaresipService: Service() { } "call established" -> { ConnectionService.connections[callp]?.setActive() + ensureCommunicationMode() nm.cancel(CALL_NOTIFICATION_ID) Log.d(TAG, "AoR $aor call $callp established") call!!.status.value = "connected" @@ -1042,6 +1047,7 @@ class BaresipService: Service() { if (tone == "busy") playBusy() else if (!Call.inCall()) { + am.mode = AudioManager.MODE_NORMAL resetCallVolume() proximitySensing(false) } @@ -1864,6 +1870,16 @@ class BaresipService: Service() { } } + private fun ensureCommunicationMode() { + // On Android 11+, Telecom usually handles this. + // On Android 10 and below, we must be more aggressive. + if (VERSION.SDK_INT < 31 || am.mode != MODE_IN_COMMUNICATION) { + if (Call.inCall()) { + Log.d(TAG, "Manual Mode Guard: Setting MODE_IN_COMMUNICATION") + am.mode = MODE_IN_COMMUNICATION + } + } + } @SuppressLint("WakelockTimeout", "Wakelock") private fun proximitySensing(enable: Boolean) { if (enable) {