added count down latch to await account connect before going into publish profile activity

This commit is contained in:
Daniel Gultsch 2018-10-31 12:52:23 +01:00
parent fe45a7afcc
commit 19e13115d3
5 changed files with 53 additions and 29 deletions

View File

@ -10,4 +10,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService
public void considerSync() {
}
@Override
public void signalAccountStateChange() {
}
}

View File

@ -19,4 +19,6 @@ public abstract class AbstractQuickConversationsService {
public static boolean isConversations() {
return "conversations".equals(BuildConfig.FLAVOR_mode);
}
public abstract void signalAccountStateChange();
}

View File

@ -322,6 +322,11 @@ public class XmppConnectionService extends Service {
public void onStatusChanged(final Account account) {
XmppConnection connection = account.getXmppConnection();
updateAccountUi();
if (account.getStatus() == Account.State.ONLINE || account.getStatus().isError()) {
mQuickConversationsService.signalAccountStateChange();
}
if (account.getStatus() == Account.State.ONLINE) {
synchronized (mLowPingTimeoutMode) {
if (mLowPingTimeoutMode.remove(account.getJid().asBareJid())) {

View File

@ -1,7 +1,6 @@
package eu.siacs.conversations.entities;
import android.util.Base64;
import android.util.Log;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -10,7 +9,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.android.PhoneNumberContact;
import eu.siacs.conversations.xml.Element;
import rocks.xmpp.addr.Jid;
@ -71,7 +69,6 @@ public class Entry implements Comparable<Entry> {
} catch (NoSuchAlgorithmException e) {
return "";
}
Log.d(Config.LOGTAG,"status quo string: "+builder.toString());
byte[] sha1 = md.digest(builder.toString().getBytes());
return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
}

View File

@ -24,6 +24,8 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.SSLHandshakeException;
@ -64,6 +66,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private final AtomicBoolean mVerificationInProgress = new AtomicBoolean(false);
private final AtomicBoolean mVerificationRequestInProgress = new AtomicBoolean(false);
private CountDownLatch awaitingAccountStateChange;
private Attempt mLastSyncAttempt = new Attempt(0, 0);
@ -144,6 +147,13 @@ public class QuickConversationsService extends AbstractQuickConversationsService
}
public void signalAccountStateChange() {
if (awaitingAccountStateChange != null && awaitingAccountStateChange.getCount() > 0) {
Log.d(Config.LOGTAG, "signaled state change");
awaitingAccountStateChange.countDown();
}
}
private void createAccountAndWait(Phonenumber.PhoneNumber phoneNumber, final long timestamp) {
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
Log.d(Config.LOGTAG, "requesting verification for " + PhoneNumberUtilWrapper.normalize(service, phoneNumber));
@ -194,7 +204,13 @@ public class QuickConversationsService extends AbstractQuickConversationsService
if (code == 200) {
account.setOption(Account.OPTION_UNVERIFIED, false);
account.setOption(Account.OPTION_DISABLED, false);
awaitingAccountStateChange = new CountDownLatch(1);
service.updateAccount(account);
try {
awaitingAccountStateChange.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": timer expired while waiting for account to connect");
}
synchronized (mOnVerification) {
for (OnVerification onVerification : mOnVerification) {
onVerification.onVerificationSucceeded();
@ -323,7 +339,6 @@ public class QuickConversationsService extends AbstractQuickConversationsService
query.setTo(syncServer);
Element book = new Element("phone-book", Namespace.SYNCHRONIZATION).setChildren(entries);
String statusQuo = Entry.statusQuo(contacts.values(), account.getRoster().getWithSystemAccounts(PhoneNumberContact.class));
Log.d(Config.LOGTAG,"status quo="+statusQuo);
book.setAttribute("ver", statusQuo);
query.addChild(book);
mLastSyncAttempt = Attempt.create(hash);
@ -363,6 +378,22 @@ public class QuickConversationsService extends AbstractQuickConversationsService
}
public interface OnVerificationRequested {
void onVerificationRequestFailed(int code);
void onVerificationRequested();
void onVerificationRequestedRetryAt(long timestamp);
}
public interface OnVerification {
void onVerificationFailed(int code);
void onVerificationSucceeded();
void onVerificationRetryAt(long timestamp);
}
private static class Attempt {
private final long timestamp;
private int hash;
@ -380,20 +411,4 @@ public class QuickConversationsService extends AbstractQuickConversationsService
return hash != this.hash || SystemClock.elapsedRealtime() - timestamp >= Config.CONTACT_SYNC_RETRY_INTERVAL;
}
}
public interface OnVerificationRequested {
void onVerificationRequestFailed(int code);
void onVerificationRequested();
void onVerificationRequestedRetryAt(long timestamp);
}
public interface OnVerification {
void onVerificationFailed(int code);
void onVerificationSucceeded();
void onVerificationRetryAt(long timestamp);
}
}