VoIP: always use silent for pending call notification

This commit is contained in:
ganfra 2020-12-15 18:44:59 +01:00
parent 81f7932cb7
commit a16086db6f
5 changed files with 6 additions and 55 deletions

View File

@ -144,10 +144,6 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
ACTION_CALL_TERMINATED -> {
handleCallTerminated(intent)
}
ACTION_ONGOING_CALL_BG -> {
// there is an ongoing call but call activity is in background
displayCallOnGoingInBackground(intent)
}
else -> {
// Should not happen
callRingPlayerIncoming?.stop()
@ -278,26 +274,6 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
notificationManager.notify(callId.hashCode(), notification)
}
/**
* Display a call in progress notification.
*/
private fun displayCallOnGoingInBackground(intent: Intent) {
Timber.v("## VOIP displayCallInProgressNotification")
val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: return
val call = callManager.getCallById(callId) ?: return
if (!knownCalls.contains(callId)) {
Timber.v("Call in in background for unknown call $callId$")
return
}
val opponentMatrixItem = getOpponentMatrixItem(call)
val notification = notificationUtils.buildPendingCallNotification(
mxCall = call.mxCall,
title = opponentMatrixItem?.getBestName() ?: call.mxCall.opponentUserId,
fromBg = true)
notificationManager.notify(callId.hashCode(), notification)
}
fun addConnection(callConnection: CallConnection) {
connections[callConnection.callId] = callConnection
}
@ -313,7 +289,6 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
private const val ACTION_OUTGOING_RINGING_CALL = "im.vector.app.core.services.CallService.ACTION_OUTGOING_RINGING_CALL"
private const val ACTION_CALL_CONNECTING = "im.vector.app.core.services.CallService.ACTION_CALL_CONNECTING"
private const val ACTION_ONGOING_CALL = "im.vector.app.core.services.CallService.ACTION_ONGOING_CALL"
private const val ACTION_ONGOING_CALL_BG = "im.vector.app.core.services.CallService.ACTION_ONGOING_CALL_BG"
private const val ACTION_CALL_TERMINATED = "im.vector.app.core.services.CallService.ACTION_CALL_TERMINATED"
private const val ACTION_NO_ACTIVE_CALL = "im.vector.app.core.services.CallService.NO_ACTIVE_CALL"
// private const val ACTION_ACTIVITY_VISIBLE = "im.vector.app.core.services.CallService.ACTION_ACTIVITY_VISIBLE"
@ -334,16 +309,6 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
ContextCompat.startForegroundService(context, intent)
}
fun onOnGoingCallBackground(context: Context,
callId: String) {
val intent = Intent(context, CallService::class.java)
.apply {
action = ACTION_ONGOING_CALL_BG
putExtra(EXTRA_CALL_ID, callId)
}
ContextCompat.startForegroundService(context, intent)
}
fun onOutgoingCallRinging(context: Context,
callId: String) {

View File

@ -323,18 +323,6 @@ class WebRtcCall(val mxCall: MxCall,
remoteVideoTrack?.removeSink(it)
}
}
if (remoteSurfaceRenderers.isEmpty()) {
// The call is going to continue in background, so ensure notification is visible
mxCall
.takeIf { it.state is CallState.Connected }
?.let { mxCall ->
// Start background service with notification
CallService.onOnGoingCallBackground(
context = context,
callId = mxCall.callId
)
}
}
}
private suspend fun setupOutgoingCall() = withContext(dispatcher) {

View File

@ -1323,6 +1323,7 @@ class RoomDetailViewModel @AssistedInject constructor(
}
}
.subscribe {
Timber.v("Unread state: $it")
setState { copy(unreadState = it) }
}
.disposeOnClear()

View File

@ -393,9 +393,9 @@ class NotificationUtils @Inject constructor(private val context: Context,
*/
@SuppressLint("NewApi")
fun buildPendingCallNotification(mxCall: MxCall,
title: String,
fromBg: Boolean = false): Notification {
val builder = NotificationCompat.Builder(context, if (fromBg) CALL_NOTIFICATION_CHANNEL_ID else SILENT_NOTIFICATION_CHANNEL_ID)
title: String): Notification {
val builder = NotificationCompat.Builder(context, SILENT_NOTIFICATION_CHANNEL_ID)
.setContentTitle(ensureTitleNotEmpty(title))
.apply {
if (mxCall.isVideoCall) {
@ -407,11 +407,6 @@ class NotificationUtils @Inject constructor(private val context: Context,
.setSmallIcon(R.drawable.incoming_call_notification_transparent)
.setCategory(NotificationCompat.CATEGORY_CALL)
if (fromBg) {
builder.priority = NotificationCompat.PRIORITY_LOW
builder.setOngoing(true)
}
val rejectCallPendingIntent = buildRejectCallPendingIntent(mxCall.callId)
builder.addAction(

View File

@ -4,6 +4,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="4dp"
android:paddingBottom="4dp"
xmlns:tools="http://schemas.android.com/tools"
tools:style="@style/AlertStyle"
xmlns:app="http://schemas.android.com/apk/res-auto">