aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-08-13 23:02:04 +0200
committerChristian Schneppe <christian@pix-art.de>2017-08-13 23:02:04 +0200
commit9f06d99f6a7c09f3b0c3637ccc6fec6f296494d0 (patch)
tree61b5fac293b9b9a5289fefd7fa5c87d5492a0f3c /src/main/java/de/pixart/messenger/services
parentea3cdf46cbe8289e942b71d7e1e1ddf68072ee66 (diff)
some code cleanup and avoid scheduling reconnect task for negative interval
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 9a5905968..dc2728540 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -366,32 +366,29 @@ public class XmppConnectionService extends Service {
}
account.pendingConferenceJoins.clear();
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
- } else {
- if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
- resetSendingToWaiting(account);
- if (!account.isOptionSet(Account.OPTION_DISABLED)) {
- 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");
- reconnectAccount(account, true, false);
- } else {
- int timeToReconnect = mRandom.nextInt(10) + 2;
- scheduleWakeUpCall(timeToReconnect, account.getUuid().hashCode());
- }
- }
- }
- } else if (account.getStatus() == Account.State.REGISTRATION_SUCCESSFUL) {
- databaseBackend.updateAccount(account);
+ } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
+ resetSendingToWaiting(account);
+ if (!account.isOptionSet(Account.OPTION_DISABLED) && isInLowPingTimeoutMode(account)) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now");
reconnectAccount(account, true, false);
- } else if ((account.getStatus() != Account.State.CONNECTING)
- && (account.getStatus() != Account.State.NO_INTERNET)) {
- resetSendingToWaiting(account);
- if (connection != null) {
- int next = connection.getTimeToNextAttempt();
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + ": error connecting account. try again in "
- + next + "s for the "
- + (connection.getAttempt() + 1) + " time");
+ } else {
+ int timeToReconnect = mRandom.nextInt(10) + 2;
+ scheduleWakeUpCall(timeToReconnect, account.getUuid().hashCode());
+ }
+ } else if (account.getStatus() == Account.State.REGISTRATION_SUCCESSFUL) {
+ databaseBackend.updateAccount(account);
+ reconnectAccount(account, true, false);
+ } else if (account.getStatus() != Account.State.CONNECTING && account.getStatus() != Account.State.NO_INTERNET) {
+ resetSendingToWaiting(account);
+ if (connection != null) {
+ final int next = connection.getTimeToNextAttempt();
+ final boolean lowPingTimeoutMode = isInLowPingTimeoutMode(account);
+ if (next <= 0) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error connecting account. reconnecting now. lowPingTimeout=" + Boolean.toString(lowPingTimeoutMode));
+ 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());
}
}
@@ -399,6 +396,13 @@ public class XmppConnectionService extends Service {
getNotificationService().updateErrorNotification();
}
};
+
+ private boolean isInLowPingTimeoutMode(Account account) {
+ synchronized (mLowPingTimeoutMode) {
+ return mLowPingTimeoutMode.contains(account.getJid().toBareJid());
+ }
+ }
+
private OpenPgpServiceConnection pgpServiceConnection;
private PgpEngine mPgpEngine = null;
private PowerManager pm;
@@ -536,7 +540,7 @@ public class XmppConnectionService extends Service {
if (!progressTracker.contains(p) && p != 100 && p != 0) {
progressTracker.add(p);
if (informableCallback != null) {
- informableCallback.inform(getString(R.string.transcoding_video_progress, p));
+ informableCallback.inform(getString(R.string.transcoding_video_progress, String.valueOf(p)));
}
}
}
@@ -731,7 +735,7 @@ public class XmppConnectionService extends Service {
resendFailedFileMessages(conversation);
}
}
- final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid());
+ final boolean lowTimeout = isInLowPingTimeoutMode(account);
account.getXmppConnection().sendPing();
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());