leaving low ping timeout mode after coming online

This commit is contained in:
Daniel Gultsch 2016-11-02 09:36:14 +01:00
parent e538272417
commit e582b9fc10

View file

@ -295,6 +295,11 @@ public class XmppConnectionService extends Service {
mOnAccountUpdate.onAccountUpdate(); mOnAccountUpdate.onAccountUpdate();
} }
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
synchronized (mLowPingTimeoutMode) {
if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": leaving low ping timeout mode");
}
}
if (account.setShowErrorNotification(true)) { if (account.setShowErrorNotification(true)) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
} }
@ -336,14 +341,16 @@ public class XmppConnectionService extends Service {
&& listeners; && listeners;
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": push mode="+Boolean.toString(pushMode)+" listeners="+Boolean.toString(listeners)); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": push mode="+Boolean.toString(pushMode)+" listeners="+Boolean.toString(listeners));
if (!disabled && !pushMode) { if (!disabled && !pushMode) {
synchronized (mLowPingTimeoutMode) {
if (mLowPingTimeoutMode.contains(account.getJid().toBareJid())) { if (mLowPingTimeoutMode.contains(account.getJid().toBareJid())) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": went into offline state during low ping mode. reconnecting now"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now");
reconnectAccount(account,true,false); reconnectAccount(account, true, false);
} else { } else {
int timeToReconnect = mRandom.nextInt(20) + 10; int timeToReconnect = mRandom.nextInt(20) + 10;
scheduleWakeUpCall(timeToReconnect, account.getUuid().hashCode()); scheduleWakeUpCall(timeToReconnect, account.getUuid().hashCode());
} }
} }
}
} else if (account.getStatus() == Account.State.REGISTRATION_SUCCESSFUL) { } else if (account.getStatus() == Account.State.REGISTRATION_SUCCESSFUL) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
reconnectAccount(account, true, false); reconnectAccount(account, true, false);
@ -628,6 +635,7 @@ public class XmppConnectionService extends Service {
} }
} }
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
synchronized (mLowPingTimeoutMode) {
long lastReceived = account.getXmppConnection().getLastPacketReceived(); long lastReceived = account.getXmppConnection().getLastPacketReceived();
long lastSent = account.getXmppConnection().getLastPingSent(); long lastSent = account.getXmppConnection().getLastPingSent();
long pingInterval = (Config.PUSH_MODE || "ui".equals(action)) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000; long pingInterval = (Config.PUSH_MODE || "ui".equals(action)) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000;
@ -654,7 +662,8 @@ public class XmppConnectionService extends Service {
} else { } else {
this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode()); this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode());
if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) { if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": leaving low ping timeout mode"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": leaving low ping timeout mode");
}
} }
} }
} }
@ -695,10 +704,12 @@ public class XmppConnectionService extends Service {
account.getXmppConnection().waitForPush(); account.getXmppConnection().waitForPush();
cancelWakeUpCall(account.getUuid().hashCode()); cancelWakeUpCall(account.getUuid().hashCode());
} else { } else {
synchronized (mLowPingTimeoutMode) {
final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()); final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid());
account.getXmppConnection().sendPing(); account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",listeners="+Boolean.toString(listeners)+",lowTimeout="+Boolean.toString(lowTimeout)+")"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",listeners=" + Boolean.toString(listeners) + ",lowTimeout=" + Boolean.toString(lowTimeout) + ")");
scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT: Config.PING_TIMEOUT, account.getUuid().hashCode()); scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode());
}
} }
} }
} }