From a44ad6015dd60d255cd7a5a1000a7483d11769ea Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 14 Jan 2024 18:05:43 +0100 Subject: [PATCH] update UI with correct state after UI gets invoked with ACTION_VIEW --- .../services/CallIntegrationConnectionService.java | 13 +++++++++++-- .../siacs/conversations/ui/RtpSessionActivity.java | 8 ++++---- .../xmpp/jingle/JingleConnectionManager.java | 13 ++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java index cfd6ae603..28f59a060 100644 --- a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java @@ -29,6 +29,7 @@ import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection; import eu.siacs.conversations.xmpp.jingle.Media; +import eu.siacs.conversations.xmpp.jingle.RtpEndUserState; import java.util.Collection; import java.util.Collections; @@ -83,6 +84,7 @@ public class CallIntegrationConnectionService extends ConnectionService { } final Account account = service.findAccountByUuid(phoneAccountHandle.getId()); final Intent intent = new Intent(this, RtpSessionActivity.class); + intent.setAction(Intent.ACTION_VIEW); intent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, account.getJid().toEscapedString()); intent.putExtra(RtpSessionActivity.EXTRA_WITH, jid.toEscapedString()); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -93,10 +95,17 @@ public class CallIntegrationConnectionService extends ConnectionService { service.getJingleConnectionManager() .proposeJingleRtpSession(account, jid, media); + intent.putExtra( + RtpSessionActivity.EXTRA_LAST_REPORTED_STATE, + RtpEndUserState.FINDING_DEVICE.toString()); if (Media.audioOnly(media)) { - intent.setAction(RtpSessionActivity.ACTION_MAKE_VOICE_CALL); + intent.putExtra( + RtpSessionActivity.EXTRA_LAST_ACTION, + RtpSessionActivity.ACTION_MAKE_VOICE_CALL); } else { - intent.setAction(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL); + intent.putExtra( + RtpSessionActivity.EXTRA_LAST_ACTION, + RtpSessionActivity.ACTION_MAKE_VIDEO_CALL); } callIntegration = proposal.getCallIntegration(); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 8f546918a..598232467 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -467,8 +467,7 @@ public class RtpSessionActivity extends XmppActivity } } - private void putProximityWakeLockInProperState( - final CallIntegration.AudioDevice audioDevice) { + private void putProximityWakeLockInProperState(final CallIntegration.AudioDevice audioDevice) { if (audioDevice == CallIntegration.AudioDevice.EARPIECE) { acquireProximityWakeLock(); } else { @@ -583,7 +582,8 @@ public class RtpSessionActivity extends XmppActivity .getJingleConnectionManager() .proposeJingleRtpSession(account, with, media); } else { - throw new IllegalStateException("We should not be initializing direct calls from the RtpSessionActivity. Go through CallIntegrationConnectionService.placeCall instead!"); + throw new IllegalStateException( + "We should not be initializing direct calls from the RtpSessionActivity. Go through CallIntegrationConnectionService.placeCall instead!"); } putScreenInCallMode(media); } @@ -1312,7 +1312,7 @@ public class RtpSessionActivity extends XmppActivity final Set media = actionToMedia(lastAction == null ? action : lastAction); this.rtpConnectionReference = null; Log.d(Config.LOGTAG, "attempting retry with " + with.toEscapedString()); - CallIntegrationConnectionService.placeCall(this,account,with,media); + CallIntegrationConnectionService.placeCall(this, account, with, media); } private void exit(final View view) { 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 5edd461fb..5a5117a4c 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -636,17 +636,16 @@ public class JingleConnectionManager extends AbstractConnectionManager { } public boolean fireJingleRtpConnectionStateUpdates() { - boolean firedUpdates = false; for (final AbstractJingleConnection connection : this.connections.values()) { if (connection instanceof JingleRtpConnection jingleRtpConnection) { if (jingleRtpConnection.isTerminated()) { continue; } jingleRtpConnection.fireStateUpdate(); - firedUpdates = true; + return true; } } - return firedUpdates; + return false; } public void retractSessionProposal(final Account account, final Jid with) { @@ -745,8 +744,16 @@ public class JingleConnectionManager extends AbstractConnectionManager { synchronized (this.rtpSessionProposals) { for (Map.Entry entry : this.rtpSessionProposals.entrySet()) { + final var state = entry.getValue(); final RtpSessionProposal proposal = entry.getKey(); if (proposal.account == account && with.asBareJid().equals(proposal.with)) { + // CallIntegrationConnectionService starts RtpSessionActivity with ACTION_VIEW + // and an EXTRA_LAST_REPORTED_STATE of DISCOVERING devices. however due to + // possible race conditions the state might have already moved on so we are going + // to update the UI + final RtpEndUserState endUserState = state.toEndUserState(); + mXmppConnectionService.notifyJingleRtpConnectionUpdate( + account, proposal.with, proposal.sessionId, endUserState); return true; } }