ping all accounts at the same time

This commit is contained in:
Daniel Gultsch 2016-05-02 14:31:30 +02:00
parent 7674e01585
commit 06a561743a
1 changed files with 17 additions and 5 deletions

View File

@ -51,6 +51,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -555,6 +556,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
this.wakeLock.acquire(); this.wakeLock.acquire();
boolean pingNow = false;
HashSet<Account> pingCandidates = new HashSet<>();
for (Account account : accounts) { for (Account account : accounts) {
if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!account.isOptionSet(Account.OPTION_DISABLED)) {
if (!hasInternetConnection()) { if (!hasInternetConnection()) {
@ -583,13 +587,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
int secs = (int) (pingTimeoutIn / 1000); int secs = (int) (pingTimeoutIn / 1000);
this.scheduleWakeUpCall(secs, account.getUuid().hashCode()); this.scheduleWakeUpCall(secs, account.getUuid().hashCode());
} }
} else if (msToNextPing <= 0) { } else {
account.getXmppConnection().sendPing(); pingCandidates.add(account);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping"); if (msToNextPing <= 0) {
this.scheduleWakeUpCall(Config.PING_TIMEOUT, account.getUuid().hashCode()); pingNow = true;
} else { } else {
this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode()); this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode());
} }
}
} else if (account.getStatus() == Account.State.OFFLINE) { } else if (account.getStatus() == Account.State.OFFLINE) {
reconnectAccount(account, true, interactive); reconnectAccount(account, true, interactive);
} else if (account.getStatus() == Account.State.CONNECTING) { } else if (account.getStatus() == Account.State.CONNECTING) {
@ -617,6 +622,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
} }
if (pingNow) {
for (Account account : pingCandidates) {
account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping");
this.scheduleWakeUpCall(Config.PING_TIMEOUT, account.getUuid().hashCode());
}
}
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
try { try {
wakeLock.release(); wakeLock.release();