fully depend on sm

This commit is contained in:
Daniel Gultsch 2015-08-13 18:25:10 +02:00
parent 32826ec29d
commit 83e1e6468e
7 changed files with 76 additions and 86 deletions

View File

@ -149,14 +149,25 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override @Override
public void onBind(final Account account) { public void onBind(final Account account) {
resetSendingToWaiting(account);
account.getRoster().clearPresences(); account.getRoster().clearPresences();
account.pendingConferenceJoins.clear();
account.pendingConferenceLeaves.clear();
fetchRosterFromServer(account); fetchRosterFromServer(account);
fetchBookmarks(account); fetchBookmarks(account);
sendPresence(account); sendPresence(account);
connectMultiModeConversations(account); connectMultiModeConversations(account);
updateConversationUi(); for (Conversation conversation : account.pendingConferenceLeaves) {
leaveMuc(conversation);
}
account.pendingConferenceLeaves.clear();
for (Conversation conversation : account.pendingConferenceJoins) {
joinMuc(conversation);
}
account.pendingConferenceJoins.clear();
mMessageArchiveService.executePendingQueries(account);
mJingleConnectionManager.cancelInTransmission();
syncDirtyContacts(account);
account.getAxolotlService().publishOwnDeviceIdIfNeeded();
account.getAxolotlService().publishBundlesIfNeeded();
} }
}; };
private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() { private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@ -248,14 +259,15 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
mOnAccountUpdate.onAccountUpdate(); mOnAccountUpdate.onAccountUpdate();
} }
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
for (Conversation conversation : account.pendingConferenceLeaves) { if (connection != null && connection.getFeatures().csi()) {
leaveMuc(conversation); if (checkListeners()) {
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ " sending csi//inactive");
connection.sendInactive();
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ " sending csi//active");
connection.sendActive();
}
} }
for (Conversation conversation : account.pendingConferenceJoins) {
joinMuc(conversation);
}
mMessageArchiveService.executePendingQueries(account);
mJingleConnectionManager.cancelInTransmission();
List<Conversation> conversations = getConversations(); List<Conversation> conversations = getConversations();
for (Conversation conversation : conversations) { for (Conversation conversation : conversations) {
if (conversation.getAccount() == account) { if (conversation.getAccount() == account) {
@ -263,21 +275,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendUnsentMessages(conversation); sendUnsentMessages(conversation);
} }
} }
if (connection != null && connection.getFeatures().csi()) {
if (checkListeners()) {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ " sending csi//inactive");
connection.sendInactive();
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ " sending csi//active");
connection.sendActive();
}
}
syncDirtyContacts(account);
account.getAxolotlService().publishOwnDeviceIdIfNeeded();
account.getAxolotlService().publishBundlesIfNeeded();
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode()); scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else if (account.getStatus() == Account.State.OFFLINE) { } else if (account.getStatus() == Account.State.OFFLINE) {
if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!account.isOptionSet(Account.OPTION_DISABLED)) {
@ -859,7 +856,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster");
} }
iqPacket.query(Xmlns.ROSTER).setAttribute("ver", account.getRosterVersion()); iqPacket.query(Xmlns.ROSTER).setAttribute("ver", account.getRosterVersion());
sendIqPacket(account,iqPacket,mIqParser); sendIqPacket(account, iqPacket, mIqParser);
} }
public void fetchBookmarks(final Account account) { public void fetchBookmarks(final Account account) {
@ -1478,6 +1475,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
public void joinMuc(Conversation conversation) { public void joinMuc(Conversation conversation) {
Account account = conversation.getAccount(); Account account = conversation.getAccount();
account.pendingConferenceJoins.remove(conversation); account.pendingConferenceJoins.remove(conversation);

View File

@ -1,13 +1,10 @@
package eu.siacs.conversations.xmpp; package eu.siacs.conversations.xmpp;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.os.SystemClock; import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import android.util.SparseArray; import android.util.SparseArray;
@ -65,6 +62,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived; import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket; import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
import eu.siacs.conversations.xmpp.stanzas.AbstractAcknowledgeableStanza;
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
@ -94,7 +92,7 @@ public class XmppConnection implements Runnable {
private String streamId = null; private String streamId = null;
private int smVersion = 3; private int smVersion = 3;
private final SparseArray<String> mStanzaReceipts = new SparseArray<>(); private final SparseArray<AbstractAcknowledgeableStanza> mStanzaQueue = new SparseArray<>();
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
@ -342,22 +340,19 @@ public class XmppConnection implements Runnable {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": session resumed"); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": session resumed");
} }
acknowledgeStanzaUpTo(serverCount); acknowledgeStanzaUpTo(serverCount);
ArrayList<IqPacket> failedIqPackets = new ArrayList<>(); ArrayList<AbstractAcknowledgeableStanza> failedStanzas = new ArrayList<>();
for(int i = 0; i < this.mStanzaReceipts.size(); ++i) { for(int i = 0; i < this.mStanzaQueue.size(); ++i) {
String id = mStanzaReceipts.valueAt(i); failedStanzas.add(mStanzaQueue.valueAt(i));
Pair<IqPacket,OnIqPacketReceived> pair = id == null ? null : this.packetCallbacks.get(id);
if (pair != null) {
failedIqPackets.add(pair.first);
}
} }
mStanzaReceipts.clear(); mStanzaQueue.clear();
Log.d(Config.LOGTAG,"resending "+failedIqPackets.size()+" iq stanza"); Log.d(Config.LOGTAG,"resending "+failedStanzas.size()+" stanzas");
for(IqPacket packet : failedIqPackets) { for(AbstractAcknowledgeableStanza packet : failedStanzas) {
sendUnmodifiedIqPacket(packet,null); sendPacket(packet);
} }
} catch (final NumberFormatException ignored) { } catch (final NumberFormatException ignored) {
} }
sendInitialPing(); Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": online with resource " + account.getResource());
changeStatus(Account.State.ONLINE);
} else if (nextTag.isStart("r")) { } else if (nextTag.isStart("r")) {
tagReader.readElement(nextTag); tagReader.readElement(nextTag);
if (Config.EXTENDED_SM_LOGGING) { if (Config.EXTENDED_SM_LOGGING) {
@ -399,36 +394,22 @@ public class XmppConnection implements Runnable {
} }
private void acknowledgeStanzaUpTo(int serverCount) { private void acknowledgeStanzaUpTo(int serverCount) {
for (int i = 0; i < mStanzaReceipts.size(); ++i) { for (int i = 0; i < mStanzaQueue.size(); ++i) {
if (serverCount >= mStanzaReceipts.keyAt(i)) { if (serverCount >= mStanzaQueue.keyAt(i)) {
if (Config.EXTENDED_SM_LOGGING) { if (Config.EXTENDED_SM_LOGGING) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server acknowledged stanza #" + mStanzaReceipts.keyAt(i)); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server acknowledged stanza #" + mStanzaQueue.keyAt(i));
} }
String id = mStanzaReceipts.valueAt(i); AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i);
if (acknowledgedListener != null) { if (stanza instanceof MessagePacket && acknowledgedListener != null) {
acknowledgedListener.onMessageAcknowledged(account, id); MessagePacket packet = (MessagePacket) stanza;
acknowledgedListener.onMessageAcknowledged(account, packet.getId());
} }
mStanzaReceipts.removeAt(i); mStanzaQueue.removeAt(i);
i--; i--;
} }
} }
} }
private void sendInitialPing() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": sending intial ping");
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid());
iq.addChild("ping", "urn:xmpp:ping");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": online with resource " + account.getResource());
changeStatus(Account.State.ONLINE);
}
});
}
private Element processPacket(final Tag currentTag, final int packetType) private Element processPacket(final Tag currentTag, final int packetType)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
Element element; Element element;
@ -775,7 +756,7 @@ public class XmppConnection implements Runnable {
final EnablePacket enable = new EnablePacket(smVersion); final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable); tagWriter.writeStanzaAsync(enable);
stanzasSent = 0; stanzasSent = 0;
mStanzaReceipts.clear(); mStanzaQueue.clear();
} }
features.carbonsEnabled = false; features.carbonsEnabled = false;
features.blockListRequested = false; features.blockListRequested = false;
@ -783,10 +764,11 @@ public class XmppConnection implements Runnable {
sendServiceDiscoveryInfo(account.getServer()); sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryInfo(account.getJid().toBareJid()); sendServiceDiscoveryInfo(account.getJid().toBareJid());
sendServiceDiscoveryItems(account.getServer()); sendServiceDiscoveryItems(account.getServer());
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": online with resource " + account.getResource());
changeStatus(Account.State.ONLINE);
if (bindListener != null) { if (bindListener != null) {
bindListener.onBind(account); bindListener.onBind(account);
} }
sendInitialPing();
} }
private void sendServiceDiscoveryInfo(final Jid jid) { private void sendServiceDiscoveryInfo(final Jid jid) {
@ -937,16 +919,17 @@ public class XmppConnection implements Runnable {
return; return;
} }
final String name = packet.getName(); final String name = packet.getName();
if (name.equals("iq") || name.equals("message") || name.equals("presence")) {
++stanzasSent;
}
tagWriter.writeStanzaAsync(packet); tagWriter.writeStanzaAsync(packet);
if ((packet instanceof MessagePacket || packet instanceof IqPacket) && packet.getId() != null && this.streamId != null) { if (packet instanceof AbstractAcknowledgeableStanza) {
if (Config.EXTENDED_SM_LOGGING) { AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet;
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for stanza #" + stanzasSent); ++stanzasSent;
this.mStanzaQueue.put(stanzasSent, stanza);
if (stanza instanceof MessagePacket && stanza.getId() != null && this.streamId != null) {
if (Config.EXTENDED_SM_LOGGING) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent);
}
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
} }
this.mStanzaReceipts.put(stanzasSent, packet.getId());
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
} }
} }

