From 619af9c6c5ac871a1863865a9f566df565953410 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2021 18:42:34 +0100 Subject: [PATCH] back button should not end call if call is connected. fixes #3975 --- .../ui/ConversationsActivity.java | 1 + .../conversations/ui/RtpSessionActivity.java | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index 7f33ef05f..61a8a586e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -537,6 +537,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio @Override protected void onNewIntent(final Intent intent) { + super.onNewIntent(intent); if (isViewOrShareIntent(intent)) { if (xmppConnectionService != null) { clearPendingViewIntent(); diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 6a2d19f44..dbb8763fb 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -458,18 +458,21 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe @Override public void onBackPressed() { + if (isConnected()) { + if (switchToPictureInPicture()) { + return; + } + } else { + endCall(); + } super.onBackPressed(); - endCall(); } @Override public void onUserLeaveHint() { super.onUserLeaveHint(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) { - if (shouldBePictureInPicture()) { - startPictureInPicture(); - return; - } + if (switchToPictureInPicture()) { + return; } //TODO apparently this method is not getting called on Android 10 when using the task switcher final boolean emptyReference = rtpConnectionReference == null || rtpConnectionReference.get() == null; @@ -478,6 +481,21 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } } + private boolean isConnected() { + final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null; + return connection != null && connection.getEndUserState() == RtpEndUserState.CONNECTED; + } + + private boolean switchToPictureInPicture() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) { + if (shouldBePictureInPicture()) { + startPictureInPicture(); + return true; + } + } + return false; + } + @RequiresApi(api = Build.VERSION_CODES.O) private void startPictureInPicture() { try {