transform nimbuzz workaround into a more general 'waitForDisco' condition

This commit is contained in:
Daniel Gultsch 2016-04-09 08:53:58 +02:00
parent a8ebc5fafc
commit 14b46c3ee7
1 changed files with 11 additions and 6 deletions

View File

@ -118,6 +118,7 @@ public class XmppConnection implements Runnable {
private long lastDiscoStarted = 0;
private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0);
private AtomicBoolean mIsServiceItemsDiscoveryPending = new AtomicBoolean(true);
private boolean mWaitForDisco = true;
private final ArrayList<String> mPendingServiceDiscoveriesIds = new ArrayList<>();
private boolean mInteractive = false;
private int attempt = 0;
@ -1011,8 +1012,9 @@ public class XmppConnection implements Runnable {
synchronized (this.disco) {
this.disco.clear();
}
mPendingServiceDiscoveries.set(mServerIdentity == Identity.NIMBUZZ ? 1 : 0);
mPendingServiceDiscoveries.set(0);
mIsServiceItemsDiscoveryPending.set(true);
mWaitForDisco = mServerIdentity != Identity.NIMBUZZ;
lastDiscoStarted = SystemClock.elapsedRealtime();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery");
mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
@ -1031,13 +1033,14 @@ public class XmppConnection implements Runnable {
}
sendServiceDiscoveryInfo(account.getJid().toBareJid());
sendServiceDiscoveryItems(account.getServer());
if (!mWaitForDisco) {
finalizeBind();
}
this.lastSessionStarted = SystemClock.elapsedRealtime();
}
private void sendServiceDiscoveryInfo(final Jid jid) {
if (mServerIdentity != Identity.NIMBUZZ) {
mPendingServiceDiscoveries.incrementAndGet();
}
mPendingServiceDiscoveries.incrementAndGet();
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(jid);
iq.query("http://jabber.org/protocol/disco#info");
@ -1081,7 +1084,9 @@ public class XmppConnection implements Runnable {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco info for " + jid.toString());
}
if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
if (mPendingServiceDiscoveries.decrementAndGet() == 0 && !mIsServiceItemsDiscoveryPending.get()) {
if (mPendingServiceDiscoveries.decrementAndGet() == 0
&& !mIsServiceItemsDiscoveryPending.get()
&& mWaitForDisco) {
finalizeBind();
}
}
@ -1136,7 +1141,7 @@ public class XmppConnection implements Runnable {
}
if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
mIsServiceItemsDiscoveryPending.set(false);
if (mPendingServiceDiscoveries.get() == 0) {
if (mPendingServiceDiscoveries.get() == 0 && mWaitForDisco) {
finalizeBind();
}
}