diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-05-09 20:48:56 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-05-09 20:48:56 +0200 |
commit | c0afad2fcd2be07834f64625204984879880afd5 (patch) | |
tree | 4d936b19362d1f4acd01d982e88813661fc7eb42 /src/main/java/de/pixart/messenger/xmpp | |
parent | 699dbe2e2a56ac36160950c1ac06b16f59eab6c1 (diff) |
avoid race conditions when downloading files or decrypting pgp messages
and waiting for sm catchup
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 3d7961980..f7b826030 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -98,7 +98,7 @@ public class XmppConnection implements Runnable { private static final int PACKET_IQ = 0; private static final int PACKET_MESSAGE = 1; private static final int PACKET_PRESENCE = 2; - protected Account account; + protected final Account account; private final WakeLock wakeLock; private Socket socket; private XmlReader tagReader; @@ -136,7 +136,7 @@ public class XmppConnection implements Runnable { private OnBindListener bindListener = null; private final ArrayList<OnAdvancedStreamFeaturesLoaded> advancedStreamFeaturesLoadedListeners = new ArrayList<>(); private OnMessageAcknowledged acknowledgedListener = null; - private XmppConnectionService mXmppConnectionService = null; + private final XmppConnectionService mXmppConnectionService; private EditAccountActivity mEditAccountActivity = null; private SaslMechanism saslMechanism; @@ -657,11 +657,13 @@ public class XmppConnection implements Runnable { final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); tagWriter.writeStanzaAsync(ack); } else if (nextTag.isStart("a")) { - if (mWaitingForSmCatchup.compareAndSet(true, false)) { - int count = mSmCatchupMessageCounter.get(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")"); - if (count > 0) { - mXmppConnectionService.getNotificationService().finishBacklog(true, account); + synchronized (account) { + if (mWaitingForSmCatchup.compareAndSet(true, false)) { + int count = mSmCatchupMessageCounter.get(); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")"); + if (count > 0) { + mXmppConnectionService.getNotificationService().finishBacklog(true, account); + } } } final Element ack = tagReader.readElement(nextTag); |