Cancel full screen notification when call is closed

Generate missed call notification also when baresip app is not visible
This commit is contained in:
Juha Heinanen
2026-02-21 21:56:15 +02:00
parent edbcf6e3d6
commit f7662fa6bd
3 changed files with 51 additions and 38 deletions
@@ -1081,8 +1081,8 @@ class BaresipService: Service() {
}
"call closed" -> {
Log.d(TAG, "AoR $aor call $callp is closed prm: ${ev[1]}")
if (call != null) {
nm.cancel(CALL_NOTIFICATION_ID)
if (call != null) {
stopRinging()
stopMediaPlayer()
aec?.release()
@@ -1109,7 +1109,8 @@ class BaresipService: Service() {
val tone = ev[2]
if (tone == "busy") {
playBusy()
} else if (!Call.inCall()) {
}
else if (!Call.inCall()) {
resetCallVolume()
abandonAudioFocus(applicationContext)
proximitySensing(false)
@@ -1162,7 +1163,6 @@ class BaresipService: Service() {
}
ua.account.missedCalls = ua.account.missedCalls || missed
}
if (!Utils.isVisible()) {
if (missed) {
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
val caller = Utils.friendlyUri(this, call.peerUri, ua.account)
@@ -1186,7 +1186,8 @@ class BaresipService: Service() {
if (missedCalls == 0) {
nb.setContentTitle(getString(R.string.missed_call_from))
nb.setContentText(caller)
} else {
}
else {
nb.setContentTitle(getString(R.string.missed_calls))
nb.setContentText(
String.format(getString(R.string.missed_calls_count),
@@ -1194,17 +1195,17 @@ class BaresipService: Service() {
}
nm.notify(CALL_MISSED_NOTIFICATION_ID, nb.build())
}
if (!Utils.isVisible())
return
}
}
val reason = ev[1].trim()
if ((reason != "") && (ua.calls().isEmpty())) {
if (reason[0].isDigit()) {
if (reason[0] != '3')
toast("${getString(R.string.call_failed)}: $reason")
} else {
toast("${getString(R.string.call_closed)}: ${Api.call_peer_uri(callp)}: $reason")
}
else
toast("${getString(R.string.call_closed)}: ${Api.call_peer_uri(callp)}: $reason")
}
}
}
@@ -111,7 +111,7 @@ class MainActivity : ComponentActivity() {
exitProcess(0)
}
} else
handleServiceEvent(applicationContext, viewModel, first.event, first.params)
handleServiceEvent(this, viewModel, first.event, first.params)
}
}
else
@@ -3,7 +3,9 @@ package com.tutpro.baresip
import android.Manifest.permission.READ_EXTERNAL_STORAGE
import android.Manifest.permission.RECORD_AUDIO
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.app.Activity
import android.app.Activity.RESULT_OK
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
@@ -1342,11 +1344,13 @@ private fun CallUriRow(
alertMessage.value = ctx.getString(R.string.call_not_secure)
showAlert.value = true
}
R.color.colorTrafficYellow -> {
alertTitle.value = ctx.getString(R.string.alert)
alertMessage.value = ctx.getString(R.string.peer_not_verified)
showAlert.value = true
}
R.color.colorTrafficGreen -> {
dialogTitle.value = ctx.getString(R.string.info)
dialogMessage.value = ctx.getString(R.string.call_is_secure)
@@ -2460,6 +2464,14 @@ fun handleServiceEvent(ctx: Context, viewModel: ViewModel, event: String, params
showCall(ctx, viewModel, ua)
}
"call closed" -> {
val activity = ctx as? Activity
if (activity != null) {
val kgm = activity.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (kgm.isKeyguardLocked) {
activity.finishAndRemoveTask()
return
}
}
if (aor == viewModel.selectedAor.value) {
viewModel.dialerState.callButtonsEnabled.value = true
ua.account.resumeUri = ""