fixed bug in new ping strategy

This commit is contained in:
Daniel Gultsch 2015-01-06 19:46:52 +01:00
parent 353f4e38bb
commit f02f510c18

View File

@ -421,16 +421,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
long lastReceived = account.getXmppConnection().getLastPacketReceived(); long lastReceived = account.getXmppConnection().getLastPacketReceived();
long lastSent = account.getXmppConnection().getLastPingSent(); long lastSent = account.getXmppConnection().getLastPingSent();
long pingInterval = "ui".equals(action) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000; long pingInterval = "ui".equals(action) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000;
long secondsToNextPing = ((lastReceived + pingInterval) - SystemClock.elapsedRealtime()) / 1000; long msToNextPing = (Math.max(lastReceived,lastSent) + pingInterval) - SystemClock.elapsedRealtime();
if (lastSent > lastReceived && (lastSent + Config.PING_TIMEOUT * 1000) < SystemClock.elapsedRealtime()) { if (lastSent > lastReceived && (lastSent + Config.PING_TIMEOUT * 1000) < SystemClock.elapsedRealtime()) {
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": ping timeout"); Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": ping timeout");
this.reconnectAccount(account, true); this.reconnectAccount(account, true);
} else if (secondsToNextPing <= 0) { } else if (msToNextPing <= 0) {
account.getXmppConnection().sendPing(); account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid()+" send ping"); Log.d(Config.LOGTAG, account.getJid().toBareJid()+" send ping");
this.scheduleWakeUpCall(Config.PING_TIMEOUT,account.getUuid().hashCode()); this.scheduleWakeUpCall(Config.PING_TIMEOUT,account.getUuid().hashCode());
} else { } else {
this.scheduleWakeUpCall((int) secondsToNextPing, account.getUuid().hashCode()); this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode());
} }
} else if (account.getStatus() == Account.State.OFFLINE) { } else if (account.getStatus() == Account.State.OFFLINE) {
if (account.getXmppConnection() == null) { if (account.getXmppConnection() == null) {