Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/iNPUTmice/Conversations.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2022-09-26 10:47:53 +0300
committerDaniel Gultsch <daniel@gultsch.de>2022-09-26 10:47:53 +0300
commitcb775ece992a8ded54c4cccae484475edc548803 (patch)
tree1bedf32eb093a81e511de35371c721905b5b2b25
parent3d56d01826e53ce5bb5b6450d99a195957a40626 (diff)
wait for DB restore before bind
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java12
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java23
2 files changed, 26 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index e4af37947..483016364 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1939,7 +1939,7 @@ public class XmppConnectionService extends Service {
databaseBackend.expireOldMessages(deletionDate);
}
Log.d(Config.LOGTAG, "restoring roster...");
- for (Account account : accounts) {
+ for (final Account account : accounts) {
databaseBackend.readRoster(account.getRoster());
account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage
}
@@ -1977,11 +1977,11 @@ public class XmppConnectionService extends Service {
public void loadPhoneContacts() {
mContactMergerExecutor.execute(() -> {
- Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
+ final Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
Log.d(Config.LOGTAG, "start merging phone contacts with roster");
- for (Account account : accounts) {
- List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class);
- for (JabberIdContact jidContact : contacts.values()) {
+ for (final Account account : accounts) {
+ final List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class);
+ for (final JabberIdContact jidContact : contacts.values()) {
final Contact contact = account.getRoster().getContact(jidContact.getJid());
boolean needsCacheClean = contact.setPhoneContact(jidContact);
if (needsCacheClean) {
@@ -1989,7 +1989,7 @@ public class XmppConnectionService extends Service {
}
withSystemAccounts.remove(contact);
}
- for (Contact contact : withSystemAccounts) {
+ for (final Contact contact : withSystemAccounts) {
boolean needsCacheClean = contact.unsetPhoneContact(JabberIdContact.class);
if (needsCacheClean) {
getAvatarService().clear(contact);
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index e753e4b39..2ba2daea0 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -753,6 +753,7 @@ public class XmppConnection implements Runnable {
processFailed(failed, false); // wait for new stream features
}
if (bound != null) {
+ clearIqCallbacks();
this.isBound = true;
final Element streamManagementEnabled =
bound.findChild("enabled", Namespace.STREAM_MANAGEMENT);
@@ -1134,7 +1135,12 @@ public class XmppConnection implements Runnable {
tagReader.setInputStream(sslSocket.getInputStream());
tagWriter.setOutputStream(sslSocket.getOutputStream());
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS connection established");
- final boolean quickStart = establishStream(true);
+ final boolean quickStart;
+ try {
+ quickStart = establishStream(true);
+ } catch (final InterruptedException e) {
+ return;
+ }
if (quickStart) {
this.quickStartInProgress = true;
}
@@ -1333,6 +1339,17 @@ public class XmppConnection implements Runnable {
sm
&& bindFeatures != null
&& bindFeatures.containsAll(Bind2.QUICKSTART_FEATURES);
+ if (bindFeatures != null) {
+ try {
+ mXmppConnectionService.restoredFromDatabaseLatch.await();
+ } catch (final InterruptedException e) {
+ Log.d(
+ Config.LOGTAG,
+ account.getJid().asBareJid()
+ + ": interrupted while waiting for DB restore during SASL2 bind");
+ return;
+ }
+ }
authenticate = generateAuthenticationRequest(firstMessage, bindFeatures, sm);
} else {
throw new AssertionError("Missing implementation for " + version);
@@ -1876,7 +1893,6 @@ public class XmppConnection implements Runnable {
}
}
}
- Log.d(Config.LOGTAG, commands.toString());
synchronized (this.commands) {
this.commands.clear();
this.commands.putAll(commands);
@@ -2018,12 +2034,13 @@ public class XmppConnection implements Runnable {
}
}
- private boolean establishStream(final boolean secureConnection) throws IOException {
+ private boolean establishStream(final boolean secureConnection) throws IOException, InterruptedException {
final SaslMechanism saslMechanism = account.getPinnedMechanism();
if (secureConnection
&& Config.SASL_2_ENABLED
&& saslMechanism != null
&& account.isOptionSet(Account.OPTION_QUICKSTART_AVAILABLE)) {
+ mXmppConnectionService.restoredFromDatabaseLatch.await();
this.saslMechanism = saslMechanism;
final Element authenticate =
generateAuthenticationRequest(saslMechanism.getClientFirstMessage());