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
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 long CONTACT_SYNC_RETRY_INTERVAL = 1000L * 60 * 1;
public static final long CONTACT_SYNC_RETRY_INTERVAL = 1000L * 60 * 5;
//Notification settings

View File

@ -24,5 +24,5 @@ public abstract class AbstractQuickConversationsService {
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();
mJingleConnectionManager.cancelInTransmission();
mQuickConversationsService.considerSync();
mQuickConversationsService.considerSyncBackground(false);
fetchRosterFromServer(account);
if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
fetchBookmarks(account);

View File

@ -728,7 +728,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
@Override
protected void onBackendConnected() {
xmppConnectionService.getQuickConversationsService().considerSync();
xmppConnectionService.getQuickConversationsService().considerSyncBackground(false);
if (mPostponedActivityResult != null) {
onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
this.mPostponedActivityResult = null;
@ -1008,7 +1008,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
public void onRefresh() {
Log.d(Config.LOGTAG,"user requested to refresh");
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.CryptoHelper;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import eu.siacs.conversations.utils.SerialSingleThreadExecutor;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
@ -58,9 +59,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService
public static final int API_ERROR_SSL_HANDSHAKE = -4;
public static final int API_ERROR_AIRPLANE_MODE = -5;
private static final String API_DOMAIN = "api."+Config.QUICKSY_DOMAIN;
private static final String API_DOMAIN = "api." + Config.QUICKSY_DOMAIN;
private static final String BASE_URL = "https://"+API_DOMAIN;
private static final String BASE_URL = "https://" + API_DOMAIN;
private static final String INSTALLATION_ID = "eu.siacs.conversations.installation-id";
@ -74,6 +75,8 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private Attempt mLastSyncAttempt = Attempt.NULL;
private final SerialSingleThreadExecutor mSerialSingleThreadExecutor = new SerialSingleThreadExecutor(QuickConversationsService.class.getSimpleName());
QuickConversationsService(XmppConnectionService xmppConnectionService) {
super(xmppConnectionService);
}
@ -296,7 +299,18 @@ public class QuickConversationsService extends AbstractQuickConversationsService
}
@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);
for (Account account : service.getAccounts()) {
refresh(account, contacts.values());
@ -378,7 +392,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
} else if (response.getType() == IqPacket.TYPE.TIMEOUT) {
mLastSyncAttempt = Attempt.NULL;
} else {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": failed to sync contact list with api server");
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": failed to sync contact list with api server");
}
mRunningSyncJobs.decrementAndGet();
service.syncRoster(account);
@ -408,7 +422,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private final long timestamp;
private int hash;
private static final Attempt NULL = new Attempt(0,0);
private static final Attempt NULL = new Attempt(0, 0);
private Attempt(long timestamp, int hash) {
this.timestamp = timestamp;