diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-08-01 13:24:24 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-08-01 13:24:24 +0200 |
commit | 793a50fb376cb2c9f1b97fb606e1db949127e277 (patch) | |
tree | 98feff99582a4e4a24c7906472298f786d2eabb2 /src/main/java/de/pixart/messenger | |
parent | d7bc205420bc07578aee49087b3988429e22372b (diff) |
provide upgrade path for accounts with publish-options
Diffstat (limited to 'src/main/java/de/pixart/messenger')
3 files changed, 24 insertions, 4 deletions
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(); diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 872035af0..74d0cf010 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -57,6 +57,7 @@ public class Account extends AbstractEntity { public static final int OPTION_REGISTER = 2; public static final int OPTION_USECOMPRESSION = 3; public static final int OPTION_MAGIC_CREATE = 4; + public static final int OPTION_REQURIES_ACCESS_MODE_CHANGE = 5; public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>(); public boolean httpUploadAvailable(long filesize) { diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index a3cfb93c7..611a0b65d 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -59,7 +59,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static DatabaseBackend instance = null; public static final String DATABASE_NAME = "history"; - public static final int DATABASE_VERSION = 36; + public static final int DATABASE_VERSION = 37; // = Conversations DATABASE_VERSION + 1 private static String CREATE_CONTATCS_STATEMENT = "create table " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " @@ -456,6 +456,15 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } } + + if (oldVersion < 37 && newVersion >= 37) { + List<Account> accounts = getAccounts(db); + for (Account account : accounts) { + account.setOption(Account.OPTION_REQURIES_ACCESS_MODE_CHANGE, true); + db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + + "=?", new String[]{account.getUuid()}); + } + } } private static ContentValues createFingerprintStatusContentValues(FingerprintStatus.Trust trust, boolean active) { |