Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBE-2772] Support multiple call notifications in CallService #1088

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4085,7 +4085,7 @@ public class io/getstream/video/android/core/notifications/DefaultNotificationHa
public final fun getHideRingingNotificationInForeground ()Z
public final fun getNotificationIconRes ()I
public fun getOngoingCallNotification (Ljava/lang/String;Lio/getstream/video/android/model/StreamCallId;)Landroid/app/Notification;
public fun getRingingCallNotification (Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)Landroid/app/Notification;
public fun getRingingCallNotification (Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;Z)Landroid/app/Notification;
public fun onLiveCall (Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)V
public fun onNotification (Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)V
public fun onPermissionDenied ()V
Expand Down Expand Up @@ -4132,7 +4132,8 @@ public abstract interface class io/getstream/video/android/core/notifications/No
public static final field INTENT_EXTRA_CALL_DISPLAY_NAME Ljava/lang/String;
public static final field INTENT_EXTRA_NOTIFICATION_ID Ljava/lang/String;
public abstract fun getOngoingCallNotification (Ljava/lang/String;Lio/getstream/video/android/model/StreamCallId;)Landroid/app/Notification;
public abstract fun getRingingCallNotification (Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)Landroid/app/Notification;
public abstract fun getRingingCallNotification (Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;Z)Landroid/app/Notification;
public static synthetic fun getRingingCallNotification$default (Lio/getstream/video/android/core/notifications/NotificationHandler;Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;ZILjava/lang/Object;)Landroid/app/Notification;
public abstract fun onLiveCall (Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)V
public abstract fun onNotification (Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)V
public abstract fun onRingingCall (Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.annotation.DrawableRes
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.CallStyle
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.Person
import androidx.core.content.ContextCompat
import io.getstream.android.push.permissions.DefaultNotificationPermissionHandler
import io.getstream.android.push.permissions.NotificationPermissionHandler
import io.getstream.log.TaggedLogger
Expand Down Expand Up @@ -85,19 +86,15 @@ public open class DefaultNotificationHandler(
}

override fun onRingingCall(callId: StreamCallId, callDisplayName: String) {
val serviceIntent = CallService.buildStartIntent(
this.application,
callId,
CallService.TRIGGER_INCOMING_CALL,
callDisplayName,
)
ContextCompat.startForegroundService(application.applicationContext, serviceIntent)
Log.d("ServiceDebug", "[onRingingCall] callId: ${callId.id}")
CallService.showIncomingCall(application, callId, callDisplayName)
}

override fun getRingingCallNotification(
ringingState: RingingState,
callId: StreamCallId,
callDisplayName: String,
shouldHaveContentIntent: Boolean,
): Notification? {
return if (ringingState is RingingState.Incoming) {
val fullScreenPendingIntent = intentResolver.searchIncomingCallPendingIntent(callId)
Expand All @@ -110,6 +107,7 @@ public open class DefaultNotificationHandler(
acceptCallPendingIntent,
rejectCallPendingIntent,
callDisplayName,
shouldHaveContentIntent,
)
} else {
logger.e { "Ringing call notification not shown, one of the intents is null." }
Expand Down Expand Up @@ -139,6 +137,7 @@ public open class DefaultNotificationHandler(
acceptCallPendingIntent: PendingIntent,
rejectCallPendingIntent: PendingIntent,
callDisplayName: String,
shouldHaveContentIntent: Boolean,
): Notification {
// if the app is in foreground then don't interrupt the user with a high priority
// notification (popup). The application will display an incoming ringing call
Expand Down Expand Up @@ -182,9 +181,20 @@ public open class DefaultNotificationHandler(
setContentText(callDisplayName)
setChannelId(channelId)
setOngoing(false)
setContentIntent(fullScreenPendingIntent)
setFullScreenIntent(fullScreenPendingIntent, true)
setCategory(NotificationCompat.CATEGORY_CALL)
setFullScreenIntent(fullScreenPendingIntent, true)
if (shouldHaveContentIntent) {
setContentIntent(fullScreenPendingIntent)
} else {
val emptyIntent = PendingIntent.getActivity(
application,
0,
Intent(),
PendingIntent.FLAG_IMMUTABLE,
)
setContentIntent(emptyIntent)
setAutoCancel(false)
}
addCallActions(acceptCallPendingIntent, rejectCallPendingIntent, callDisplayName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface NotificationHandler : NotificationPermissionHandler {
ringingState: RingingState,
callId: StreamCallId,
callDisplayName: String,
shouldHaveContentIntent: Boolean = true,
): Notification?

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal object NoOpNotificationHandler : NotificationHandler {
ringingState: RingingState,
callId: StreamCallId,
callDisplayName: String,
shouldHaveContentIntent: Boolean,
): Notification? = null

override fun onPermissionDenied() { /* NoOp */ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package io.getstream.video.android.core.notifications.internal.receivers

import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationManagerCompat
import android.util.Log
import io.getstream.log.taggedLogger
import io.getstream.result.Result
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.notifications.NotificationHandler
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_REJECT_CALL
import io.getstream.video.android.core.notifications.internal.service.CallService
import io.getstream.video.android.model.StreamCallId

/**
* Used to process any pending intents that feature the [ACTION_REJECT_CALL] action. By consuming this
Expand All @@ -41,12 +41,7 @@ internal class RejectCallBroadcastReceiver : GenericCallActionBroadcastReceiver(
is Result.Success -> logger.d { "[onReceive] rejectCall, Success: $rejectResult" }
is Result.Failure -> logger.d { "[onReceive] rejectCall, Failure: $rejectResult" }
}
val serviceIntent = CallService.buildStopIntent(context)
context.stopService(serviceIntent)

// As a second precaution cancel also the notification
NotificationManagerCompat.from(
context,
).cancel(NotificationHandler.INCOMING_CALL_NOTIFICATION_ID)
Log.d("ServiceDebug", "[reject onReceive] callId: ${call.id}")
CallService.removeIncomingCall(context, StreamCallId.fromCallCid(call.cid))
}
}
Loading
Loading