Skip sync on oneshot operation

pull/159/head
M66B 6 years ago
parent 24ac579b1c
commit 7f9b4fc2b5

@ -229,7 +229,7 @@ public class EntityOperation {
if (SEND.equals(name)) if (SEND.equals(name))
ServiceSend.start(context); ServiceSend.start(context);
else else
ServiceSynchronize.process(context); ServiceSynchronize.process(context, false);
} }
static void sync(Context context, long fid, boolean foreground) { static void sync(Context context, long fid, boolean foreground) {
@ -258,7 +258,7 @@ public class EntityOperation {
if (folder.account == null) // Outbox if (folder.account == null) // Outbox
ServiceSend.start(context); ServiceSend.start(context);
else if (foreground) else if (foreground)
ServiceSynchronize.process(context); ServiceSynchronize.process(context, true);
} }
static void subscribe(Context context, long fid, boolean subscribe) { static void subscribe(Context context, long fid, boolean subscribe) {

@ -334,7 +334,7 @@ public class FragmentFolders extends FragmentBase {
if (enabled) if (enabled)
ServiceSynchronize.reload(context, "refresh folders"); ServiceSynchronize.reload(context, "refresh folders");
else else
ServiceSynchronize.process(context); ServiceSynchronize.process(context, true);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();

@ -101,6 +101,7 @@ public class ServiceSynchronize extends LifecycleService {
private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
private static boolean booted = false; private static boolean booted = false;
private static boolean sync = true;
private static boolean oneshot = false; private static boolean oneshot = false;
private static final int CONNECT_BACKOFF_START = 8; // seconds private static final int CONNECT_BACKOFF_START = 8; // seconds
@ -406,7 +407,7 @@ public class ServiceSynchronize extends LifecycleService {
if (doStart) { if (doStart) {
if (clear) if (clear)
db.account().clearAccountConnected(); db.account().clearAccountConnected();
start(); start(!oneshot || sync);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
@ -442,7 +443,7 @@ public class ServiceSynchronize extends LifecycleService {
return ((enabled && pollInterval == 0) || oneshot); return ((enabled && pollInterval == 0) || oneshot);
} }
private void start() { private void start(final boolean sync) {
EntityLog.log(this, "Main start"); EntityLog.log(this, "Main start");
state = new Core.State(networkState); state = new Core.State(networkState);
@ -486,7 +487,7 @@ public class ServiceSynchronize extends LifecycleService {
@Override @Override
public void run() { public void run() {
try { try {
monitorAccount(account, astate); monitorAccount(account, astate, sync);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(account.name, ex); Log.e(account.name, ex);
} }
@ -549,7 +550,7 @@ public class ServiceSynchronize extends LifecycleService {
stopSelf(); 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 pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wlAccount = pm.newWakeLock( final PowerManager.WakeLock wlAccount = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id);
@ -988,7 +989,8 @@ public class ServiceSynchronize extends LifecycleService {
idler.start(); idler.start();
idlers.add(idler); idlers.add(idler);
EntityOperation.sync(this, folder.id, false); if (sync)
EntityOperation.sync(this, folder.id, false);
} else } else
mapFolders.put(folder, null); mapFolders.put(folder, null);
@ -1509,11 +1511,12 @@ public class ServiceSynchronize extends LifecycleService {
.setAction("reset")); .setAction("reset"));
} }
static void process(Context context) { static void process(Context context, boolean sync) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true); boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0); int pollInterval = prefs.getInt("poll_interval", 0);
if (!enabled || pollInterval > 0) { if (!enabled || pollInterval > 0) {
ServiceSynchronize.sync = sync;
oneshot = true; oneshot = true;
ContextCompat.startForegroundService(context, ContextCompat.startForegroundService(context,
new Intent(context, ServiceSynchronize.class) new Intent(context, ServiceSynchronize.class)

@ -42,7 +42,7 @@ public class WorkerPoll extends Worker {
@Override @Override
public Result doWork() { public Result doWork() {
Log.i("Running " + getName()); Log.i("Running " + getName());
ServiceSynchronize.process(getApplicationContext()); ServiceSynchronize.process(getApplicationContext(), true);
return Result.success(); return Result.success();
} }

Loading…
Cancel
Save