make RtpSessionActivity onNewIntent and onBackendConnected run through the same code
This commit is contained in:
parent
a619cfe0d8
commit
b90906b973
|
@ -127,6 +127,7 @@ import eu.siacs.conversations.xmpp.jingle.JingleFileTransferConnection;
|
||||||
import eu.siacs.conversations.xmpp.jingle.Media;
|
import eu.siacs.conversations.xmpp.jingle.Media;
|
||||||
import eu.siacs.conversations.xmpp.jingle.OngoingRtpSession;
|
import eu.siacs.conversations.xmpp.jingle.OngoingRtpSession;
|
||||||
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
|
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
|
||||||
|
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -1556,20 +1557,25 @@ public class ConversationFragment extends XmppFragment
|
||||||
if (ongoingRtpSession.isPresent()) {
|
if (ongoingRtpSession.isPresent()) {
|
||||||
final OngoingRtpSession id = ongoingRtpSession.get();
|
final OngoingRtpSession id = ongoingRtpSession.get();
|
||||||
final Intent intent = new Intent(getActivity(), RtpSessionActivity.class);
|
final Intent intent = new Intent(getActivity(), RtpSessionActivity.class);
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
intent.putExtra(
|
intent.putExtra(
|
||||||
RtpSessionActivity.EXTRA_ACCOUNT,
|
RtpSessionActivity.EXTRA_ACCOUNT,
|
||||||
id.getAccount().getJid().asBareJid().toEscapedString());
|
id.getAccount().getJid().asBareJid().toEscapedString());
|
||||||
intent.putExtra(RtpSessionActivity.EXTRA_WITH, id.getWith().toEscapedString());
|
intent.putExtra(RtpSessionActivity.EXTRA_WITH, id.getWith().toEscapedString());
|
||||||
if (id instanceof AbstractJingleConnection) {
|
if (id instanceof AbstractJingleConnection) {
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
|
||||||
intent.putExtra(RtpSessionActivity.EXTRA_SESSION_ID, id.getSessionId());
|
intent.putExtra(RtpSessionActivity.EXTRA_SESSION_ID, id.getSessionId());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else if (id instanceof JingleConnectionManager.RtpSessionProposal proposal) {
|
} else if (id instanceof JingleConnectionManager.RtpSessionProposal proposal) {
|
||||||
if (proposal.media.contains(Media.VIDEO)) {
|
if (Media.audioOnly(proposal.media)) {
|
||||||
intent.setAction(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
intent.putExtra(
|
||||||
|
RtpSessionActivity.EXTRA_LAST_ACTION,
|
||||||
|
RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
||||||
} else {
|
} else {
|
||||||
intent.setAction(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
intent.putExtra(
|
||||||
|
RtpSessionActivity.EXTRA_LAST_ACTION,
|
||||||
|
RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
||||||
}
|
}
|
||||||
|
intent.putExtra(RtpSessionActivity.EXTRA_PROPOSED_SESSION_ID, proposal.sessionId);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -460,6 +460,9 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
public void onNewIntent(final Intent intent) {
|
public void onNewIntent(final Intent intent) {
|
||||||
Log.d(Config.LOGTAG, this.getClass().getName() + ".onNewIntent()");
|
Log.d(Config.LOGTAG, this.getClass().getName() + ".onNewIntent()");
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
if (intent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
if (xmppConnectionService == null) {
|
if (xmppConnectionService == null) {
|
||||||
Log.d(
|
Log.d(
|
||||||
|
@ -467,32 +470,21 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
"RtpSessionActivity: background service wasn't bound in onNewIntent()");
|
"RtpSessionActivity: background service wasn't bound in onNewIntent()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Account account = extractAccount(intent);
|
initializeWithIntent(Event.ON_NEW_INTENT, intent);
|
||||||
final String action = intent.getAction();
|
|
||||||
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
|
||||||
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
|
||||||
if (sessionId != null) {
|
|
||||||
Log.d(Config.LOGTAG, "reinitializing from onNewIntent()");
|
|
||||||
if (initializeActivityWithRunningRtpSession(account, with, sessionId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
|
|
||||||
Log.d(Config.LOGTAG, "accepting call from onNewIntent()");
|
|
||||||
requestPermissionsAndAcceptCall();
|
|
||||||
resetIntent(intent.getExtras());
|
|
||||||
}
|
|
||||||
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(action)) {
|
|
||||||
proposeJingleRtpSession(account, with, actionToMedia(action));
|
|
||||||
setWith(account.getRoster().getContact(with), null);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("received onNewIntent without sessionId");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
final Intent intent = getIntent();
|
final var intent = getIntent();
|
||||||
|
if (intent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
initializeWithIntent(Event.ON_BACKEND_CONNECTED, intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeWithIntent(final Event event, @NonNull final Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
|
Log.d(Config.LOGTAG, "initializeWithIntent(" + event + "," + action + ")");
|
||||||
final Account account = extractAccount(intent);
|
final Account account = extractAccount(intent);
|
||||||
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
||||||
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
||||||
|
@ -505,9 +497,6 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
requestPermissionsAndAcceptCall();
|
requestPermissionsAndAcceptCall();
|
||||||
resetIntent(intent.getExtras());
|
resetIntent(intent.getExtras());
|
||||||
}
|
}
|
||||||
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(action)) {
|
|
||||||
proposeJingleRtpSession(account, with, actionToMedia(action));
|
|
||||||
setWith(account.getRoster().getContact(with), null);
|
|
||||||
} else if (Intent.ACTION_VIEW.equals(action)) {
|
} else if (Intent.ACTION_VIEW.equals(action)) {
|
||||||
final String proposedSessionId = intent.getStringExtra(EXTRA_PROPOSED_SESSION_ID);
|
final String proposedSessionId = intent.getStringExtra(EXTRA_PROPOSED_SESSION_ID);
|
||||||
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession =
|
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession =
|
||||||
|
@ -520,8 +509,6 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
||||||
final String lastAction = intent.getStringExtra(EXTRA_LAST_ACTION);
|
|
||||||
final Set<Media> media = actionToMedia(lastAction);
|
|
||||||
final RtpEndUserState state =
|
final RtpEndUserState state =
|
||||||
extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState);
|
extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState);
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
|
@ -541,6 +528,8 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
if (END_CARD.contains(state)) {
|
if (END_CARD.contains(state)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final String lastAction = intent.getStringExtra(EXTRA_LAST_ACTION);
|
||||||
|
final Set<Media> media = actionToMedia(lastAction);
|
||||||
if (xmppConnectionService
|
if (xmppConnectionService
|
||||||
.getJingleConnectionManager()
|
.getJingleConnectionManager()
|
||||||
.hasMatchingProposal(account, with)) {
|
.hasMatchingProposal(account, with)) {
|
||||||
|
@ -567,19 +556,6 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void proposeJingleRtpSession(
|
|
||||||
final Account account, final Jid with, final Set<Media> media) {
|
|
||||||
if (with.isBareJid()) {
|
|
||||||
xmppConnectionService
|
|
||||||
.getJingleConnectionManager()
|
|
||||||
.proposeJingleRtpSession(account, with, media);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"We should not be initializing direct calls from the RtpSessionActivity. Go through CallIntegrationConnectionService.placeCall instead!");
|
|
||||||
}
|
|
||||||
putScreenInCallMode(media);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(
|
public void onRequestPermissionsResult(
|
||||||
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
@ -1526,4 +1502,9 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
private static boolean emptyReference(final WeakReference<?> weakReference) {
|
private static boolean emptyReference(final WeakReference<?> weakReference) {
|
||||||
return weakReference == null || weakReference.get() == null;
|
return weakReference == null || weakReference.get() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Event {
|
||||||
|
ON_BACKEND_CONNECTED,
|
||||||
|
ON_NEW_INTENT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue