indicate call reconnect in notification

This commit is contained in:
Daniel Gultsch 2021-11-19 12:26:11 +01:00
parent f8a94161db
commit db834a1f07
4 changed files with 36 additions and 15 deletions

View File

@ -488,15 +488,24 @@ public class NotificationService {
notify(INCOMING_CALL_NOTIFICATION_ID, notification); notify(INCOMING_CALL_NOTIFICATION_ID, notification);
} }
public Notification getOngoingCallNotification(final AbstractJingleConnection.Id id, final Set<Media> media) { public Notification getOngoingCallNotification(final XmppConnectionService.OngoingCall ongoingCall) {
final AbstractJingleConnection.Id id = ongoingCall.id;
final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "ongoing_calls"); final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "ongoing_calls");
if (media.contains(Media.VIDEO)) { if (ongoingCall.media.contains(Media.VIDEO)) {
builder.setSmallIcon(R.drawable.ic_videocam_white_24dp); builder.setSmallIcon(R.drawable.ic_videocam_white_24dp);
if (ongoingCall.reconnecting) {
builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_video_call));
} else {
builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call)); builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call));
}
} else { } else {
builder.setSmallIcon(R.drawable.ic_call_white_24dp); builder.setSmallIcon(R.drawable.ic_call_white_24dp);
if (ongoingCall.reconnecting) {
builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_call));
} else {
builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call)); builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call));
} }
}
builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName()); builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName());
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setPriority(NotificationCompat.PRIORITY_HIGH);

View File

@ -1298,8 +1298,8 @@ public class XmppConnectionService extends Service {
toggleForegroundService(false); toggleForegroundService(false);
} }
public void setOngoingCall(AbstractJingleConnection.Id id, Set<Media> media) { public void setOngoingCall(AbstractJingleConnection.Id id, Set<Media> media, final boolean reconnecting) {
ongoingCall.set(new OngoingCall(id, media)); ongoingCall.set(new OngoingCall(id, media, reconnecting));
toggleForegroundService(false); toggleForegroundService(false);
} }
@ -1315,7 +1315,7 @@ public class XmppConnectionService extends Service {
final Notification notification; final Notification notification;
final int id; final int id;
if (ongoing != null) { if (ongoing != null) {
notification = this.mNotificationService.getOngoingCallNotification(ongoing.id, ongoing.media); notification = this.mNotificationService.getOngoingCallNotification(ongoing);
id = NotificationService.ONGOING_CALL_NOTIFICATION_ID; id = NotificationService.ONGOING_CALL_NOTIFICATION_ID;
startForeground(id, notification); startForeground(id, notification);
mNotificationService.cancel(NotificationService.FOREGROUND_NOTIFICATION_ID); mNotificationService.cancel(NotificationService.FOREGROUND_NOTIFICATION_ID);
@ -4869,12 +4869,14 @@ public class XmppConnectionService extends Service {
} }
public static class OngoingCall { public static class OngoingCall {
private final AbstractJingleConnection.Id id; public final AbstractJingleConnection.Id id;
private final Set<Media> media; public final Set<Media> media;
public final boolean reconnecting;
public OngoingCall(AbstractJingleConnection.Id id, Set<Media> media) { public OngoingCall(AbstractJingleConnection.Id id, Set<Media> media, final boolean reconnecting) {
this.id = id; this.id = id;
this.media = media; this.media = media;
this.reconnecting = reconnecting;
} }
@Override @Override
@ -4882,12 +4884,12 @@ public class XmppConnectionService extends Service {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
OngoingCall that = (OngoingCall) o; OngoingCall that = (OngoingCall) o;
return Objects.equal(id, that.id); return reconnecting == that.reconnecting && Objects.equal(id, that.id) && Objects.equal(media, that.media);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(id); return Objects.hashCode(id, media, reconnecting);
} }
} }
} }

View File

@ -1484,8 +1484,10 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
this.stateHistory.add(newState); this.stateHistory.add(newState);
if (newState == PeerConnection.PeerConnectionState.CONNECTED) { if (newState == PeerConnection.PeerConnectionState.CONNECTED) {
this.sessionDuration.start(); this.sessionDuration.start();
updateOngoingCallNotification();
} else if (this.sessionDuration.isRunning()) { } else if (this.sessionDuration.isRunning()) {
this.sessionDuration.stop(); this.sessionDuration.stop();
updateOngoingCallNotification();
} }
final boolean neverConnected = !this.stateHistory.contains(PeerConnection.PeerConnectionState.CONNECTED); final boolean neverConnected = !this.stateHistory.contains(PeerConnection.PeerConnectionState.CONNECTED);
@ -1633,8 +1635,15 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
private void updateOngoingCallNotification() { private void updateOngoingCallNotification() {
if (STATES_SHOWING_ONGOING_CALL.contains(this.state)) { final State state = this.state;
xmppConnectionService.setOngoingCall(id, getMedia()); if (STATES_SHOWING_ONGOING_CALL.contains(state)) {
final boolean reconnecting;
if (state == State.SESSION_ACCEPTED) {
reconnecting = getPeerConnectionStateAsEndUserState() == RtpEndUserState.RECONNECTING;
} else {
reconnecting = false;
}
xmppConnectionService.setOngoingCall(id, getMedia(), reconnecting);
} else { } else {
xmppConnectionService.removeOngoingCall(); xmppConnectionService.removeOngoingCall();
} }
@ -1758,7 +1767,6 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
return webRTCWrapper.getRemoteVideoTrack(); return webRTCWrapper.getRemoteVideoTrack();
} }
public EglBase.Context getEglBaseContext() { public EglBase.Context getEglBaseContext() {
return webRTCWrapper.getEglBaseContext(); return webRTCWrapper.getEglBaseContext();
} }

View File

@ -920,6 +920,8 @@
<string name="hang_up">Hang up</string> <string name="hang_up">Hang up</string>
<string name="ongoing_call">Ongoing call</string> <string name="ongoing_call">Ongoing call</string>
<string name="ongoing_video_call">Ongoing video call</string> <string name="ongoing_video_call">Ongoing video call</string>
<string name="reconnecting_call">Reconnecting call</string>
<string name="reconnecting_video_call">Reconnecting video call</string>
<string name="disable_tor_to_make_call">Disable Tor to make calls</string> <string name="disable_tor_to_make_call">Disable Tor to make calls</string>
<string name="incoming_call">Incoming call</string> <string name="incoming_call">Incoming call</string>
<string name="incoming_call_duration">Incoming call · %s</string> <string name="incoming_call_duration">Incoming call · %s</string>