mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-30 21:58:52 +02:00
Added watchdog
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user