Prevent crash

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

@ -166,6 +166,7 @@ public class WorkerCleanup extends Worker {
}
static void queue(Context context) {
try {
Log.i("Queuing " + getName() + " every " + CLEANUP_INTERVAL + " hours");
PeriodicWorkRequest workRequest =
@ -175,12 +176,20 @@ public class WorkerCleanup extends Worker {
.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) {
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,6 +47,7 @@ public class WorkerPoll extends Worker {
}
static void init(Context context) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
@ -65,6 +66,10 @@ public class WorkerPoll extends Worker {
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}
private static String getName() {

@ -49,6 +49,7 @@ public class WorkerWatchdog extends Worker {
}
static void init(Context context) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean watchdog = prefs.getBoolean("watchdog", true);
if (watchdog) {
@ -66,6 +67,10 @@ public class WorkerWatchdog extends Worker {
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}
private static String getName() {

Loading…
Cancel
Save