Use Call.hasTelecomCall() to check is telecom call exists

Apply default call volume to all types of calls
This commit is contained in:
Juha Heinanen
2026-05-11 09:01:22 +03:00
parent 3d16b467f1
commit c74d780619
@@ -871,12 +871,8 @@ class BaresipService: Service() {
break break
speakerPhone = speakerPhoneAuto speakerPhone = speakerPhoneAuto
stopMediaPlayer() stopMediaPlayer()
val hasTelecom = ConnectionService.connections.containsKey(callp) || setCallVolume()
ConnectionService.pendingOutgoingConnection != null ensureCommunicationMode()
if (!hasTelecom) {
setCallVolume()
ensureCommunicationMode()
}
proximitySensing(proximitySensing) proximitySensing(proximitySensing)
} }
"call ringing" -> { "call ringing" -> {
@@ -1467,9 +1463,7 @@ class BaresipService: Service() {
}, audioDelay) }, audioDelay)
} }
val isTelecom = Call.calls().any { ConnectionService.connections.containsKey(it.callp) } || if (Call.hasTelecomCall())
ConnectionService.pendingOutgoingConnection != null
if (isTelecom)
executeCall() executeCall()
else if (VERSION.SDK_INT < 31) { else if (VERSION.SDK_INT < 31) {
Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION") Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION")
@@ -1823,6 +1817,8 @@ class BaresipService: Service() {
}) })
calls.add(call) calls.add(call)
setCallVolume()
ensureCommunicationMode()
postServiceEvent(ServiceEvent( postServiceEvent(ServiceEvent(
"call incoming", "call incoming",
arrayListOf(ua.uap, call.callp), arrayListOf(ua.uap, call.callp),
@@ -1854,12 +1850,10 @@ class BaresipService: Service() {
private fun addMobileUserAgent() { private fun addMobileUserAgent() {
if (!telecom || Utils.pstnAccountHandle(this) == null) return if (!telecom || Utils.pstnAccountHandle(this) == null) return
val mobileAor = Utils.getLine1Number(this)?.let { "tel:$it" } ?: "tel:mobile" val mobileAor = Utils.getLine1Number(this)?.let { "tel:$it" } ?: "tel:mobile"
val existingMobileUa = uas.value.find { it.account.isMobile } val existingMobileUa = uas.value.find { it.account.isMobile }
if (existingMobileUa != null) { if (existingMobileUa != null) {
// If we previously had tel:mobile but now have a real number, replace it // Replace previous tel:mobile with real number
if (existingMobileUa.account.aor == "tel:mobile" && mobileAor != "tel:mobile") { if (existingMobileUa.account.aor == "tel:mobile" && mobileAor != "tel:mobile") {
val updatedUas = uas.value.toMutableList() val updatedUas = uas.value.toMutableList()
updatedUas.remove(existingMobileUa) updatedUas.remove(existingMobileUa)
@@ -2181,8 +2175,7 @@ class BaresipService: Service() {
cleanupRunnable = null cleanupRunnable = null
} }
if (isSpeakerphoneOn == speakerPhone) { if (isSpeakerphoneOn == speakerPhone) {
val hasTelecom = Call.calls().any { ConnectionService.connections.containsKey(it.callp) } if (Call.hasTelecomCall() || currentMode == MODE_IN_COMMUNICATION) {
if (hasTelecom || currentMode == MODE_IN_COMMUNICATION) {
Log.d(TAG, "Already in valid call mode ($currentMode) with correct speaker state.") Log.d(TAG, "Already in valid call mode ($currentMode) with correct speaker state.")
return return
} }
@@ -2209,13 +2202,17 @@ class BaresipService: Service() {
val runnable = Runnable { val runnable = Runnable {
cleanupRunnable = null cleanupRunnable = null
if (Call.inCall()) { if (Call.inCall()) {
val hasTelecom = Call.calls().any { ConnectionService.connections.containsKey(it.callp) } val hasTelecom = Call.hasTelecomCall()
if (!hasTelecom && am.mode != MODE_IN_COMMUNICATION && am.mode != AudioManager.MODE_IN_CALL) { if (!hasTelecom && am.mode != MODE_IN_COMMUNICATION && am.mode != AudioManager.MODE_IN_CALL) {
am.mode = MODE_IN_COMMUNICATION am.mode = MODE_IN_COMMUNICATION
Log.d(TAG, "Manual Mode Guard: Setting MODE_IN_COMMUNICATON from ${am.mode}") Log.d(TAG, "Manual Mode Guard: Setting MODE_IN_COMMUNICATON from ${am.mode}")
} }
Log.d(TAG, "Applying speakerphone state: $speakerPhone") Log.d(TAG, "Applying speakerphone state: $speakerPhone")
if (!hasTelecom) { if (InCallService.instance != null) {
Log.d(TAG, "Using InCallService for audio route: $speakerPhone")
@Suppress("DEPRECATION")
InCallService.instance!!.setAudioRoute(if (speakerPhone) android.telecom.CallAudioState.ROUTE_SPEAKER else android.telecom.CallAudioState.ROUTE_EARPIECE)
} else if (!hasTelecom) {
Log.d(TAG, "No Telecom connection, using AudioManager for speaker") Log.d(TAG, "No Telecom connection, using AudioManager for speaker")
Utils.setSpeakerPhone(mainExecutor, am, speakerPhone) Utils.setSpeakerPhone(mainExecutor, am, speakerPhone)
} else { } else {
@@ -2250,7 +2247,7 @@ class BaresipService: Service() {
) )
) )
} }
if (!Call.calls().any { ConnectionService.connections.containsKey(it.callp) }) if (!Call.hasTelecomCall())
resetCallVolume() resetCallVolume()
proximitySensing(false) proximitySensing(false)
} }