From a16086db6ff2a48e4b917f28c8859530f2b7056d Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 15 Dec 2020 18:44:59 +0100 Subject: [PATCH] VoIP: always use silent for pending call notification --- .../vector/app/core/services/CallService.kt | 35 ------------------- .../app/features/call/webrtc/WebRtcCall.kt | 12 ------- .../home/room/detail/RoomDetailViewModel.kt | 1 + .../notifications/NotificationUtils.kt | 11 ++---- .../layout/alerter_incoming_call_layout.xml | 2 ++ 5 files changed, 6 insertions(+), 55 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/services/CallService.kt b/vector/src/main/java/im/vector/app/core/services/CallService.kt index efdec1c251..0350971087 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallService.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallService.kt @@ -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) { diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt index f7cd148618..e6ebdaf572 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt @@ -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) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index ab4236489b..8dff6fe675 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -1323,6 +1323,7 @@ class RoomDetailViewModel @AssistedInject constructor( } } .subscribe { + Timber.v("Unread state: $it") setState { copy(unreadState = it) } } .disposeOnClear() diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index 2ec917c739..8850507c6a 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -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( diff --git a/vector/src/main/res/layout/alerter_incoming_call_layout.xml b/vector/src/main/res/layout/alerter_incoming_call_layout.xml index 6cbcfd10d7..a874e41743 100644 --- a/vector/src/main/res/layout/alerter_incoming_call_layout.xml +++ b/vector/src/main/res/layout/alerter_incoming_call_layout.xml @@ -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">