always do contact sync in background

This commit is contained in:
Daniel Gultsch 2018-11-07 15:44:39 +01:00
parent 8a67f31368
commit 5be43e36e4
6 changed files with 25 additions and 11 deletions

View file

@ -22,7 +22,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
} }
@Override @Override
public void considerSync(boolean force) { public void considerSyncBackground(boolean force) {
} }
} }

View file

@ -48,7 +48,7 @@ public final class Config {
public static final boolean ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true public static final boolean ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true
public static final long CONTACT_SYNC_RETRY_INTERVAL = 1000L * 60 * 1; public static final long CONTACT_SYNC_RETRY_INTERVAL = 1000L * 60 * 5;
//Notification settings //Notification settings

View file

@ -24,5 +24,5 @@ public abstract class AbstractQuickConversationsService {
public abstract boolean isSynchronizing(); public abstract boolean isSynchronizing();
public abstract void considerSync(boolean force); public abstract void considerSyncBackground(boolean force);
} }

View file

@ -292,7 +292,7 @@ public class XmppConnectionService extends Service {
} }
account.getRoster().clearPresences(); account.getRoster().clearPresences();
mJingleConnectionManager.cancelInTransmission(); mJingleConnectionManager.cancelInTransmission();
mQuickConversationsService.considerSync(); mQuickConversationsService.considerSyncBackground(false);
fetchRosterFromServer(account); fetchRosterFromServer(account);
if (!account.getXmppConnection().getFeatures().bookmarksConversion()) { if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
fetchBookmarks(account); fetchBookmarks(account);

View file

@ -728,7 +728,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
xmppConnectionService.getQuickConversationsService().considerSync(); xmppConnectionService.getQuickConversationsService().considerSyncBackground(false);
if (mPostponedActivityResult != null) { if (mPostponedActivityResult != null) {
onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
this.mPostponedActivityResult = null; this.mPostponedActivityResult = null;
@ -1008,7 +1008,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
public void onRefresh() { public void onRefresh() {
Log.d(Config.LOGTAG,"user requested to refresh"); Log.d(Config.LOGTAG,"user requested to refresh");
if (QuickConversationsService.isQuicksy() && xmppConnectionService != null) { if (QuickConversationsService.isQuicksy() && xmppConnectionService != null) {
xmppConnectionService.getQuickConversationsService().considerSync(true); xmppConnectionService.getQuickConversationsService().considerSyncBackground(true);
} }
} }

View file

@ -41,6 +41,7 @@ import eu.siacs.conversations.entities.Entry;
import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper; import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import eu.siacs.conversations.utils.SerialSingleThreadExecutor;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.OnIqPacketReceived; import eu.siacs.conversations.xmpp.OnIqPacketReceived;
@ -74,6 +75,8 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private Attempt mLastSyncAttempt = Attempt.NULL; private Attempt mLastSyncAttempt = Attempt.NULL;
private final SerialSingleThreadExecutor mSerialSingleThreadExecutor = new SerialSingleThreadExecutor(QuickConversationsService.class.getSimpleName());
QuickConversationsService(XmppConnectionService xmppConnectionService) { QuickConversationsService(XmppConnectionService xmppConnectionService) {
super(xmppConnectionService); super(xmppConnectionService);
} }
@ -296,7 +299,18 @@ public class QuickConversationsService extends AbstractQuickConversationsService
} }
@Override @Override
public void considerSync(boolean forced) { public void considerSyncBackground(final boolean forced) {
mRunningSyncJobs.incrementAndGet();
mSerialSingleThreadExecutor.execute(() -> {
considerSync(forced);
if (mRunningSyncJobs.decrementAndGet() == 0) {
service.updateRosterUi();
}
});
}
private void considerSync(boolean forced) {
Map<String, PhoneNumberContact> contacts = PhoneNumberContact.load(service); Map<String, PhoneNumberContact> contacts = PhoneNumberContact.load(service);
for (Account account : service.getAccounts()) { for (Account account : service.getAccounts()) {
refresh(account, contacts.values()); refresh(account, contacts.values());