indicate call reconnect in notification

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/services/NotificationService.java    | 17 
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java  | 18 
src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java | 14 
src/main/res/values/strings.xml                                           |  2 
4 files changed, 36 insertions(+), 15 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/services/NotificationService.java ๐Ÿ”—

@@ -488,14 +488,23 @@ public class NotificationService {
         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");
-        if (media.contains(Media.VIDEO)) {
+        if (ongoingCall.media.contains(Media.VIDEO)) {
             builder.setSmallIcon(R.drawable.ic_videocam_white_24dp);
-            builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call));
+            if (ongoingCall.reconnecting) {
+                builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_video_call));
+            } else {
+                builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call));
+            }
         } else {
             builder.setSmallIcon(R.drawable.ic_call_white_24dp);
-            builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call));
+            if (ongoingCall.reconnecting) {
+                builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_call));
+            } else {
+                builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call));
+            }
         }
         builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName());
         builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java ๐Ÿ”—

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

src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java ๐Ÿ”—

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

src/main/res/values/strings.xml ๐Ÿ”—

@@ -920,6 +920,8 @@
     <string name="hang_up">Hang up</string>
     <string name="ongoing_call">Ongoing 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="incoming_call">Incoming call</string>
     <string name="incoming_call_duration">Incoming call ยท %s</string>