View File

@ -0,0 +1,17 @@
package eu.siacs.conversations.xmpp.stanzas;
abstract public class AbstractAcknowledgeableStanza extends AbstractStanza {
protected AbstractAcknowledgeableStanza(String name) {
super(name);
}
public String getId() {
return this.getAttribute("id");
}
public void setId(final String id) {
setAttribute("id", id);
}
}

View File

@ -18,10 +18,6 @@ public class AbstractStanza extends Element {
return getAttributeAsJid("from"); return getAttributeAsJid("from");
} }
public String getId() {
return this.getAttribute("id");
}
public void setTo(final Jid to) { public void setTo(final Jid to) {
if (to != null) { if (to != null) {
setAttribute("to", to.toString()); setAttribute("to", to.toString());
@ -34,10 +30,6 @@ public class AbstractStanza extends Element {
} }
} }
public void setId(final String id) {
setAttribute("id", id);
}
public boolean fromServer(final Account account) { public boolean fromServer(final Account account) {
return getFrom() == null return getFrom() == null
|| getFrom().equals(account.getServer()) || getFrom().equals(account.getServer())

View File

@ -2,9 +2,9 @@ package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
public class IqPacket extends AbstractStanza { public class IqPacket extends AbstractAcknowledgeableStanza {
public static enum TYPE { public enum TYPE {
ERROR, ERROR,
SET, SET,
RESULT, RESULT,

View File

@ -5,7 +5,7 @@ import android.util.Pair;
import eu.siacs.conversations.parser.AbstractParser; import eu.siacs.conversations.parser.AbstractParser;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
public class MessagePacket extends AbstractStanza { public class MessagePacket extends AbstractAcknowledgeableStanza {
public static final int TYPE_CHAT = 0; public static final int TYPE_CHAT = 0;
public static final int TYPE_NORMAL = 2; public static final int TYPE_NORMAL = 2;
public static final int TYPE_GROUPCHAT = 3; public static final int TYPE_GROUPCHAT = 3;

View File

@ -1,6 +1,6 @@
package eu.siacs.conversations.xmpp.stanzas; package eu.siacs.conversations.xmpp.stanzas;
public class PresencePacket extends AbstractStanza { public class PresencePacket extends AbstractAcknowledgeableStanza {
public PresencePacket() { public PresencePacket() {
super("presence"); super("presence");