create a new axolotl service when the account jid changes

This commit is contained in:
Daniel Gultsch 2017-08-10 14:17:47 +02:00
parent 0da2f1ed3f
commit 57c11d42d5
3 changed files with 24 additions and 2 deletions

View File

@ -263,6 +263,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
public AxolotlService(Account account, XmppConnectionService connectionService) { 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) { if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} }
@ -362,6 +365,16 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
publishBundlesIfNeeded(true, wipeOther); 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() { public int getOwnDeviceId() {
return axolotlStore.getLocalRegistrationId(); return axolotlStore.getLocalRegistrationId();
} }

View File

@ -312,8 +312,17 @@ public class Account extends AbstractEntity {
public boolean setJid(final Jid next) { public boolean setJid(final Jid next) {
final Jid prev = this.jid != null ? this.jid.toBareJid() : null; 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.jid = next;
return prev == null || (next != null && !prev.equals(next.toBareJid())); this.axolotlService = oldAxolotlService.makeNew();
}
}
this.jid = next;
return changed;
} }
public Jid getServer() { public Jid getServer() {

View File

@ -1389,7 +1389,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
} }
public void recreateAxolotlDb(SQLiteDatabase db) { private void recreateAxolotlDb(SQLiteDatabase db) {
Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + ">>> (RE)CREATING AXOLOTL DATABASE <<<"); Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + ">>> (RE)CREATING AXOLOTL DATABASE <<<");
db.execSQL("DROP TABLE IF EXISTS " + SQLiteAxolotlStore.SESSION_TABLENAME); db.execSQL("DROP TABLE IF EXISTS " + SQLiteAxolotlStore.SESSION_TABLENAME);
db.execSQL(CREATE_SESSIONS_STATEMENT); db.execSQL(CREATE_SESSIONS_STATEMENT);