mirror of https://github.com/M66B/FairEmail.git
Skip sync on oneshot operation
This commit is contained in:
parent
24ac579b1c
commit
7f9b4fc2b5
|
@ -229,7 +229,7 @@ public class EntityOperation {
|
|||
if (SEND.equals(name))
|
||||
ServiceSend.start(context);
|
||||
else
|
||||
ServiceSynchronize.process(context);
|
||||
ServiceSynchronize.process(context, false);
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid, boolean foreground) {
|
||||
|
@ -258,7 +258,7 @@ public class EntityOperation {
|
|||
if (folder.account == null) // Outbox
|
||||
ServiceSend.start(context);
|
||||
else if (foreground)
|
||||
ServiceSynchronize.process(context);
|
||||
ServiceSynchronize.process(context, true);
|
||||
}
|
||||
|
||||
static void subscribe(Context context, long fid, boolean subscribe) {
|
||||
|
|
|
@ -334,7 +334,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
if (enabled)
|
||||
ServiceSynchronize.reload(context, "refresh folders");
|
||||
else
|
||||
ServiceSynchronize.process(context);
|
||||
ServiceSynchronize.process(context, true);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
|
|
@ -101,6 +101,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||
|
||||
private static boolean booted = false;
|
||||
private static boolean sync = true;
|
||||
private static boolean oneshot = false;
|
||||
|
||||
private static final int CONNECT_BACKOFF_START = 8; // seconds
|
||||
|
@ -406,7 +407,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
if (doStart) {
|
||||
if (clear)
|
||||
db.account().clearAccountConnected();
|
||||
start();
|
||||
start(!oneshot || sync);
|
||||
}
|
||||
|
||||
} catch (Throwable ex) {
|
||||
|
@ -442,7 +443,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
return ((enabled && pollInterval == 0) || oneshot);
|
||||
}
|
||||
|
||||
private void start() {
|
||||
private void start(final boolean sync) {
|
||||
EntityLog.log(this, "Main start");
|
||||
|
||||
state = new Core.State(networkState);
|
||||
|
@ -486,7 +487,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
monitorAccount(account, astate);
|
||||
monitorAccount(account, astate, sync);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(account.name, ex);
|
||||
}
|
||||
|
@ -549,7 +550,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
stopSelf();
|
||||
}
|
||||
|
||||
private void monitorAccount(final EntityAccount account, final Core.State state) throws NoSuchProviderException {
|
||||
private void monitorAccount(final EntityAccount account, final Core.State state, final boolean sync) throws NoSuchProviderException {
|
||||
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
final PowerManager.WakeLock wlAccount = pm.newWakeLock(
|
||||
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id);
|
||||
|
@ -988,6 +989,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
idler.start();
|
||||
idlers.add(idler);
|
||||
|
||||
if (sync)
|
||||
EntityOperation.sync(this, folder.id, false);
|
||||
} else
|
||||
mapFolders.put(folder, null);
|
||||
|
@ -1509,11 +1511,12 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
.setAction("reset"));
|
||||
}
|
||||
|
||||
static void process(Context context) {
|
||||
static void process(Context context, boolean sync) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean enabled = prefs.getBoolean("enabled", true);
|
||||
int pollInterval = prefs.getInt("poll_interval", 0);
|
||||
if (!enabled || pollInterval > 0) {
|
||||
ServiceSynchronize.sync = sync;
|
||||
oneshot = true;
|
||||
ContextCompat.startForegroundService(context,
|
||||
new Intent(context, ServiceSynchronize.class)
|
||||
|
|
|
@ -42,7 +42,7 @@ public class WorkerPoll extends Worker {
|
|||
@Override
|
||||
public Result doWork() {
|
||||
Log.i("Running " + getName());
|
||||
ServiceSynchronize.process(getApplicationContext());
|
||||
ServiceSynchronize.process(getApplicationContext(), true);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue