Hardened call closed event handling

This commit is contained in:
Juha Heinanen
2026-05-25 08:55:04 +03:00
parent 8247f53f54
commit dc18b425ce
@@ -1136,12 +1136,6 @@ class BaresipService: Service() {
} }
"call closed" -> { "call closed" -> {
Log.d(TAG, "AoR $aor call $callp is closed prm: ${ev[1]}") Log.d(TAG, "AoR $aor call $callp is closed prm: ${ev[1]}")
if (call != null) {
call.terminated.value = true
call.remove()
if (!Call.inCall())
proximitySensing(false)
}
val connection = ConnectionService.connections[callp] val connection = ConnectionService.connections[callp]
if (connection != null) { if (connection != null) {
val cause = when { val cause = when {
@@ -1156,12 +1150,19 @@ class BaresipService: Service() {
connection.destroy() connection.destroy()
ConnectionService.connections.remove(callp) ConnectionService.connections.remove(callp)
} }
updateStatusNotification()
if (call != null) { if (call != null) {
call.terminated.value = true
call.remove()
val noMoreCalls = synchronized(calls) { !Call.inCall() }
stopRinging() stopRinging()
stopMediaPlayer() stopMediaPlayer()
if (!Call.inCall())
if (noMoreCalls) {
proximitySensing(false)
abandonAudioFocus(this) abandonAudioFocus(this)
}
val newCall = call.newCall val newCall = call.newCall
if (newCall != null) { if (newCall != null) {
newCall.onHoldCall = null newCall.onHoldCall = null
@@ -1174,8 +1175,8 @@ class BaresipService: Service() {
call.onHoldCall = null call.onHoldCall = null
} }
val isConference = call.conferenceCall val isConference = call.conferenceCall
val hasOtherCalls = calls.any { it.ua == ua } val hasOtherCalls = synchronized(calls) { calls.any { it.ua == ua } }
if (calls.isEmpty()) { if (noMoreCalls) {
aec?.release() aec?.release()
aec = null aec = null
agc?.release() agc?.release()
@@ -1188,7 +1189,10 @@ class BaresipService: Service() {
if (isConference && !hasOtherCalls) { if (isConference && !hasOtherCalls) {
Log.d(TAG, "Last conference call closed, scheduling mixminus unload") Log.d(TAG, "Last conference call closed, scheduling mixminus unload")
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
if (calls.none { it.conferenceCall }) { val conferenceActive = synchronized(calls) {
calls.any { it.conferenceCall }
}
if (!conferenceActive) {
Log.d(TAG, "Unloading mixminus module") Log.d(TAG, "Unloading mixminus module")
Api.module_unload("mixminus") Api.module_unload("mixminus")
} }