Use baresip's missed call notification also for missed mobile calls
Added caller's contact name (is available) to Connection Service connection
This commit is contained in:
@ -2276,8 +2276,7 @@ class BaresipService: Service() {
|
|||||||
history.add()
|
history.add()
|
||||||
if (call.dir == "in" && call.startTime == null && !call.rejected) {
|
if (call.dir == "in" && call.startTime == null && !call.rejected) {
|
||||||
call.ua.account.missedCalls = true
|
call.ua.account.missedCalls = true
|
||||||
if (!call.ua.account.isMobile)
|
showMissedCallNotification(uap, call.peerUri, call.ua.account.aor)
|
||||||
showMissedCallNotification(uap, call.peerUri, call.ua.account.aor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
synchronized(calls) {
|
synchronized(calls) {
|
||||||
@ -3095,6 +3094,11 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showMissedCallNotification(uap: Long, peerUri: String, aor: String) {
|
private fun showMissedCallNotification(uap: Long, peerUri: String, aor: String) {
|
||||||
|
Utils.cancelMissedCallsNotification(this)
|
||||||
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
|
Utils.cancelMissedCallsNotification(this)
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
val caller = Utils.friendlyUri(this, peerUri, Account.ofAor(aor)!!)
|
val caller = Utils.friendlyUri(this, peerUri, Account.ofAor(aor)!!)
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.telecom.TelecomManager
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
@ -104,7 +102,7 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
|
|||||||
|
|
||||||
LaunchedEffect(ua, refreshTrigger) {
|
LaunchedEffect(ua, refreshTrigger) {
|
||||||
if (ua.account.isMobile)
|
if (ua.account.isMobile)
|
||||||
clearSystemMissedCalls(ctx)
|
Utils.cancelMissedCallsNotification(ctx)
|
||||||
callHistory.value = loadCallHistory(aor)
|
callHistory.value = loadCallHistory(aor)
|
||||||
isHistoryLoaded = true
|
isHistoryLoaded = true
|
||||||
}
|
}
|
||||||
@ -599,15 +597,3 @@ fun callTint(direction: Int): Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -80,6 +80,10 @@ class ConnectionService : ConnectionService() {
|
|||||||
|
|
||||||
val ua = UserAgent.ofUap(uap)
|
val ua = UserAgent.ofUap(uap)
|
||||||
if (ua != null) {
|
if (ua != null) {
|
||||||
|
val contactName = Utils.friendlyUri(this, peerUri, ua.account)
|
||||||
|
if (contactName != peerUri)
|
||||||
|
connection.setCallerDisplayName(contactName, TelecomManager.PRESENTATION_ALLOWED)
|
||||||
|
|
||||||
connection.setRinging()
|
connection.setRinging()
|
||||||
if (ua.account.answerMode == Api.ANSWERMODE_AUTO) {
|
if (ua.account.answerMode == Api.ANSWERMODE_AUTO) {
|
||||||
Log.d(TAG, "Auto-answering call $callp")
|
Log.d(TAG, "Auto-answering call $callp")
|
||||||
@ -126,6 +130,15 @@ class ConnectionService : ConnectionService() {
|
|||||||
pendingOutgoingConnection = connection
|
pendingOutgoingConnection = connection
|
||||||
|
|
||||||
connection.setAddress(request?.address, TelecomManager.PRESENTATION_ALLOWED)
|
connection.setAddress(request?.address, TelecomManager.PRESENTATION_ALLOWED)
|
||||||
|
|
||||||
|
val ua = UserAgent.ofUap(uap)
|
||||||
|
if (ua != null) {
|
||||||
|
val address = request?.address?.toString() ?: ""
|
||||||
|
val contactName = Utils.friendlyUri(this, address, ua.account)
|
||||||
|
if (contactName != address)
|
||||||
|
connection.setCallerDisplayName(contactName, TelecomManager.PRESENTATION_ALLOWED)
|
||||||
|
}
|
||||||
|
|
||||||
connection.connectionCapabilities = Connection.CAPABILITY_SUPPORT_HOLD or
|
connection.connectionCapabilities = Connection.CAPABILITY_SUPPORT_HOLD or
|
||||||
Connection.CAPABILITY_HOLD or
|
Connection.CAPABILITY_HOLD or
|
||||||
Connection.CAPABILITY_MERGE_CONFERENCE or
|
Connection.CAPABILITY_MERGE_CONFERENCE or
|
||||||
|
|||||||
@ -1368,6 +1368,19 @@ object Utils {
|
|||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun cancelMissedCallsNotification(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(29)
|
@RequiresApi(29)
|
||||||
fun pstnAccountHandle(ctx: Context): PhoneAccountHandle? {
|
fun pstnAccountHandle(ctx: Context): PhoneAccountHandle? {
|
||||||
val roleManager = ctx.getSystemService(ROLE_SERVICE) as RoleManager
|
val roleManager = ctx.getSystemService(ROLE_SERVICE) as RoleManager
|
||||||
|
|||||||
Reference in New Issue
Block a user