Fixed adding of mobile call to history

Fixed outgoing mobile call event
Do not show new call card when mobile call is placed on hold
This commit is contained in:
Juha Heinanen
2026-05-12 10:17:34 +03:00
parent 294d30055d
commit 8fbb73a21c
4 changed files with 30 additions and 12 deletions
@@ -1291,10 +1291,9 @@ private fun AccountContent(
Answer() Answer()
} }
Voicemail() Voicemail()
if (!ua.account.isMobile) { CountryCode()
CountryCode() if (!ua.account.isMobile)
TelProvider() TelProvider()
}
NumericKeypad() NumericKeypad()
DefaultAccount() DefaultAccount()
if (!ua.account.isMobile) if (!ua.account.isMobile)
@@ -68,6 +68,7 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.IconCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.tutpro.baresip.Utils.e164Uri
import com.tutpro.baresip.Utils.toCircle import com.tutpro.baresip.Utils.toCircle
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -1703,8 +1704,12 @@ class BaresipService: Service() {
} }
fun handleExternalCall(telecomCall: android.telecom.Call, preferredAor: String? = null) { fun handleExternalCall(telecomCall: android.telecom.Call, preferredAor: String? = null) {
val uri = telecomCall.details.handle?.schemeSpecificPart ?: "Unknown" val rawUri = telecomCall.details.handle?.toString() ?: "Unknown"
Log.d(TAG, "Handling external call from $uri (preferredAor=$preferredAor)") val uri = try {
java.net.URLDecoder.decode(rawUri, "UTF-8")
} catch (_: Exception) {
rawUri
}
if (uas.value.isEmpty()) { if (uas.value.isEmpty()) {
Log.e(TAG, "No User Agents available to handle external call") Log.e(TAG, "No User Agents available to handle external call")
@@ -1719,13 +1724,17 @@ class BaresipService: Service() {
telecomCall.details.state telecomCall.details.state
else else
@Suppress("DEPRECATION") telecomCall.state @Suppress("DEPRECATION") telecomCall.state
val isIncoming = telecomState == android.telecom.Call.STATE_RINGING
Log.d(TAG, "Handling external call ${if (isIncoming) "from" else "to"} $uri (preferredAor=$preferredAor)")
val initialStatus = when (telecomState) { val initialStatus = when (telecomState) {
android.telecom.Call.STATE_RINGING -> "incoming" android.telecom.Call.STATE_RINGING -> "incoming"
android.telecom.Call.STATE_DIALING, android.telecom.Call.STATE_CONNECTING -> "outgoing" android.telecom.Call.STATE_DIALING, android.telecom.Call.STATE_CONNECTING -> "outgoing"
else -> "connected" else -> "connected"
} }
if (initialStatus == "incoming") { if (isIncoming) {
if (ua.account.blockUnknown && Contact.contactName(uri) == uri) { if (ua.account.blockUnknown && Contact.contactName(uri) == uri) {
Log.d(TAG, "Auto-rejecting incoming PSTN call from $uri") Log.d(TAG, "Auto-rejecting incoming PSTN call from $uri")
telecomCall.disconnect() telecomCall.disconnect()
@@ -1786,7 +1795,7 @@ class BaresipService: Service() {
setCallVolume() setCallVolume()
ensureCommunicationMode() ensureCommunicationMode()
postServiceEvent(ServiceEvent( postServiceEvent(ServiceEvent(
"call incoming", if (isIncoming) "call incoming" else "call outgoing",
arrayListOf(ua.uap, call.callp), arrayListOf(ua.uap, call.callp),
System.nanoTime()) System.nanoTime())
) )
@@ -1797,7 +1806,8 @@ class BaresipService: Service() {
val call = calls.find { it.callp == callp } val call = calls.find { it.callp == callp }
if (call != null) { if (call != null) {
if (call.ua.account.callHistory) { if (call.ua.account.callHistory) {
val history = CallHistoryNew(call.ua.account.aor, call.peerUri, call.dir) val historyPeerUri = e164Uri(call.peerUri, call.ua.account.countryCode)
val history = CallHistoryNew(call.ua.account.aor, historyPeerUri, call.dir)
history.stopTime = GregorianCalendar() history.stopTime = GregorianCalendar()
history.startTime = call.startTime history.startTime = call.startTime
history.rejected = call.rejected history.rejected = call.rejected
@@ -916,6 +916,7 @@ private fun MainContent(navController: NavController, viewModel: ViewModel, cont
val calls by viewModel.calls.collectAsState() val calls by viewModel.calls.collectAsState()
val selectedAor by viewModel.selectedAor.collectAsState() val selectedAor by viewModel.selectedAor.collectAsState()
val ua = uas.value.find { it.account.aor == selectedAor }
val aorCalls = calls.filter { it.ua.account.aor == selectedAor } val aorCalls = calls.filter { it.ua.account.aor == selectedAor }
val hasActiveCalls = aorCalls.any { !it.callOnHold.value } val hasActiveCalls = aorCalls.any { !it.callOnHold.value }
val conferenceCall = aorCalls.any { it.conferenceCall } val conferenceCall = aorCalls.any { it.conferenceCall }
@@ -1027,7 +1028,12 @@ private fun MainContent(navController: NavController, viewModel: ViewModel, cont
} }
} }
if (!hasActiveCalls || conferenceCall) val showEmptyCard = if (ua?.account?.isMobile == true)
aorCalls.isEmpty()
else
!hasActiveCalls || conferenceCall
if (showEmptyCard)
CallCard(ctx = ctx, viewModel = viewModel, call = null, dialerState = viewModel.dialerState) CallCard(ctx = ctx, viewModel = viewModel, call = null, dialerState = viewModel.dialerState)
Indicator( Indicator(
@@ -133,7 +133,10 @@ object Utils {
return if (uri.contains("@")) return if (uri.contains("@"))
uri.substringAfter(":").substringBefore("@") uri.substringAfter(":").substringBefore("@")
else else
"" if (isTelUri(uri))
uri.substringAfter(":").substringBefore(";")
else
""
} }
fun uriMatch(firstUri: String, secondUri: String): Boolean { fun uriMatch(firstUri: String, secondUri: String): Boolean {
@@ -185,14 +188,14 @@ object Utils {
return u return u
} }
private fun e164Uri(uri: String, countryCode: String): String { fun e164Uri(uri: String, countryCode: String): String {
if (countryCode == "") return uri if (countryCode == "") return uri
val scheme = uri.take(4) val scheme = uri.take(4)
val userPart = uriUserPart(uri) val userPart = uriUserPart(uri)
return if (userPart.isDigitsOnly()) { return if (userPart.isDigitsOnly()) {
when { when {
userPart.startsWith("00") -> uri.replace("$scheme$userPart", userPart.startsWith("00") -> uri.replace("$scheme$userPart",
scheme + userPart.substring(2)) scheme + "+" + userPart.substring(2))
userPart.startsWith("0") -> uri.replace("${scheme}0", userPart.startsWith("0") -> uri.replace("${scheme}0",
"$scheme$countryCode") "$scheme$countryCode")
else -> uri.replace(scheme, "$scheme$countryCode") else -> uri.replace(scheme, "$scheme$countryCode")