From e0cb127005fac54904350f2359b573fc80a85f11 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 21 Apr 2020 22:46:46 +0200 Subject: [PATCH] retract call when pressing home or power button during ringing --- .../conversations/ui/RtpSessionActivity.java | 20 ++++++++++++++----- .../xmpp/jingle/JingleConnectionManager.java | 2 +- .../xmpp/jingle/RtpEndUserState.java | 1 + src/main/res/values/strings.xml | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index f85ad3f4e..0b671453a 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -95,16 +95,21 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe private void endCall() { if (this.rtpConnectionReference == null) { - final Intent intent = getIntent(); - final Account account = extractAccount(intent); - final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH)); - xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid()); + retractSessionProposal(); finish(); } else { requireRtpConnection().endCall(); } } + private void retractSessionProposal() { + final Intent intent = getIntent(); + final Account account = extractAccount(intent); + final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH)); + resetIntent(account, with, RtpEndUserState.RETRACTED, actionToMedia(intent.getAction())); + xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid()); + } + private void rejectCall(View view) { requireRtpConnection().rejectCall(); finish(); @@ -290,6 +295,8 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe final JingleRtpConnection jingleRtpConnection = weakReference == null ? null : weakReference.get(); if (jingleRtpConnection != null) { releaseVideoTracks(jingleRtpConnection); + } else if (!isChangingConfigurations()) { + retractSessionProposal(); } releaseProximityWakeLock(); super.onStop(); @@ -420,6 +427,9 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe case CONNECTIVITY_ERROR: setTitle(R.string.rtp_state_connectivity_error); break; + case RETRACTED: + setTitle(R.string.rtp_state_retracted); + break; case APPLICATION_ERROR: setTitle(R.string.rtp_state_application_failure); break; @@ -468,7 +478,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe this.binding.endCall.setImageResource(R.drawable.ic_clear_white_48dp); this.binding.endCall.setVisibility(View.VISIBLE); this.binding.acceptCall.setVisibility(View.INVISIBLE); - } else if (state == RtpEndUserState.CONNECTIVITY_ERROR || state == RtpEndUserState.APPLICATION_ERROR) { + } else if (asList(RtpEndUserState.CONNECTIVITY_ERROR, RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.RETRACTED).contains(state)) { this.binding.rejectCall.setOnClickListener(this::exit); this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp); this.binding.rejectCall.setVisibility(View.VISIBLE); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index b25647854..07d6a25cb 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -402,11 +402,11 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } if (matchingProposal != null) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retracting rtp session proposal with " + with); this.rtpSessionProposals.remove(matchingProposal); final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionRetract(matchingProposal); writeLogMissedOutgoing(account, matchingProposal.with, matchingProposal.sessionId, null, System.currentTimeMillis()); mXmppConnectionService.sendMessagePacket(account, messagePacket); - } } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpEndUserState.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpEndUserState.java index 4baa0019d..398777cfe 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpEndUserState.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/RtpEndUserState.java @@ -11,5 +11,6 @@ public enum RtpEndUserState { ENDED, //close UI DECLINED_OR_BUSY, //other party declined; no retry button CONNECTIVITY_ERROR, //network error; retry button + RETRACTED, //user pressed home or power button during 'ringing' - shows retry button APPLICATION_ERROR //something rather bad happened; libwebrtc failed or we got in IQ-error } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 32ade6387..48ca72cea 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -904,6 +904,7 @@ Ringing Busy Unable to connect call + Retracted call Application failure Hang up Ongoing call