nimbuzz.com: don't wait for disco replies to set account to online

This commit is contained in:
Daniel Gultsch 2016-01-15 14:26:23 +01:00
parent 635210d278
commit c5743067ad
2 changed files with 27 additions and 12 deletions

View File

@ -2478,7 +2478,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
Thread thread = new Thread(account.getXmppConnection()); Thread thread = new Thread(account.getXmppConnection());
account.getXmppConnection().setInteractive(interactive); account.getXmppConnection().setInteractive(interactive);
thread.start(); thread.start();
scheduleWakeUpCall(Config.CONNECT_TIMEOUT, account.getUuid().hashCode()); scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
} else { } else {
account.getRoster().clearPresences(); account.getRoster().clearPresences();
account.setXmppConnection(null); account.setXmppConnection(null);

View File

@ -226,8 +226,16 @@ public class XmppConnection implements Runnable {
lastPingSent = SystemClock.elapsedRealtime(); lastPingSent = SystemClock.elapsedRealtime();
lastDiscoStarted = Long.MAX_VALUE; lastDiscoStarted = Long.MAX_VALUE;
this.attempt++; this.attempt++;
if (account.getJid().getDomainpart().equals("chat.facebook.com")) { switch (account.getJid().getDomainpart()) {
case "chat.facebook.com":
mServerIdentity = Identity.FACEBOOK; mServerIdentity = Identity.FACEBOOK;
break;
case "nimbuzz.com":
mServerIdentity = Identity.NIMBUZZ;
break;
default:
mServerIdentity = Identity.UNKNOWN;
break;
} }
try { try {
shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER); shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER);
@ -718,10 +726,12 @@ public class XmppConnection implements Runnable {
this.streamFeatures = tagReader.readElement(currentTag); this.streamFeatures = tagReader.readElement(currentTag);
if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) { if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) {
sendStartTLS(); sendStartTLS();
} else if (this.streamFeatures.hasChild("register") } else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) {
&& account.isOptionSet(Account.OPTION_REGISTER) if (features.encryptionEnabled) {
&& features.encryptionEnabled) {
sendRegistryRequest(); sendRegistryRequest();
} else {
throw new IncompatibleServerException();
}
} else if (!this.streamFeatures.hasChild("register") } else if (!this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER)) { && account.isOptionSet(Account.OPTION_REGISTER)) {
changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED); changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED);
@ -987,7 +997,7 @@ public class XmppConnection implements Runnable {
synchronized (this.disco) { synchronized (this.disco) {
this.disco.clear(); this.disco.clear();
} }
mPendingServiceDiscoveries = 0; mPendingServiceDiscoveries = mServerIdentity == Identity.NIMBUZZ ? 1 : 0;
lastDiscoStarted = SystemClock.elapsedRealtime(); lastDiscoStarted = SystemClock.elapsedRealtime();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery");
mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
@ -998,7 +1008,9 @@ public class XmppConnection implements Runnable {
} }
private void sendServiceDiscoveryInfo(final Jid jid) { private void sendServiceDiscoveryInfo(final Jid jid) {
if (mServerIdentity != Identity.NIMBUZZ) {
mPendingServiceDiscoveries++; mPendingServiceDiscoveries++;
}
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(jid); iq.setTo(jid);
iq.query("http://jabber.org/protocol/disco#info"); iq.query("http://jabber.org/protocol/disco#info");
@ -1007,7 +1019,7 @@ public class XmppConnection implements Runnable {
@Override @Override
public void onIqPacketReceived(final Account account, final IqPacket packet) { public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() == IqPacket.TYPE.RESULT) {
boolean advancedStreamFeaturesLoaded = false; boolean advancedStreamFeaturesLoaded;
synchronized (XmppConnection.this.disco) { synchronized (XmppConnection.this.disco) {
final List<Element> elements = packet.query().getChildren(); final List<Element> elements = packet.query().getChildren();
final Info info = new Info(); final Info info = new Info();
@ -1018,7 +1030,9 @@ public class XmppConnection implements Runnable {
String name = element.getAttribute("name"); String name = element.getAttribute("name");
if (type != null && category != null) { if (type != null && category != null) {
info.identities.add(new Pair<>(category, type)); info.identities.add(new Pair<>(category, type));
if (type.equals("im") && category.equals("server")) { if (mServerIdentity == Identity.UNKNOWN
&& type.equals("im")
&& category.equals("server")) {
if (name != null && jid.equals(account.getServer())) { if (name != null && jid.equals(account.getServer())) {
switch (name) { switch (name) {
case "Prosody": case "Prosody":
@ -1051,7 +1065,7 @@ public class XmppConnection implements Runnable {
} }
if (packet.getType() != IqPacket.TYPE.TIMEOUT) { if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
mPendingServiceDiscoveries--; mPendingServiceDiscoveries--;
if (mPendingServiceDiscoveries <= 0) { if (mPendingServiceDiscoveries == 0) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": done with service discovery"); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": done with service discovery");
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource());
changeStatus(Account.State.ONLINE); changeStatus(Account.State.ONLINE);
@ -1409,6 +1423,7 @@ public class XmppConnection implements Runnable {
SLACK, SLACK,
EJABBERD, EJABBERD,
PROSODY, PROSODY,
NIMBUZZ,
UNKNOWN UNKNOWN
} }