diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 55c8717c..cae4e965 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -801,7 +801,7 @@ class BaresipService: Service() { "incoming call" -> { val peerUri = ev[1] val bevent = ev[2].toLong() - val toastMsg = if (Call.isAnyCallActive(applicationContext)) + val toastMsg = if (Utils.isAnyCallActive(applicationContext)) String.format(getString(R.string.call_auto_rejected), Utils.friendlyUri(this, peerUri, ua.account)) else if (ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) @@ -1541,8 +1541,7 @@ class BaresipService: Service() { @SuppressLint("WakelockTimeout") private fun updatePartialWakeLock() { val isAnyUaActive = uasStatus.value.values.any { it != R.drawable.circle_white } - val isAnyCallActive = calls.isNotEmpty() - val needsToStayAwake = isAnyUaActive || isAnyCallActive + val needsToStayAwake = isAnyUaActive || calls.isNotEmpty() try { if (needsToStayAwake) { if (!partialWakeLock.isHeld) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Call.kt b/app/src/main/kotlin/com/tutpro/baresip/Call.kt index 3dff670e..8f74a7a0 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Call.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Call.kt @@ -1,7 +1,5 @@ package com.tutpro.baresip -import android.content.Context -import android.media.AudioManager import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf @@ -144,13 +142,5 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str fun inCall(): Boolean { return BaresipService.calls.isNotEmpty() } - - fun isAnyCallActive(ctx: Context): Boolean { - // Check SIP calls managed by baresip - if (inCall()) return true - // MODE_IN_CALL indicates a PSTN call is active - val am = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager - return am.mode == AudioManager.MODE_IN_CALL - } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt index fe8df5fb..36a61d02 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt @@ -206,13 +206,23 @@ class ConnectionService : ConnectionService() { override fun onHold() { Log.d(TAG, "Telecom Connection onHold $callp") - Api.call_hold(callp, true) + val call = Call.ofCallp(callp) + if (call == null || !call.conferenceCall) { + Api.call_hold(callp, true) + } else { + Log.d(TAG, "Call $callp is in conference, skipping baresip hold") + } setOnHold() } override fun onUnhold() { Log.d(TAG, "Telecom Connection onUnhold $callp") - Api.call_hold(callp, false) + val call = Call.ofCallp(callp) + if (call == null || !call.conferenceCall) { + Api.call_hold(callp, false) + } else { + Log.d(TAG, "Call $callp is in conference, skipping baresip resume") + } setActive() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt index cfd5717d..111af184 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt @@ -2061,7 +2061,7 @@ private fun makeCall(ctx: Context, viewModel: ViewModel, uriText: String, confer alertMessage.value = String.format(ctx.getString(R.string.invalid_sip_or_tel_uri), uri) showAlert.value = true } - else if (Call.isAnyCallActive(ctx)) + else if (Utils.isPSTNCallActive(ctx) || Call.calls().any { it.ua.account.aor != ua.account.aor } ) Toast.makeText(ctx, R.string.call_already_active, Toast.LENGTH_SHORT).show() else { val tm = ctx.getSystemService(Context.TELECOM_SERVICE) as android.telecom.TelecomManager diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 8fea284f..97e3431c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -41,6 +41,7 @@ import androidx.core.text.isDigitsOnly import androidx.lifecycle.Lifecycle import androidx.lifecycle.ProcessLifecycleOwner import androidx.navigation.NavController +import com.tutpro.baresip.Call.Companion.inCall import java.io.BufferedInputStream import java.io.BufferedOutputStream import java.io.File @@ -841,6 +842,16 @@ object Utils { Configuration.UI_MODE_NIGHT_YES } + fun isAnyCallActive(ctx: Context): Boolean { + return inCall() || isPSTNCallActive(ctx) + } + + fun isPSTNCallActive(ctx: Context): Boolean { + // MODE_IN_CALL indicates a PSTN call is active + val am = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager + return am.mode == AudioManager.MODE_IN_CALL + } + fun relativeTime(ctx: Context, time: GregorianCalendar): String { return if (DateUtils.isToday(time.timeInMillis)) { val fmt = DateFormat.getTimeInstance(DateFormat.SHORT) @@ -887,7 +898,7 @@ object Utils { Log.d(TAG, "Setting com device to TYPE_BUILTIN_EARPIECE") if (!am.setCommunicationDevice(speakerDevice)) Log.e(TAG, "Could not set com device") - if (Call.inCall() && am.mode == AudioManager.MODE_NORMAL) { + if (inCall() && am.mode == AudioManager.MODE_NORMAL) { Log.d(TAG, "Setting mode to communication") am.mode = AudioManager.MODE_IN_COMMUNICATION }