Prevent crash

pull/160/head
M66B 5 years ago
parent f544f485a8
commit d99f19f2b6

@ -166,21 +166,30 @@ public class WorkerCleanup extends Worker {
}
static void queue(Context context) {
Log.i("Queuing " + getName() + " every " + CLEANUP_INTERVAL + " hours");
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerCleanup.class, CLEANUP_INTERVAL, TimeUnit.HOURS)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
try {
Log.i("Queuing " + getName() + " every " + CLEANUP_INTERVAL + " hours");
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerCleanup.class, CLEANUP_INTERVAL, TimeUnit.HOURS)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}
static void cancel(Context context) {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
try {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
} catch (IllegalStateException ex) {
Log.w(ex);
}
}
private static String getName() {

@ -47,23 +47,28 @@ public class WorkerPoll extends Worker {
}
static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
if (enabled && pollInterval > 0) {
Log.i("Queuing " + getName() + " every " + pollInterval + " minutes");
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
if (enabled && pollInterval > 0) {
Log.i("Queuing " + getName() + " every " + pollInterval + " minutes");
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerPoll.class, pollInterval, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerPoll.class, pollInterval, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
} else {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
Log.i("Queued " + getName());
} else {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}

@ -49,22 +49,27 @@ public class WorkerWatchdog extends Worker {
}
static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean watchdog = prefs.getBoolean("watchdog", true);
if (watchdog) {
Log.i("Queuing " + getName() + " every " + WATCHDOG_INTERVAL + " minutes");
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean watchdog = prefs.getBoolean("watchdog", true);
if (watchdog) {
Log.i("Queuing " + getName() + " every " + WATCHDOG_INTERVAL + " minutes");
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerWatchdog.class, WATCHDOG_INTERVAL, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerWatchdog.class, WATCHDOG_INTERVAL, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
} else {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
Log.i("Queued " + getName());
} else {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}

Loading…
Cancel
Save