diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-10-26 22:16:49 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-10-26 22:16:49 +0200 |
commit | c5cad43be468b32d98e279f550606bd1287170b5 (patch) | |
tree | 0f2e6a4d5476c65177b70b3f85de1cb8f9602580 /src/main/java/de/pixart | |
parent | 1052af9276e4c660b95b7b7fecfc8f40fe28c485 (diff) |
introduced low ping timeout mode after gcm push
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/Config.java | 1 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 992be709d..01c2bcc56 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -62,6 +62,7 @@ public final class Config { public static final int PING_MAX_INTERVAL = 300; public static final int IDLE_PING_INTERVAL = 1800; //540 is minimum according to docs; public static final int PING_MIN_INTERVAL = 30; + public static final int LOW_PING_TIMEOUT = 1; // used after push received public static final int PING_TIMEOUT = 15; public static final int SOCKET_TIMEOUT = 15; public static final int CONNECT_TIMEOUT = 60; diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index bfb0a63a0..73c9a1e12 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -155,6 +155,7 @@ public class XmppConnectionService extends Service { private final List<Conversation> conversations = new CopyOnWriteArrayList<>(); private final IqGenerator mIqGenerator = new IqGenerator(this); private final List<String> mInProgressAvatarFetches = new ArrayList<>(); + private final HashSet<Jid> mLowPingTimeoutMode = new HashSet<>(); private WakeLock wakeLock; private long mLastActivity = 0; public static VideoCompressor CompressVideo; @@ -727,7 +728,8 @@ public class XmppConnectionService extends Service { long lastSent = account.getXmppConnection().getLastPingSent(); long pingInterval = (Config.PUSH_MODE || "ui".equals(action)) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000; long msToNextPing = (Math.max(lastReceived, lastSent) + pingInterval) - SystemClock.elapsedRealtime(); - long pingTimeoutIn = (lastSent + Config.PING_TIMEOUT * 1000) - SystemClock.elapsedRealtime(); + int pingTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()) ? Config.LOW_PING_TIMEOUT * 1000 : Config.PING_TIMEOUT * 1000; + long pingTimeoutIn = (lastSent + pingTimeout) - SystemClock.elapsedRealtime(); if (lastSent > lastReceived) { if (pingTimeoutIn < 0) { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ping timeout"); @@ -735,10 +737,18 @@ public class XmppConnectionService extends Service { } else { int secs = (int) (pingTimeoutIn / 1000); this.scheduleWakeUpCall(secs, account.getUuid().hashCode()); + if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": leaving low ping timeout mode"); + } } } else { pingCandidates.add(account); - if (msToNextPing <= 0 || CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash)) { + if (CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash)) { + pingNow = true; + if (mLowPingTimeoutMode.add(account.getJid().toBareJid())) { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": entering low ping timeout mode"); + } + } else if (msToNextPing <= 0) { pingNow = true; } else { this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode()); |