Added watchdog

This commit is contained in:
M66B
2019-05-12 20:15:16 +02:00
parent d4da0bb223
commit a2c38bd234
6 changed files with 118 additions and 2 deletions

View File

@@ -222,6 +222,10 @@ public class ServiceSynchronize extends LifecycleService {
onOneshot(false);
break;
case "watchdog":
onWatchdog();
break;
default:
Log.w("Unknown action: " + action);
}
@@ -317,6 +321,11 @@ public class ServiceSynchronize extends LifecycleService {
onReload(true, "oneshot end");
}
private void onWatchdog() {
EntityLog.log(this, "Service watchdog");
// Network events will manage the service
}
private void queue_reload(final boolean start, final boolean clear, final String reason) {
final boolean doStop = started;
final boolean doStart = (start && isEnabled() && networkState.isSuitable());
@@ -1387,4 +1396,14 @@ public class ServiceSynchronize extends LifecycleService {
new Intent(context, ServiceSynchronize.class)
.setAction("oneshot_start"));
}
static void watchdog(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
if (enabled && pollInterval == 0)
ContextCompat.startForegroundService(context,
new Intent(context, ServiceSynchronize.class)
.setAction("watchdog"));
}
}