From b3ba43a21a2d963fa68dfa71ab6e46ff9318d8b7 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 20 Mar 2024 14:45:35 +0600 Subject: [PATCH] fix: Add network constrain on RefreshCollectionWorker RefreshCollectionWorker has no network constrain defined but it makes networks requests. So the job can fail if it runs when no network is present. issue: https://gitlab.e.foundation/e/backlog/-/issues/7421 --- .../davdroid/servicedetection/RefreshCollectionsWorker.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt index 8efd63168..45aea5d2f 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt @@ -13,9 +13,11 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.hilt.work.HiltWorker import androidx.lifecycle.map +import androidx.work.Constraints import androidx.work.Data import androidx.work.ExistingWorkPolicy import androidx.work.ForegroundInfo +import androidx.work.NetworkType import androidx.work.OneTimeWorkRequestBuilder import androidx.work.OutOfQuotaPolicy import androidx.work.WorkInfo @@ -139,9 +141,15 @@ class RefreshCollectionsWorker @AssistedInject constructor( val arguments = Data.Builder() .putLong(ARG_SERVICE_ID, serviceId) .build() + + val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .build() + val workRequest = OneTimeWorkRequestBuilder() .setInputData(arguments) .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) + .setConstraints(constraints) .build() WorkManager.getInstance(context).enqueueUniqueWork( -- GitLab