improvements to RtpSessionActivity

This commit is contained in:
Daniel Gultsch 2020-04-10 13:13:20 +02:00
parent 14d008d89d
commit 2e8b91665b
2 changed files with 26 additions and 12 deletions

View file

@ -84,7 +84,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final Account account = extractAccount(intent); final Account account = extractAccount(intent);
final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH)); final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid()); xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
finishAndReleaseWakeLock(); finish();
} else { } else {
requireRtpConnection().endCall(); requireRtpConnection().endCall();
} }
@ -92,7 +92,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
private void rejectCall(View view) { private void rejectCall(View view) {
requireRtpConnection().rejectCall(); requireRtpConnection().rejectCall();
finishAndReleaseWakeLock(); finish();
} }
private void acceptCall(View view) { private void acceptCall(View view) {
@ -123,11 +123,6 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
} }
private void finishAndReleaseWakeLock() {
releaseWakeLock();
finish();
}
private void releaseWakeLock() { private void releaseWakeLock() {
if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) { if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) {
Log.d(Config.LOGTAG, "releasing wake lock"); Log.d(Config.LOGTAG, "releasing wake lock");
@ -153,6 +148,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
if (ACTION_ACCEPT_CALL.equals(intent.getAction())) { if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
Log.d(Config.LOGTAG, "accepting call from onNewIntent()"); Log.d(Config.LOGTAG, "accepting call from onNewIntent()");
requestPermissionsAndAcceptCall(); requestPermissionsAndAcceptCall();
resetIntent(intent.getExtras());
} }
} else { } else {
throw new IllegalStateException("received onNewIntent without sessionId"); throw new IllegalStateException("received onNewIntent without sessionId");
@ -170,6 +166,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
if (ACTION_ACCEPT_CALL.equals(intent.getAction())) { if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
Log.d(Config.LOGTAG, "intent action was accept"); Log.d(Config.LOGTAG, "intent action was accept");
requestPermissionsAndAcceptCall(); requestPermissionsAndAcceptCall();
resetIntent(intent.getExtras());
} }
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(intent.getAction())) { } else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(intent.getAction())) {
proposeJingleRtpSession(account, with); proposeJingleRtpSession(account, with);
@ -212,6 +209,14 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
} }
@Override
public void onStop() {
if (!isChangingConfigurations()) {
releaseWakeLock();
}
super.onStop();
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
endCall(); endCall();
@ -223,13 +228,13 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager() final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()
.findJingleRtpConnection(account, with, sessionId); .findJingleRtpConnection(account, with, sessionId);
if (reference == null || reference.get() == null) { if (reference == null || reference.get() == null) {
finishAndReleaseWakeLock(); finish();
return; return;
} }
this.rtpConnectionReference = reference; this.rtpConnectionReference = reference;
final RtpEndUserState currentState = requireRtpConnection().getEndUserState(); final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
if (currentState == RtpEndUserState.ENDED) { if (currentState == RtpEndUserState.ENDED) {
finishAndReleaseWakeLock(); finish();
return; return;
} }
binding.with.setText(getWith().getDisplayName()); binding.with.setText(getWith().getDisplayName());
@ -334,7 +339,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
private void exit(View view) { private void exit(View view) {
finishAndReleaseWakeLock(); finish();
} }
private Contact getWith() { private Contact getWith() {
@ -369,7 +374,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final AbstractJingleConnection.Id id = requireRtpConnection().getId(); final AbstractJingleConnection.Id id = requireRtpConnection().getId();
if (account == id.account && id.with.equals(with) && id.sessionId.equals(sessionId)) { if (account == id.account && id.with.equals(with) && id.sessionId.equals(sessionId)) {
if (state == RtpEndUserState.ENDED) { if (state == RtpEndUserState.ENDED) {
finishAndReleaseWakeLock(); finish();
return; return;
} else if (asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.CONNECTIVITY_ERROR).contains(state)) { } else if (asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.CONNECTIVITY_ERROR).contains(state)) {
resetIntent(account, with, state); resetIntent(account, with, state);
@ -399,8 +404,13 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
} }
private void resetIntent(final Bundle extras) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtras(extras);
setIntent(intent);
}
private void resetIntent(final Account account, Jid with, final RtpEndUserState state) { private void resetIntent(final Account account, Jid with, final RtpEndUserState state) {
Log.d(Config.LOGTAG, "resetting intent");
final Intent intent = new Intent(Intent.ACTION_VIEW); final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString()); intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString()); intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());

View file

@ -664,6 +664,10 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
sendSessionTerminate(Reason.SUCCESS); sendSessionTerminate(Reason.SUCCESS);
return; return;
} }
if (isInState(State.TERMINATED_APPLICATION_FAILURE, State.TERMINATED_CONNECTIVITY_ERROR, State.TERMINATED_DECLINED_OR_BUSY)) {
Log.d(Config.LOGTAG, "ignoring request to end call because already in state " + this.state);
return;
}
throw new IllegalStateException("called 'endCall' while in state " + this.state + ". isInitiator=" + isInitiator()); throw new IllegalStateException("called 'endCall' while in state " + this.state + ". isInitiator=" + isInitiator());
} }