Display caller avatar when showing CallStyle notification.

This commit is contained in:
Alex Hart 2023-04-21 14:34:47 -03:00 committed by GitHub
parent f14bce9849
commit 211d79d14d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 19 deletions

View file

@ -35,6 +35,8 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.disposables.Disposable;
/**
* Provide a foreground service for {@link SignalCallManager} to leverage to run in the background when necessary. Also
* provides devices listeners needed for during a call (i.e., bluetooth, power button).
@ -71,7 +73,8 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
private SignalAudioManager signalAudioManager;
private int lastNotificationId;
private Notification lastNotification;
private boolean isGroup = true;
private boolean isGroup = true;
private Disposable notificationDisposable = Disposable.empty();
public static void update(@NonNull Context context, int type, @NonNull RecipientId recipientId) {
Intent intent = new Intent(context, WebRtcCallService.class);
@ -145,6 +148,8 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
Log.v(TAG, "onDestroy");
super.onDestroy();
notificationDisposable.dispose();
if (uncaughtExceptionHandlerManager != null) {
uncaughtExceptionHandlerManager.unregister();
}
@ -226,10 +231,14 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
}
public void setCallInProgressNotification(int type, @NonNull RecipientId id) {
lastNotificationId = CallNotificationBuilder.getNotificationId(type);
lastNotification = CallNotificationBuilder.getCallInProgressNotification(this, type, Recipient.resolved(id));
notificationDisposable.dispose();
notificationDisposable = CallNotificationBuilder.getCallInProgressNotification(this, type, Recipient.resolved(id))
.subscribe(notification -> {
lastNotificationId = CallNotificationBuilder.getNotificationId(type);
lastNotification = notification;
startForegroundCompat(lastNotificationId, lastNotification);
startForegroundCompat(lastNotificationId, lastNotification);
});
}
private void startForegroundCompat(int notificationId, Notification notification) {

View file

@ -10,15 +10,19 @@ import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import org.signal.core.util.PendingIntentFlags;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.MainActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.WebRtcCallActivity;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.webrtc.WebRtcCallService;
import org.thoughtcrime.securesms.util.ConversationUtil;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
/**
* Manages the state of the WebRtc items in the Android notification bar.
*
@ -46,7 +50,7 @@ public class CallNotificationBuilder {
*/
public static final int API_LEVEL_CALL_STYLE = 29;
public static Notification getCallInProgressNotification(Context context, int type, Recipient recipient) {
public static Single<Notification> getCallInProgressNotification(Context context, int type, Recipient recipient) {
Intent contentIntent = new Intent(context, WebRtcCallActivity.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
contentIntent.putExtra(WebRtcCallActivity.EXTRA_STARTED_FROM_FULLSCREEN, true);
@ -63,32 +67,46 @@ public class CallNotificationBuilder {
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting));
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setContentIntent(null);
return Single.just(builder.build());
} else if (type == TYPE_INCOMING_RINGING) {
builder.setContentText(context.getString(recipient.isGroup() ? R.string.NotificationBarManager__incoming_signal_group_call : R.string.NotificationBarManager__incoming_signal_call));
builder.setStyle(NotificationCompat.CallStyle.forIncomingCall(
ConversationUtil.buildPersonWithoutIcon(context, recipient),
getServicePendingIntent(context, WebRtcCallService.denyCallIntent(context)),
getActivityPendingIntent(context, WebRtcCallActivity.ANSWER_ACTION)
));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
return Single.fromCallable(() -> ConversationUtil.buildPerson(context, recipient))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(person -> {
builder.setStyle(NotificationCompat.CallStyle.forIncomingCall(
person,
getServicePendingIntent(context, WebRtcCallService.denyCallIntent(context)),
getActivityPendingIntent(context, WebRtcCallActivity.ANSWER_ACTION)
));
return builder.build();
});
} else if (type == TYPE_OUTGOING_RINGING) {
builder.setContentText(context.getString(R.string.NotificationBarManager__establishing_signal_call));
builder.addAction(getServiceNotificationAction(context, WebRtcCallService.hangupIntent(context), R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__cancel_call));
return Single.just(builder.build());
} else {
builder.setContentText(context.getString(R.string.NotificationBarManager_signal_call_in_progress));
builder.setOnlyAlertOnce(true);
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(
ConversationUtil.buildPersonWithoutIcon(context, recipient),
getServicePendingIntent(context, WebRtcCallService.hangupIntent(context))
));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
}
return builder.build();
return Single.fromCallable(() -> ConversationUtil.buildPerson(context, recipient))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(person -> {
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(
person,
getServicePendingIntent(context, WebRtcCallService.hangupIntent(context))
));
return builder.build();
});
}
}
public static int getNotificationId(int type) {