Properly cancel missed mobile calls notification when call history is entered

This commit is contained in:
Juha Heinanen
2026-07-15 16:50:16 +03:00
parent 230d2ca99a
commit f39153ac1d

View File

@ -1,7 +1,9 @@
package com.tutpro.baresip
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.telecom.TelecomManager
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
@ -98,7 +100,11 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
var refreshTrigger by remember { mutableIntStateOf(0) }
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(aor, refreshTrigger) {
val ctx = LocalContext.current
LaunchedEffect(ua, refreshTrigger) {
if (ua.account.isMobile)
clearSystemMissedCalls(ctx)
callHistory.value = loadCallHistory(aor)
isHistoryLoaded = true
}
@ -114,8 +120,6 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
}
}
val ctx = LocalContext.current
BackHandler(enabled = true) {
val serviceIntent = Intent(ctx, BaresipService::class.java)
serviceIntent.action = "Clear Missed"
@ -594,3 +598,16 @@ fun callTint(direction: Int): Int {
else -> R.color.colorTrafficYellow
}
}
@SuppressLint("MissingPermission")
private fun clearSystemMissedCalls(ctx: Context) {
val telecom = ctx.getSystemService(TelecomManager::class.java)
try {
telecom.cancelMissedCallsNotification()
Log.d(TAG, "cancelMissedCallsNotification() succeeded")
} catch (e: SecurityException) {
Log.w(TAG, "Cannot clear missed call notification: $e")
} catch (e: Exception) {
Log.e(TAG, "Unexpected failure clearing missed call notification", e)
}
}