~singpolyma/cheogram-android

129c20b1108db8d288b5f48d9c99c091081bc30a — Daniel Gultsch 11 months ago b4e883f
use more aggressive reconnect intervals during rtp session
M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +9 -3
@@ 504,14 504,15 @@ public class XmppConnectionService extends Service {
            } else if (account.getStatus() != Account.State.CONNECTING && account.getStatus() != Account.State.NO_INTERNET) {
                resetSendingToWaiting(account);
                if (connection != null && account.getStatus().isAttemptReconnect()) {
                    final int next = connection.getTimeToNextAttempt();
                    final boolean aggressive = hasJingleRtpConnection(account);
                    final int next = connection.getTimeToNextAttempt(aggressive);
                    final boolean lowPingTimeoutMode = isInLowPingTimeoutMode(account);
                    if (next <= 0) {
                        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. reconnecting now. lowPingTimeout=" + lowPingTimeoutMode);
                        reconnectAccount(account, true, false);
                    } else {
                        final int attempt = connection.getAttempt() + 1;
                        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + lowPingTimeoutMode);
                        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + lowPingTimeoutMode+", aggressive="+aggressive);
                        scheduleWakeUpCall(next, account.getUuid().hashCode());
                    }
                }


@@ 1106,7 1107,8 @@ public class XmppConnectionService extends Service {
                        scheduleWakeUpCall((int) Math.min(timeout, discoTimeout), account.getUuid().hashCode());
                    }
                } else {
                    if (account.getXmppConnection().getTimeToNextAttempt() <= 0) {
                    final boolean aggressive = hasJingleRtpConnection(account);
                    if (account.getXmppConnection().getTimeToNextAttempt(aggressive) <= 0) {
                        reconnectAccount(account, true, interactive);
                    }
                }


@@ 5058,6 5060,10 @@ public class XmppConnectionService extends Service {
        return this.mJingleConnectionManager;
    }

    private boolean hasJingleRtpConnection(final Account account) {
        return this.mJingleConnectionManager.hasJingleRtpConnection(account);
    }

    public MessageArchiveService getMessageArchiveService() {
        return this.mMessageArchiveService;
    }

M src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java => src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +9 -4
@@ 2512,10 2512,15 @@ public class XmppConnection implements Runnable {
        return servers.size() > 0 ? servers.get(0) : null;
    }

    public int getTimeToNextAttempt() {
        final int additionalTime =
                account.getLastErrorStatus() == Account.State.POLICY_VIOLATION ? 3 : 0;
        final int interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300);
    public int getTimeToNextAttempt(final boolean aggressive) {
        final int interval;
        if (aggressive) {
            interval = Math.min((int) (3 * Math.pow(1.3,attempt)), 60);
        } else {
            final int additionalTime =
                    account.getLastErrorStatus() == Account.State.POLICY_VIOLATION ? 3 : 0;
            interval = Math.min((int) (25 * Math.pow(1.3, (additionalTime + attempt))), 300);
        }
        final int secondsSinceLast =
                (int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000);
        return interval - secondsSinceLast;

M src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java => src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +16 -0
@@ 158,6 158,21 @@ public class JingleConnectionManager extends AbstractConnectionManager {
        }
    }

    public boolean hasJingleRtpConnection(final Account account) {
        for (AbstractJingleConnection connection : this.connections.values()) {
            if (connection instanceof JingleRtpConnection) {
                final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
                if (rtpConnection.isTerminated()) {
                    continue;
                }
                if (rtpConnection.id.account == account) {
                    return true;
                }
            }
        }
        return false;
    }

    public void notifyPhoneCallStarted() {
        for (AbstractJingleConnection connection : connections.values()) {
            if (connection instanceof JingleRtpConnection) {


@@ 170,6 185,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
        }
    }


    private Optional<RtpSessionProposal> findMatchingSessionProposal(
            final Account account, final Jid with, final Set<Media> media) {
        synchronized (this.rtpSessionProposals) {