From 32a26978a19138eb862210aac11d8a0250ee08c2 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 2 May 2026 10:12:16 +0300 Subject: [PATCH] More audio fixes --- .../com/tutpro/baresip/BaresipService.kt | 35 +++++++++---------- .../com/tutpro/baresip/ConnectionService.kt | 6 ++-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 11d8dae4..c771ec41 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -17,8 +17,6 @@ import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager import android.content.pm.ServiceInfo -import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE -import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL import android.content.res.Configuration import android.database.ContentObserver import android.graphics.ImageDecoder @@ -889,10 +887,8 @@ class BaresipService: Service() { proximitySensing(proximitySensing) } "call ringing" -> { - if (!telecom) { - ensureCommunicationMode() - playRingBack() - } + if (!telecom) ensureCommunicationMode() + playRingBack() return } "call progress" -> { @@ -900,7 +896,7 @@ class BaresipService: Service() { if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0) stopMediaPlayer() else { - if (!telecom) playRingBack() + playRingBack() } return } @@ -982,6 +978,7 @@ class BaresipService: Service() { } "call answered" -> { stopMediaPlayer() + ConnectionService.connections[callp]?.setActive() ensureCommunicationMode() if (call!!.status.value == "incoming") call.status.value = "answered" @@ -992,7 +989,6 @@ class BaresipService: Service() { stopMediaPlayer() } "call established" -> { - ConnectionService.connections[callp]?.setActive() ensureCommunicationMode() stopMediaPlayer() nm.cancel(CALL_NOTIFICATION_ID) @@ -1039,8 +1035,10 @@ class BaresipService: Service() { if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0) stopMediaPlayer() else { - ConnectionService.connections[callp]?.setRinging() - playRingBack() + if (!telecom) { + ConnectionService.connections[callp]?.setRinging() + playRingBack() + } } } if (call.status.value == "connected" && !call.held && !call.onhold) { @@ -1755,16 +1753,15 @@ class BaresipService: Service() { } private fun foregroundServiceType(): Int { - return if (VERSION.SDK_INT >= 34) { - ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE - } else if (VERSION.SDK_INT >= 30) { - if (ContextCompat.checkSelfPermission(this, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) - FOREGROUND_SERVICE_TYPE_PHONE_CALL or FOREGROUND_SERVICE_TYPE_MICROPHONE - else - FOREGROUND_SERVICE_TYPE_PHONE_CALL - } else { - 0 + var type = 0 + if (VERSION.SDK_INT >= 30) { + type = type or ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL + type = type or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE } + if (VERSION.SDK_INT >= 34) { + type = type or ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE + } + return type } @SuppressLint("WakelockTimeout") diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt index ee4fa1b7..b9bbccb1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt @@ -69,7 +69,8 @@ class ConnectionService : ConnectionService() { Connection.CAPABILITY_HOLD or Connection.CAPABILITY_MERGE_CONFERENCE or Connection.CAPABILITY_SWAP_CONFERENCE - connection.audioModeIsVoip = true + if (android.os.Build.VERSION.SDK_INT >= 31) + connection.audioModeIsVoip = true val call = Call.ofCallp(callp) if (call != null) @@ -123,7 +124,8 @@ class ConnectionService : ConnectionService() { Connection.CAPABILITY_HOLD or Connection.CAPABILITY_MERGE_CONFERENCE or Connection.CAPABILITY_SWAP_CONFERENCE - connection.audioModeIsVoip = true + if (android.os.Build.VERSION.SDK_INT >= 31) + connection.audioModeIsVoip = true // Start the SIP connection logic if (uap != 0L) {