Merge pull request #3818 from deltachat/adb/tune-down-fetchworker

don't use FetchWorker if we have push notifications
This commit is contained in:
adb 2025-07-22 13:36:08 +00:00 committed by GitHub
commit 10345ab8c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -197,30 +197,30 @@ public class ApplicationContext extends MultiDexApplication {
}
}, filter);
// MAYBE TODO: i think the ApplicationContext is also created
// when the app is stated by FetchWorker timeouts.
// in this case, the normal threads shall not be started.
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
PeriodicWorkRequest fetchWorkRequest = new PeriodicWorkRequest.Builder(
FetchWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, // usually 15 minutes
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS, // the start may be preferred by up to 5 minutes, so we run every 10-15 minutes
TimeUnit.MILLISECONDS)
.setConstraints(constraints)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
"FetchWorker",
ExistingPeriodicWorkPolicy.KEEP,
fetchWorkRequest);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
if (Prefs.isPushEnabled(this)) {
FcmReceiveService.register(this);
} else {
Log.i(TAG, "FCM disabled at build time");
// MAYBE TODO: i think the ApplicationContext is also created
// when the app is stated by FetchWorker timeouts.
// in this case, the normal threads shall not be started.
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
PeriodicWorkRequest fetchWorkRequest = new PeriodicWorkRequest.Builder(
FetchWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, // usually 15 minutes
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS, // the start may be preferred by up to 5 minutes, so we run every 10-15 minutes
TimeUnit.MILLISECONDS)
.setConstraints(constraints)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
"FetchWorker",
ExistingPeriodicWorkPolicy.KEEP,
fetchWorkRequest);
}
}