mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 17:52:17 -05:00
log connection age and reshedule ping check
This commit is contained in:
parent
82d4c3b21f
commit
a535d45ec3
@ -482,9 +482,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
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 msToNextPing = (Math.max(lastReceived,lastSent) + pingInterval) - SystemClock.elapsedRealtime();
|
long msToNextPing = (Math.max(lastReceived,lastSent) + pingInterval) - SystemClock.elapsedRealtime();
|
||||||
if (lastSent > lastReceived && (lastSent + Config.PING_TIMEOUT * 1000) < SystemClock.elapsedRealtime()) {
|
long pingTimeoutIn = (lastSent + Config.PING_TIMEOUT * 1000) - SystemClock.elapsedRealtime();
|
||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": ping timeout");
|
if (lastSent > lastReceived) {
|
||||||
this.reconnectAccount(account, true);
|
if (pingTimeoutIn < 0) {
|
||||||
|
long age = (SystemClock.elapsedRealtime() - account.getXmppConnection().getLastConnect()) / 1000;
|
||||||
|
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ping timeout. connection age was: "+age+"s");
|
||||||
|
this.reconnectAccount(account, true);
|
||||||
|
} else {
|
||||||
|
int secs = (int) (pingTimeoutIn / 1000);
|
||||||
|
this.scheduleWakeUpCall(secs,account.getUuid().hashCode());
|
||||||
|
}
|
||||||
} else if (msToNextPing <= 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");
|
||||||
@ -613,7 +620,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void scheduleWakeUpCall(int seconds, int requestCode) {
|
protected void scheduleWakeUpCall(int seconds, int requestCode) {
|
||||||
final long timeToWake = SystemClock.elapsedRealtime() + (seconds + 1) * 1000;
|
final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000;
|
||||||
|
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
Loading…
Reference in New Issue
Block a user