some code cleanup. and avoid scheduling reconnect task for negative interval

This commit is contained in:
Daniel Gultsch 2017-08-05 19:13:29 +02:00
parent 490115d20e
commit 1ab391931d
1 changed files with 31 additions and 28 deletions

View File

@ -358,32 +358,29 @@ public class XmppConnectionService extends Service {
} }
account.pendingConferenceJoins.clear(); account.pendingConferenceJoins.clear();
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode()); scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else { } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
resetSendingToWaiting(account); resetSendingToWaiting(account);
if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!account.isOptionSet(Account.OPTION_DISABLED) && isInLowPingTimeoutMode(account)) {
synchronized (mLowPingTimeoutMode) {
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(10) + 2; int timeToReconnect = mRandom.nextInt(10) + 2;
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);
} else if ((account.getStatus() != Account.State.CONNECTING) } else if (account.getStatus() != Account.State.CONNECTING && account.getStatus() != Account.State.NO_INTERNET) {
&& (account.getStatus() != Account.State.NO_INTERNET)) {
resetSendingToWaiting(account); resetSendingToWaiting(account);
if (connection != null) { if (connection != null) {
int next = connection.getTimeToNextAttempt(); final int next = connection.getTimeToNextAttempt();
Log.d(Config.LOGTAG, account.getJid().toBareJid() final boolean lowPingTimeoutMode = isInLowPingTimeoutMode(account);
+ ": error connecting account. try again in " if (next <= 0) {
+ next + "s for the " Log.d(Config.LOGTAG, account.getJid().toBareJid()+": error connecting account. reconnecting now. lowPingTimeout="+Boolean.toString(lowPingTimeoutMode));
+ (connection.getAttempt() + 1) + " time"); reconnectAccount(account, true, false);
} else {
final int attempt = connection.getAttempt() + 1;
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt+ " time. lowPingTimeout="+Boolean.toString(lowPingTimeoutMode));
scheduleWakeUpCall(next, account.getUuid().hashCode()); scheduleWakeUpCall(next, account.getUuid().hashCode());
} }
} }
@ -391,6 +388,13 @@ public class XmppConnectionService extends Service {
getNotificationService().updateErrorNotification(); getNotificationService().updateErrorNotification();
} }
}; };
private boolean isInLowPingTimeoutMode(Account account) {
synchronized (mLowPingTimeoutMode) {
return mLowPingTimeoutMode.contains(account.getJid().toBareJid());
}
}
private OpenPgpServiceConnection pgpServiceConnection; private OpenPgpServiceConnection pgpServiceConnection;
private PgpEngine mPgpEngine = null; private PgpEngine mPgpEngine = null;
private WakeLock wakeLock; private WakeLock wakeLock;
@ -529,8 +533,7 @@ public class XmppConnectionService extends Service {
if (!progressTracker.contains(p) && p != 100 && p != 0) { if (!progressTracker.contains(p) && p != 100 && p != 0) {
progressTracker.add(p); progressTracker.add(p);
if (informableCallback != null) { if (informableCallback != null) {
informableCallback.inform(getString(R.string.transcoding_video_progress, String.valueOf(p)));
informableCallback.inform(getString(R.string.transcoding_video_progress, p));
} }
} }
} }
@ -722,7 +725,7 @@ public class XmppConnectionService extends Service {
} }
if (pingNow) { if (pingNow) {
for (Account account : pingCandidates) { for (Account account : pingCandidates) {
final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()); final boolean lowTimeout = isInLowPingTimeoutMode(account);
account.getXmppConnection().sendPing(); account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",lowTimeout=" + Boolean.toString(lowTimeout) + ")"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",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());