From 5a20faaf0f74854a700a4bb11277a35f6d7efa4c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 15 Apr 2020 18:28:04 +0200 Subject: [PATCH] show 'incoming video cal' notification --- .../services/NotificationService.java | 13 ++++++++++--- .../conversations/ui/RtpSessionActivity.java | 10 +++++++++- .../xmpp/jingle/JingleRtpConnection.java | 19 +++++++++++++++---- src/main/res/values/strings.xml | 1 + 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index c2665ea8b..cbd11f1d7 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -41,6 +41,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,6 +64,7 @@ import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; +import eu.siacs.conversations.xmpp.jingle.Media; public class NotificationService { @@ -334,7 +336,7 @@ public class NotificationService { } } - public void showIncomingCallNotification(AbstractJingleConnection.Id id) { + public void showIncomingCallNotification(final AbstractJingleConnection.Id id, final Set media) { final Intent fullScreenIntent = new Intent(mXmppConnectionService, RtpSessionActivity.class); fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.account.getJid().asBareJid().toEscapedString()); fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_WITH, id.with.toEscapedString()); @@ -342,8 +344,13 @@ public class NotificationService { fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "incoming_calls"); - builder.setSmallIcon(R.drawable.ic_call_white_24dp); - builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_call)); + if (media.contains(Media.VIDEO)) { + builder.setSmallIcon(R.drawable.ic_videocam_white_24dp); + builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_video_call)); + } else { + builder.setSmallIcon(R.drawable.ic_call_white_24dp); + builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_call)); + } builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName()); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); builder.setPriority(NotificationCompat.PRIORITY_HIGH); diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 22692f86b..33d17315d 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -333,7 +333,11 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe private void updateStateDisplay(final RtpEndUserState state) { switch (state) { case INCOMING_CALL: - setTitle(R.string.rtp_state_incoming_call); + if (getMedia().contains(Media.VIDEO)) { + setTitle(R.string.rtp_state_incoming_video_call); + } else { + setTitle(R.string.rtp_state_incoming_call); + } break; case CONNECTING: setTitle(R.string.rtp_state_connecting); @@ -369,6 +373,10 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } } + private Set getMedia() { + return requireRtpConnection().getMedia(); + } + @SuppressLint("RestrictedApi") private void updateButtonConfiguration(final RtpEndUserState state) { if (state == RtpEndUserState.INCOMING_CALL) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index e4ef46b60..b762ab7ec 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -278,7 +278,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web "proposed media must be set when processing pre-approved session-initiate" ); if (!this.proposedMedia.equals(contentMap.getMedia())) { - sendSessionTerminate(Reason.SECURITY_ERROR,String.format( + sendSessionTerminate(Reason.SECURITY_ERROR, String.format( "Your session proposal (Jingle Message Initiation) included media %s but your session-initiate was %s", this.proposedMedia, contentMap.getMedia() @@ -500,7 +500,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); if (originatedFromMyself) { Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": saw proposal from mysql. ignoring"); - } else if (transition(State.PROPOSED)) { + } else if (isInState(State.NULL)) { final Collection descriptions = Collections2.transform( Collections2.filter(propose.getDescriptions(), d -> d instanceof RtpDescription), input -> (RtpDescription) input @@ -509,6 +509,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web Preconditions.checkState(!media.contains(Media.UNKNOWN), "RTP descriptions contain unknown media"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received session proposal from " + from + " for " + media); this.proposedMedia = Sets.newHashSet(media); + transitionOrThrow(State.PROPOSED); if (serverMsgId != null) { this.message.setServerMsgId(serverMsgId); } @@ -521,7 +522,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private void startRinging() { Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received call from " + id.with + ". start ringing"); - xmppConnectionService.getNotificationService().showIncomingCallNotification(id); + xmppConnectionService.getNotificationService().showIncomingCallNotification(id, getMedia()); } private void receiveProceed(final Jid from, final String serverMsgId, final long timestamp) { @@ -623,7 +624,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web writeLogMessage(target); final JinglePacket jinglePacket = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId); jinglePacket.setReason(reason, text); - Log.d(Config.LOGTAG,jinglePacket.toString()); + Log.d(Config.LOGTAG, jinglePacket.toString()); send(jinglePacket); jingleConnectionManager.finishConnection(this); } @@ -744,6 +745,16 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web throw new IllegalStateException(String.format("%s has no equivalent EndUserState", this.state)); } + public Set getMedia() { + if (isInState(State.NULL)) { + throw new IllegalStateException("RTP connection has not been initialized yet"); + } + if (isInState(State.PROPOSED, State.PROCEED)) { + return Preconditions.checkNotNull(this.proposedMedia, "RTP connection has not been initialized properly"); + } + return Preconditions.checkNotNull(initiatorRtpContentMap.getMedia()); + } + public synchronized void acceptCall() { switch (this.state) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 854dfa3c6..bcb757cac 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -889,6 +889,7 @@ Please enable an account Make call Incoming call + Incoming video call Connecting Connected Accepting call