From de77528582bad2c74c4b2a182022288de19aba5f Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 18 May 2026 17:32:40 +0300 Subject: [PATCH] Fixed speakerphone toggling during mobile calls --- .../com/tutpro/baresip/BaresipService.kt | 14 ++++++++++++++ .../kotlin/com/tutpro/baresip/MainScreen.kt | 19 ++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 194c1df4..0d5e4633 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -2434,6 +2434,20 @@ class BaresipService: Service() { handler.postDelayed(runnable, 500) } + fun toggleSpeakerphone() { + speakerPhone = !speakerPhone + // Notify the UI to update the icon color + postServiceEvent( + ServiceEvent( + "speaker update,$speakerPhone", + arrayListOf(0L, 0L), + System.nanoTime() + ) + ) + // Apply the new audio route + ensureCommunicationMode() + } + @SuppressLint("WakelockTimeout", "Wakelock") private fun proximitySensing(enable: Boolean) { if (enable) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt index 67eef158..18e7139f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt @@ -643,23 +643,8 @@ private fun TopAppBar( .clip(CircleShape) .combinedClickable( onClick = { - val aor = viewModel.selectedAor.value - val ua = uas.value.find { it.account.aor == aor } - val call = ua?.currentCall() - val connection = - if (call != null) ConnectionService.connections[call.callp] else null - if (connection != null) { - @Suppress("DEPRECATION") - connection.setAudioRoute( - if (isSpeakerOn) - android.telecom.CallAudioState.ROUTE_EARPIECE - else - android.telecom.CallAudioState.ROUTE_SPEAKER - ) - } else { - BaresipService.speakerPhone = !isSpeakerOn - viewModel.updateSpeakerPhoneStatus(BaresipService.speakerPhone) - } + // Unified toggle via BaresipService + BaresipService.instance?.toggleSpeakerphone() }, onLongClick = { alertTitle.value = speakerPhoneTitle