change sync interval on change in code
This commit is contained in:
@@ -11,6 +11,7 @@ import android.content.ContentProviderClient;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.PeriodicSync;
|
||||
import android.content.SyncResult;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -529,6 +530,10 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new sync if one does not exist, or updates an existing sync if the sync interval
|
||||
* has changed.
|
||||
*/
|
||||
public static void enableKeyserverSync(Context context) {
|
||||
Account account = KeychainApplication.createAccountIfNecessary(context);
|
||||
|
||||
@@ -539,12 +544,26 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
|
||||
ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1);
|
||||
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY, true);
|
||||
ContentResolver.addPeriodicSync(
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY,
|
||||
new Bundle(),
|
||||
SYNC_INTERVAL
|
||||
);
|
||||
|
||||
boolean intervalChanged = false;
|
||||
boolean syncExists = Preferences.getKeyserverSyncEnabled(context);
|
||||
|
||||
if (syncExists) {
|
||||
long oldInterval = ContentResolver.getPeriodicSyncs(
|
||||
account, Constants.PROVIDER_AUTHORITY).get(0).period;
|
||||
if (oldInterval != SYNC_INTERVAL) {
|
||||
intervalChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!syncExists || intervalChanged) {
|
||||
ContentResolver.addPeriodicSync(
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY,
|
||||
new Bundle(),
|
||||
SYNC_INTERVAL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSyncEnabled() {
|
||||
|
||||
Reference in New Issue
Block a user