Don't show call timer notification on locked screen after call is closed
This commit is contained in:
@@ -1089,6 +1089,7 @@ class BaresipService: Service() {
|
|||||||
Handler(Looper.getMainLooper()).postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
connection.destroy()
|
connection.destroy()
|
||||||
ConnectionService.connections.remove(callp)
|
ConnectionService.connections.remove(callp)
|
||||||
|
updateStatusNotification()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
nm.cancel(CALL_NOTIFICATION_ID)
|
nm.cancel(CALL_NOTIFICATION_ID)
|
||||||
@@ -1565,18 +1566,32 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
fun updateStatusNotification() {
|
fun updateStatusNotification() {
|
||||||
|
|
||||||
val activeCall = Call.calls().find {
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
val activeCall = synchronized(calls) {
|
||||||
|
calls.find {
|
||||||
it.status.value == "connected" || it.status.value == "outgoing" || it.status.value == "answered"
|
it.status.value == "connected" || it.status.value == "outgoing" || it.status.value == "answered"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val builder = NotificationCompat.Builder(this, LOW_CHANNEL_ID)
|
val builder = NotificationCompat.Builder(this, LOW_CHANNEL_ID)
|
||||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||||
.setAction(Intent.ACTION_MAIN)
|
.setAction(Intent.ACTION_MAIN)
|
||||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
|
||||||
val pi = PendingIntent.getActivity(applicationContext, STATUS_REQ_CODE, intent, PendingIntent.FLAG_IMMUTABLE)
|
val pi = PendingIntent.getActivity(
|
||||||
val deleteIntent = Intent(this, BaresipService::class.java).setAction("Notification Dismissed")
|
applicationContext,
|
||||||
val dpi = PendingIntent.getService(this, STATUS_REQ_CODE, deleteIntent, PendingIntent.FLAG_IMMUTABLE)
|
STATUS_REQ_CODE,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
val deleteIntent =
|
||||||
|
Intent(this, BaresipService::class.java).setAction("Notification Dismissed")
|
||||||
|
val dpi = PendingIntent.getService(
|
||||||
|
this,
|
||||||
|
STATUS_REQ_CODE,
|
||||||
|
deleteIntent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setSmallIcon(R.drawable.ic_notification_b)
|
.setSmallIcon(R.drawable.ic_notification_b)
|
||||||
@@ -1592,8 +1607,10 @@ class BaresipService: Service() {
|
|||||||
val hangupIntent = Intent(this, BaresipService::class.java)
|
val hangupIntent = Intent(this, BaresipService::class.java)
|
||||||
hangupIntent.action = "Call Hangup"
|
hangupIntent.action = "Call Hangup"
|
||||||
hangupIntent.putExtra("callp", activeCall.callp)
|
hangupIntent.putExtra("callp", activeCall.callp)
|
||||||
val hpi = PendingIntent.getService(this, REJECT_REQ_CODE, hangupIntent,
|
val hpi = PendingIntent.getService(
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
this, REJECT_REQ_CODE, hangupIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(person, hpi))
|
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(person, hpi))
|
||||||
.setCategory(Notification.CATEGORY_CALL)
|
.setCategory(Notification.CATEGORY_CALL)
|
||||||
@@ -1649,28 +1666,36 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
builder.setOngoing(true)
|
builder.setOngoing(true)
|
||||||
val notification = builder.build()
|
val notification = builder.build()
|
||||||
notification.flags = notification.flags or Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT
|
notification.flags =
|
||||||
|
notification.flags or Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (activeCall != null) {
|
if (activeCall != null) {
|
||||||
if (VERSION.SDK_INT >= 29)
|
if (VERSION.SDK_INT >= 29)
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification, foregroundServiceType(activeCall))
|
startForeground(
|
||||||
|
STATUS_NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
foregroundServiceType(activeCall)
|
||||||
|
)
|
||||||
else
|
else
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification)
|
startForeground(STATUS_NOTIFICATION_ID, notification)
|
||||||
isNotificationInCall = true
|
isNotificationInCall = true
|
||||||
} else {
|
} else {
|
||||||
// If we are currently in a call notification mode, downgrade to standby FGS
|
// If we are currently in a call notification mode, downgrade to standby FGS.
|
||||||
// but DO NOT call stopForeground as that would drop FGS status.
|
// We call stopForeground(REMOVE) to explicitly clear the system's telephony UI context
|
||||||
|
// that might be persisting the timer/peer info on the lock screen.
|
||||||
if (isNotificationInCall) {
|
if (isNotificationInCall) {
|
||||||
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
isNotificationInCall = false
|
||||||
|
}
|
||||||
if (VERSION.SDK_INT >= 29)
|
if (VERSION.SDK_INT >= 29)
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification, foregroundServiceType())
|
startForeground(
|
||||||
|
STATUS_NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
foregroundServiceType()
|
||||||
|
)
|
||||||
else
|
else
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification)
|
startForeground(STATUS_NOTIFICATION_ID, notification)
|
||||||
isNotificationInCall = false
|
|
||||||
} else {
|
|
||||||
// Already in standby, just update the notification content
|
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, notification)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Failed to update foreground notification: ${e.message}")
|
Log.e(TAG, "Failed to update foreground notification: ${e.message}")
|
||||||
@@ -1678,6 +1703,7 @@ class BaresipService: Service() {
|
|||||||
nm.notify(STATUS_NOTIFICATION_ID, notification)
|
nm.notify(STATUS_NOTIFICATION_ID, notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun foregroundServiceType(activeCall: Call? = null): Int {
|
private fun foregroundServiceType(activeCall: Call? = null): Int {
|
||||||
var type = 0
|
var type = 0
|
||||||
@@ -1841,6 +1867,7 @@ class BaresipService: Service() {
|
|||||||
proximitySensing(false)
|
proximitySensing(false)
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
}
|
}
|
||||||
|
updateStatusNotification()
|
||||||
messageUpdate.postValue(System.currentTimeMillis())
|
messageUpdate.postValue(System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,12 +48,16 @@ open class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir
|
|||||||
val focusDtmf: MutableState<Boolean> = mutableStateOf(false)
|
val focusDtmf: MutableState<Boolean> = mutableStateOf(false)
|
||||||
|
|
||||||
fun add() {
|
fun add() {
|
||||||
|
synchronized(BaresipService.calls) {
|
||||||
BaresipService.calls.add(this)
|
BaresipService.calls.add(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun remove() {
|
fun remove() {
|
||||||
|
synchronized(BaresipService.calls) {
|
||||||
BaresipService.calls.remove(this)
|
BaresipService.calls.remove(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open fun connect(uri: String): Boolean {
|
open fun connect(uri: String): Boolean {
|
||||||
return Api.call_connect(callp, uri) == 0
|
return Api.call_connect(callp, uri) == 0
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ class ConnectionService : ConnectionService() {
|
|||||||
if (call != null)
|
if (call != null)
|
||||||
Api.ua_hangup(uap, callp, 0, "")
|
Api.ua_hangup(uap, callp, 0, "")
|
||||||
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
||||||
|
connections.remove(callp)
|
||||||
destroy()
|
destroy()
|
||||||
// Allow other disconnects after a short period to prevent the "Telecom Cascade" effect
|
// Allow other disconnects after a short period to prevent the "Telecom Cascade" effect
|
||||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||||
|
|||||||
Reference in New Issue
Block a user