diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-08-13 23:21:33 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-08-13 23:21:33 +0200 |
commit | 8246154a36321b2d45a5e1df3caf6e6b124f4720 (patch) | |
tree | d9035b05b44accd56826aaf0d252258c56a7de53 | |
parent | 532aadea3afaac7f03e412eb23cbe9587fa8b94a (diff) |
create a new axolotl service when the account jid changes
-rw-r--r-- | src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java | 13 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Account.java | 12 |
2 files changed, 23 insertions, 2 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 0aa797aff..87d37788c 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -263,6 +263,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public AxolotlService(Account account, XmppConnectionService connectionService) { + if (account == null || connectionService == null) { + throw new IllegalArgumentException("account and service cannot be null"); + } if (Security.getProvider("BC") == null) { Security.addProvider(new BouncyCastleProvider()); } @@ -360,6 +363,16 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { publishBundlesIfNeeded(true, wipeOther); } + public void destroy() { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": destroying old axolotl service. no longer in use"); + mXmppConnectionService.databaseBackend.wipeAxolotlDb(account); + } + + public AxolotlService makeNew() { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": make new axolotl service"); + return new AxolotlService(this.account, this.mXmppConnectionService); + } + public int getOwnDeviceId() { return axolotlStore.getLocalRegistrationId(); } diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 03673c689..3cb5e027f 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -314,9 +314,17 @@ public class Account extends AbstractEntity { public boolean setJid(final Jid next) { final Jid prev = this.jid != null ? this.jid.toBareJid() : null; + final boolean changed = prev == null || (next != null && !prev.equals(next.toBareJid())); + if (changed) { + final AxolotlService oldAxolotlService = this.axolotlService; + if (oldAxolotlService != null) { + oldAxolotlService.destroy(); + this.jid = next; + this.axolotlService = oldAxolotlService.makeNew(); + } + } this.jid = next; - return prev == null || (next != null && !prev.equals(next.toBareJid()) - ); + return changed; } public Jid getServer() { |