added count down latch to await account connect before going into publish profile activity
This commit is contained in:
parent
fe45a7afcc
commit
19e13115d3
|
@ -10,4 +10,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
public void considerSync() {
|
public void considerSync() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void signalAccountStateChange() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,4 +19,6 @@ public abstract class AbstractQuickConversationsService {
|
||||||
public static boolean isConversations() {
|
public static boolean isConversations() {
|
||||||
return "conversations".equals(BuildConfig.FLAVOR_mode);
|
return "conversations".equals(BuildConfig.FLAVOR_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void signalAccountStateChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,6 +322,11 @@ public class XmppConnectionService extends Service {
|
||||||
public void onStatusChanged(final Account account) {
|
public void onStatusChanged(final Account account) {
|
||||||
XmppConnection connection = account.getXmppConnection();
|
XmppConnection connection = account.getXmppConnection();
|
||||||
updateAccountUi();
|
updateAccountUi();
|
||||||
|
|
||||||
|
if (account.getStatus() == Account.State.ONLINE || account.getStatus().isError()) {
|
||||||
|
mQuickConversationsService.signalAccountStateChange();
|
||||||
|
}
|
||||||
|
|
||||||
if (account.getStatus() == Account.State.ONLINE) {
|
if (account.getStatus() == Account.State.ONLINE) {
|
||||||
synchronized (mLowPingTimeoutMode) {
|
synchronized (mLowPingTimeoutMode) {
|
||||||
if (mLowPingTimeoutMode.remove(account.getJid().asBareJid())) {
|
if (mLowPingTimeoutMode.remove(account.getJid().asBareJid())) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -10,7 +9,6 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
|
||||||
import eu.siacs.conversations.android.PhoneNumberContact;
|
import eu.siacs.conversations.android.PhoneNumberContact;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import rocks.xmpp.addr.Jid;
|
import rocks.xmpp.addr.Jid;
|
||||||
|
@ -71,7 +69,6 @@ public class Entry implements Comparable<Entry> {
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG,"status quo string: "+builder.toString());
|
|
||||||
byte[] sha1 = md.digest(builder.toString().getBytes());
|
byte[] sha1 = md.digest(builder.toString().getBytes());
|
||||||
return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
|
return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
@ -64,6 +66,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
|
|
||||||
private final AtomicBoolean mVerificationInProgress = new AtomicBoolean(false);
|
private final AtomicBoolean mVerificationInProgress = new AtomicBoolean(false);
|
||||||
private final AtomicBoolean mVerificationRequestInProgress = new AtomicBoolean(false);
|
private final AtomicBoolean mVerificationRequestInProgress = new AtomicBoolean(false);
|
||||||
|
private CountDownLatch awaitingAccountStateChange;
|
||||||
|
|
||||||
private Attempt mLastSyncAttempt = new Attempt(0, 0);
|
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) {
|
private void createAccountAndWait(Phonenumber.PhoneNumber phoneNumber, final long timestamp) {
|
||||||
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
|
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
|
||||||
Log.d(Config.LOGTAG, "requesting verification for " + 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) {
|
if (code == 200) {
|
||||||
account.setOption(Account.OPTION_UNVERIFIED, false);
|
account.setOption(Account.OPTION_UNVERIFIED, false);
|
||||||
account.setOption(Account.OPTION_DISABLED, false);
|
account.setOption(Account.OPTION_DISABLED, false);
|
||||||
|
awaitingAccountStateChange = new CountDownLatch(1);
|
||||||
service.updateAccount(account);
|
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) {
|
synchronized (mOnVerification) {
|
||||||
for (OnVerification onVerification : mOnVerification) {
|
for (OnVerification onVerification : mOnVerification) {
|
||||||
onVerification.onVerificationSucceeded();
|
onVerification.onVerificationSucceeded();
|
||||||
|
@ -323,7 +339,6 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
query.setTo(syncServer);
|
query.setTo(syncServer);
|
||||||
Element book = new Element("phone-book", Namespace.SYNCHRONIZATION).setChildren(entries);
|
Element book = new Element("phone-book", Namespace.SYNCHRONIZATION).setChildren(entries);
|
||||||
String statusQuo = Entry.statusQuo(contacts.values(), account.getRoster().getWithSystemAccounts(PhoneNumberContact.class));
|
String statusQuo = Entry.statusQuo(contacts.values(), account.getRoster().getWithSystemAccounts(PhoneNumberContact.class));
|
||||||
Log.d(Config.LOGTAG,"status quo="+statusQuo);
|
|
||||||
book.setAttribute("ver", statusQuo);
|
book.setAttribute("ver", statusQuo);
|
||||||
query.addChild(book);
|
query.addChild(book);
|
||||||
mLastSyncAttempt = Attempt.create(hash);
|
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 static class Attempt {
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private int hash;
|
private int hash;
|
||||||
|
@ -380,20 +411,4 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
return hash != this.hash || SystemClock.elapsedRealtime() - timestamp >= Config.CONTACT_SYNC_RETRY_INTERVAL;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue