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,8 +66,9 @@ 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);
|
||||||
|
|
||||||
QuickConversationsService(XmppConnectionService xmppConnectionService) {
|
QuickConversationsService(XmppConnectionService xmppConnectionService) {
|
||||||
super(xmppConnectionService);
|
super(xmppConnectionService);
|
||||||
|
@ -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();
|
||||||
|
@ -282,7 +298,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(Account account, Collection<PhoneNumberContact> contacts) {
|
private void refresh(Account account, Collection<PhoneNumberContact> contacts) {
|
||||||
for(Contact contact : account.getRoster().getWithSystemAccounts(PhoneNumberContact.class)) {
|
for (Contact contact : account.getRoster().getWithSystemAccounts(PhoneNumberContact.class)) {
|
||||||
final Uri uri = contact.getSystemAccount();
|
final Uri uri = contact.getSystemAccount();
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -293,7 +309,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
needsCacheClean = contact.setPhoneContact(phoneNumberContact);
|
needsCacheClean = contact.setPhoneContact(phoneNumberContact);
|
||||||
} else {
|
} else {
|
||||||
needsCacheClean = contact.unsetPhoneContact(PhoneNumberContact.class);
|
needsCacheClean = contact.unsetPhoneContact(PhoneNumberContact.class);
|
||||||
Log.d(Config.LOGTAG,uri.toString()+" vanished from address book");
|
Log.d(Config.LOGTAG, uri.toString() + " vanished from address book");
|
||||||
}
|
}
|
||||||
if (needsCacheClean) {
|
if (needsCacheClean) {
|
||||||
service.getAvatarService().clear(contact);
|
service.getAvatarService().clear(contact);
|
||||||
|
@ -303,9 +319,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
|
|
||||||
private boolean considerSync(Account account, final Map<String, PhoneNumberContact> contacts) {
|
private boolean considerSync(Account account, final Map<String, PhoneNumberContact> contacts) {
|
||||||
final int hash = contacts.keySet().hashCode();
|
final int hash = contacts.keySet().hashCode();
|
||||||
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": consider sync of "+hash);
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": consider sync of " + hash);
|
||||||
if (!mLastSyncAttempt.retry(hash)) {
|
if (!mLastSyncAttempt.retry(hash)) {
|
||||||
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": do not attempt sync");
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not attempt sync");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
XmppConnection xmppConnection = account.getXmppConnection();
|
XmppConnection xmppConnection = account.getXmppConnection();
|
||||||
|
@ -323,8 +339,7 @@ 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);
|
||||||
service.sendIqPacket(account, query, (a, response) -> {
|
service.sendIqPacket(account, query, (a, response) -> {
|
||||||
|
@ -332,12 +347,12 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
final Element phoneBook = response.findChild("phone-book", Namespace.SYNCHRONIZATION);
|
final Element phoneBook = response.findChild("phone-book", Namespace.SYNCHRONIZATION);
|
||||||
if (phoneBook != null) {
|
if (phoneBook != null) {
|
||||||
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(PhoneNumberContact.class);
|
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(PhoneNumberContact.class);
|
||||||
for(Entry entry : Entry.ofPhoneBook(phoneBook)) {
|
for (Entry entry : Entry.ofPhoneBook(phoneBook)) {
|
||||||
PhoneNumberContact phoneContact = contacts.get(entry.getNumber());
|
PhoneNumberContact phoneContact = contacts.get(entry.getNumber());
|
||||||
if (phoneContact == null) {
|
if (phoneContact == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for(Jid jid : entry.getJids()) {
|
for (Jid jid : entry.getJids()) {
|
||||||
Contact contact = account.getRoster().getContact(jid);
|
Contact contact = account.getRoster().getContact(jid);
|
||||||
final boolean needsCacheClean = contact.setPhoneContact(phoneContact);
|
final boolean needsCacheClean = contact.setPhoneContact(phoneContact);
|
||||||
if (needsCacheClean) {
|
if (needsCacheClean) {
|
||||||
|
@ -353,7 +368,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": phone number contact list remains unchanged");
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": phone number contact list remains unchanged");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service.syncRoster(account);
|
service.syncRoster(account);
|
||||||
|
@ -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