update UI with correct state after UI gets invoked with ACTION_VIEW

This commit is contained in:
Daniel Gultsch 2024-01-14 18:05:43 +01:00
parent d20cc87bda
commit a44ad6015d
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 25 additions and 9 deletions

View file

@ -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 {

View file

@ -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> 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) {

View file

@ -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<RtpSessionProposal, DeviceDiscoveryState> 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;
}
}