From 793a50fb376cb2c9f1b97fb606e1db949127e277 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 1 Aug 2017 13:24:24 +0200 Subject: provide upgrade path for accounts with publish-options --- .../pixart/messenger/crypto/axolotl/AxolotlService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java') diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java index 5dc37e4c9..7f15f692e 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -81,6 +81,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { private int numPublishTriesOnEmptyPep = 0; private boolean pepBroken = false; private AtomicBoolean ownPushPending = new AtomicBoolean(false); + private AtomicBoolean changeAccessMode = new AtomicBoolean(false); @Override public void onAdvancedStreamFeaturesAvailable(Account account) { @@ -408,6 +409,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { if (Config.OMEMO_AUTO_EXPIRY != 0) { needsPublishing |= deviceIds.removeAll(getExpiredDevices()); } + needsPublishing |= this.changeAccessMode.get(); for (Integer deviceId : deviceIds) { SignalProtocolAddress ownDeviceAddress = new SignalProtocolAddress(jid.toBareJid().toPreppedString(), deviceId); if (sessions.get(ownDeviceAddress) == null) { @@ -530,6 +532,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } }); } else { + if (AxolotlService.this.changeAccessMode.compareAndSet(true, false)) { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": done changing access mode"); + account.setOption(Account.OPTION_REQURIES_ACCESS_MODE_CHANGE, false); + mXmppConnectionService.databaseBackend.updateAccount(account); + } ownPushPending.set(false); if (packet.getType() == IqPacket.TYPE.ERROR) { pepBroken = true; @@ -583,6 +590,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... "); return; } + this.changeAccessMode.set(account.isOptionSet(Account.OPTION_REQURIES_ACCESS_MODE_CHANGE) && account.getXmppConnection().getFeatures().pepPublishOptions()); + if (this.changeAccessMode.get()) { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server gained publish-options capabilities. changing access model"); + } IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().toBareJid(), getOwnDeviceId()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override @@ -667,7 +678,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } - if (changed) { + if (changed || changeAccessMode.get()) { if (account.getPrivateKeyAlias() != null && Config.X509_VERIFICATION) { mXmppConnectionService.publishDisplayName(account); publishDeviceVerificationAndBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); @@ -725,8 +736,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announceAfter, wipe, false); } }); - } - if (packet.getType() == IqPacket.TYPE.RESULT) { + } else if (packet.getType() == IqPacket.TYPE.RESULT) { Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Successfully published bundle. "); if (wipe) { wipeOtherPepDevices(); -- cgit v1.2.3