Improved watchdog

pull/160/head
M66B 6 years ago
parent 952d93bf17
commit f59adf17f5

@ -81,9 +81,11 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
@Override @Override
protected void onExecuted(Bundle args, Boolean hasAccounts) { protected void onExecuted(Bundle args, Boolean hasAccounts) {
if (hasAccounts) if (hasAccounts) {
startActivity(new Intent(ActivityMain.this, ActivityView.class)); startActivity(new Intent(ActivityMain.this, ActivityView.class));
else ServiceSynchronize.watchdog(ActivityMain.this);
ServiceSend.watchdog(ActivityMain.this);
} else
startActivity(new Intent(ActivityMain.this, ActivitySetup.class)); startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
finish(); finish();
} }

@ -455,4 +455,8 @@ public class ServiceSend extends ServiceBase {
ContextCompat.startForegroundService(context, ContextCompat.startForegroundService(context,
new Intent(context, ServiceSend.class)); new Intent(context, ServiceSend.class));
} }
static void watchdog(Context context) {
boot(context);
}
} }

@ -261,10 +261,6 @@ public class ServiceSynchronize extends ServiceBase {
if (action != null) if (action != null)
try { try {
switch (action) { switch (action) {
case "init":
onInit();
break;
case "alarm": case "alarm":
onAlarm(); onAlarm();
break; break;
@ -333,11 +329,6 @@ public class ServiceSynchronize extends ServiceBase {
return builder; return builder;
} }
private void onInit() {
EntityLog.log(this, "Service init");
// Network events will manage the service
}
private void onAlarm() { private void onAlarm() {
schedule(this); schedule(this);
onReload(true, "alarm"); onReload(true, "alarm");
@ -1437,14 +1428,9 @@ public class ServiceSynchronize extends ServiceBase {
schedule(context); schedule(context);
// Conditionally init service // Conditionally init service
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
int accounts = db.account().getSynchronizingAccounts().size(); int accounts = db.account().getSynchronizingAccounts().size();
if (enabled && pollInterval == 0 && accounts > 0) if (accounts > 0)
ContextCompat.startForegroundService(context, watchdog(context);
new Intent(context, ServiceSynchronize.class)
.setAction("init"));
else { else {
for (EntityAccount account : db.account().getAccounts()) for (EntityAccount account : db.account().getAccounts())
db.account().setAccountState(account.id, null); db.account().setAccountState(account.id, null);

@ -45,6 +45,7 @@ public class WorkerWatchdog extends Worker {
public Result doWork() { public Result doWork() {
Log.i("Running " + getName()); Log.i("Running " + getName());
ServiceSynchronize.watchdog(getApplicationContext()); ServiceSynchronize.watchdog(getApplicationContext());
ServiceSend.watchdog(getApplicationContext());
return Result.success(); return Result.success();
} }

Loading…
Cancel
Save