Skip to content

Commit faf0648

Browse files
committed
Add foreground notification type to potentially expedited workers (required for Android 14)
1 parent a7f6192 commit faf0648

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import android.accounts.Account
88
import android.app.PendingIntent
99
import android.content.Context
1010
import android.content.Intent
11+
import android.content.pm.ServiceInfo
12+
import android.os.Build
1113
import androidx.core.app.NotificationCompat
1214
import androidx.core.app.NotificationManagerCompat
1315
import androidx.hilt.work.HiltWorker
@@ -248,7 +250,11 @@ class RefreshCollectionsWorker @AssistedInject constructor(
248250
.setOngoing(true)
249251
.setPriority(NotificationCompat.PRIORITY_LOW)
250252
.build()
251-
return ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
253+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
254+
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
255+
} else {
256+
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
257+
}
252258
}
253259

254260
private fun notifyRefreshError(contentText: String, contentIntent: Intent) {
@@ -574,4 +580,4 @@ class RefreshCollectionsWorker @AssistedInject constructor(
574580
}
575581
}
576582

577-
}
583+
}

app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import android.content.ContentResolver
1010
import android.content.Context
1111
import android.content.Intent
1212
import android.content.SyncResult
13+
import android.content.pm.ServiceInfo
1314
import android.net.ConnectivityManager
1415
import android.net.wifi.WifiManager
16+
import android.os.Build
1517
import android.provider.CalendarContract
1618
import android.provider.ContactsContract
1719
import androidx.annotation.IntDef
@@ -436,7 +438,11 @@ class SyncWorker @AssistedInject constructor(
436438
.setOngoing(true)
437439
.setPriority(NotificationCompat.PRIORITY_LOW)
438440
.build()
439-
return ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
441+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
442+
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
443+
} else {
444+
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
445+
}
440446
}
441447

442448
}

0 commit comments

Comments
 (0)