diff options
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/XmppConnection.java')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 6e55ebfe..ab17d5d5 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -88,6 +88,8 @@ public class XmppConnection implements Runnable { public long lastPingSent = 0; public long lastConnect = 0; public long lastSessionStarted = 0; + + private int attempt = 0; private static final int PACKET_IQ = 0; private static final int PACKET_MESSAGE = 1; @@ -113,6 +115,9 @@ public class XmppConnection implements Runnable { if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)&&(account.getStatus() != Account.STATUS_DISABLED)) { return; } + if (nextStatus == Account.STATUS_ONLINE) { + this.attempt = 0; + } account.setStatus(nextStatus); if (statusListener != null) { statusListener.onStatusChanged(account); @@ -123,6 +128,7 @@ public class XmppConnection implements Runnable { protected void connect() { Log.d(LOGTAG,account.getJid()+ ": connecting"); lastConnect = SystemClock.elapsedRealtime(); + this.attempt++; try { shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER); tagReader = new XmlReader(wakeLock); @@ -916,4 +922,14 @@ public class XmppConnection implements Runnable { Log.d(LOGTAG,"adding "+jid+" to pending subscriptions"); this.pendingSubscriptions.add(jid); } + + public int getTimeToNextAttempt() { + int interval = (int) (25 * Math.pow(1.5,attempt)); + int secondsSinceLast = (int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000); + return interval - secondsSinceLast; + } + + public int getAttempt() { + return this.attempt; + } } |