From cab84308a3c0a5f7222e02b65f0c422ef5175916 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Tue, 22 Feb 2022 10:14:50 +0200 Subject: [PATCH] Improved handling of call auto-rejection --- app/src/main/cpp/baresip.c | 8 ++++- .../com/tutpro/baresip/BaresipService.kt | 35 +++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 676732b9..33ce6285 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -175,7 +175,13 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, len = re_snprintf(event_buf, sizeof event_buf, "registering failed,%s", prm); break; case UA_EVENT_CALL_INCOMING: - len = re_snprintf(event_buf, sizeof event_buf, "call incoming"); + if (uag_call_count() > 1) { + LOGD("auto-rejecting call from %s\n", prm); + ua_hangup(ua, call, 486, "Busy Here"); + len = re_snprintf(event_buf, sizeof event_buf, "call rejected,%s", prm); + } else { + len = re_snprintf(event_buf, sizeof event_buf, "call incoming,%s", prm); + } break; case UA_EVENT_CALL_OUTGOING: len = re_snprintf(event_buf, sizeof event_buf, "call outgoing"); diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index e28be3b9..47e2b99d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -565,7 +565,7 @@ class BaresipService: Service() { } val call = Call.ofCallp(callp) - if (call == null && callp != "0" && ev[0] != "call incoming") { + if (call == null && callp != "0" && ev[0] != "call incoming" && ev[0] != "call rejected") { Log.w(TAG, "uaEvent $event did not find call $callp") return } @@ -635,15 +635,17 @@ class BaresipService: Service() { return } "call incoming" -> { - val peerUri = Api.call_peeruri(callp) - if (Call.calls().size > 0 || - !Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) { - Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri") - Api.ua_hangup(uap, callp, 486, "Busy Here") - playUnInterrupted(R.raw.callwaiting, 1) - if (!Utils.isVisible()) - return - newEvent = "call rejected" + val peerUri = ev[1] + if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) { + toast(getString(R.string.no_calls)) + if (ua.account.callHistory) { + NewCallHistory.add(NewCallHistory(aor, peerUri, "in")) + NewCallHistory.save() + ua.account.missedCalls = true + } + if (!isMainVisible) + return + newEvent = "call rejected" } else { Log.d(TAG, "Incoming call $uap/$callp/$peerUri") Call(callp, ua, peerUri, "in", "incoming", @@ -724,6 +726,19 @@ class BaresipService: Service() { return } } + "call rejected" -> { + playUnInterrupted(R.raw.callwaiting, 1) + if (ua.account.callHistory) { + NewCallHistory.add(NewCallHistory(aor, ev[1], "in")) + NewCallHistory.save() + ua.account.missedCalls = true + if (!isMainVisible) + return + newEvent = "call rejected" + } else { + return + } + } "call answered" -> { stopMediaPlayer() if (call!!.status == "incoming")