show 'incoming video cal' notification

This commit is contained in:
Daniel Gultsch 2020-04-15 18:28:04 +02:00
parent d4788fc1f4
commit 5a20faaf0f
4 changed files with 35 additions and 8 deletions

View file

@ -41,6 +41,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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.utils.UIHelper;
import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
import eu.siacs.conversations.xmpp.jingle.Media;
public class NotificationService { 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> media) {
final Intent fullScreenIntent = new Intent(mXmppConnectionService, RtpSessionActivity.class); final Intent fullScreenIntent = new Intent(mXmppConnectionService, RtpSessionActivity.class);
fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.account.getJid().asBareJid().toEscapedString()); fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.account.getJid().asBareJid().toEscapedString());
fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_WITH, id.with.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_NEW_TASK);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "incoming_calls"); final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "incoming_calls");
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.setSmallIcon(R.drawable.ic_call_white_24dp);
builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_call)); builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_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

@ -333,7 +333,11 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
private void updateStateDisplay(final RtpEndUserState state) { private void updateStateDisplay(final RtpEndUserState state) {
switch (state) { switch (state) {
case INCOMING_CALL: case INCOMING_CALL:
if (getMedia().contains(Media.VIDEO)) {
setTitle(R.string.rtp_state_incoming_video_call);
} else {
setTitle(R.string.rtp_state_incoming_call); setTitle(R.string.rtp_state_incoming_call);
}
break; break;
case CONNECTING: case CONNECTING:
setTitle(R.string.rtp_state_connecting); setTitle(R.string.rtp_state_connecting);
@ -369,6 +373,10 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
} }
private Set<Media> getMedia() {
return requireRtpConnection().getMedia();
}
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void updateButtonConfiguration(final RtpEndUserState state) { private void updateButtonConfiguration(final RtpEndUserState state) {
if (state == RtpEndUserState.INCOMING_CALL) { if (state == RtpEndUserState.INCOMING_CALL) {

View file

@ -278,7 +278,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
"proposed media must be set when processing pre-approved session-initiate" "proposed media must be set when processing pre-approved session-initiate"
); );
if (!this.proposedMedia.equals(contentMap.getMedia())) { 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", "Your session proposal (Jingle Message Initiation) included media %s but your session-initiate was %s",
this.proposedMedia, this.proposedMedia,
contentMap.getMedia() contentMap.getMedia()
@ -500,7 +500,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
if (originatedFromMyself) { if (originatedFromMyself) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": saw proposal from mysql. ignoring"); 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<RtpDescription> descriptions = Collections2.transform( final Collection<RtpDescription> descriptions = Collections2.transform(
Collections2.filter(propose.getDescriptions(), d -> d instanceof RtpDescription), Collections2.filter(propose.getDescriptions(), d -> d instanceof RtpDescription),
input -> (RtpDescription) input 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"); 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); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received session proposal from " + from + " for " + media);
this.proposedMedia = Sets.newHashSet(media); this.proposedMedia = Sets.newHashSet(media);
transitionOrThrow(State.PROPOSED);
if (serverMsgId != null) { if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId); this.message.setServerMsgId(serverMsgId);
} }
@ -521,7 +522,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private void startRinging() { private void startRinging() {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received call from " + id.with + ". start ringing"); 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) { 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); writeLogMessage(target);
final JinglePacket jinglePacket = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId); final JinglePacket jinglePacket = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId);
jinglePacket.setReason(reason, text); jinglePacket.setReason(reason, text);
Log.d(Config.LOGTAG,jinglePacket.toString()); Log.d(Config.LOGTAG, jinglePacket.toString());
send(jinglePacket); send(jinglePacket);
jingleConnectionManager.finishConnection(this); 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)); throw new IllegalStateException(String.format("%s has no equivalent EndUserState", this.state));
} }
public Set<Media> 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() { public synchronized void acceptCall() {
switch (this.state) { switch (this.state) {

View file

@ -889,6 +889,7 @@
<string name="please_enable_an_account">Please enable an account</string> <string name="please_enable_an_account">Please enable an account</string>
<string name="make_call">Make call</string> <string name="make_call">Make call</string>
<string name="rtp_state_incoming_call">Incoming call</string> <string name="rtp_state_incoming_call">Incoming call</string>
<string name="rtp_state_incoming_video_call">Incoming video call</string>
<string name="rtp_state_connecting">Connecting</string> <string name="rtp_state_connecting">Connecting</string>
<string name="rtp_state_connected">Connected</string> <string name="rtp_state_connected">Connected</string>
<string name="rtp_state_accepting_call">Accepting call</string> <string name="rtp_state_accepting_call">Accepting call</string>