Skip to content

Commit cc9b829

Browse files
committed
AddressBookSyncer: only request expedited for sub-jobs when parent job is expedited, too
1 parent c90de75 commit cc9b829

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,10 @@ class RefreshCollectionsWorker @AssistedInject constructor(
254254
.setOngoing(true)
255255
.setPriority(NotificationCompat.PRIORITY_LOW)
256256
.build()
257-
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
257+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
258258
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
259-
} else {
259+
else
260260
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
261-
}
262261
}
263262

264263
private fun notifyRefreshError(contentText: String, contentIntent: Intent) {

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import java.util.logging.Level
3030
/**
3131
* Sync logic for address books
3232
*/
33-
class AddressBookSyncer(context: Context) : Syncer(context) {
33+
class AddressBookSyncer(
34+
context: Context,
35+
private val expedited: Boolean
36+
) : Syncer(context) {
3437

3538
@EntryPoint
3639
@InstallIn(SingletonComponent::class)
@@ -53,9 +56,7 @@ class AddressBookSyncer(context: Context) : Syncer(context) {
5356
if (updateLocalAddressBooks(account, syncResult))
5457
for (addressBookAccount in LocalAddressBook.findAll(context, null, account).map { it.account }) {
5558
Logger.log.log(Level.INFO, "Running sync for address book", addressBookAccount)
56-
57-
// TODO: only run as expedited when this job is expedited
58-
SyncWorker.enqueue(context, addressBookAccount, ContactsContract.AUTHORITY, expedited = true)
59+
SyncWorker.enqueue(context, addressBookAccount, ContactsContract.AUTHORITY, expedited = expedited)
5960
}
6061
} catch (e: Exception) {
6162
Logger.log.log(Level.SEVERE, "Couldn't sync address books", e)

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class SyncWorker @AssistedInject constructor(
9292
internal const val ARG_ACCOUNT_TYPE = "accountType"
9393
internal const val ARG_AUTHORITY = "authority"
9494

95+
/** Boolean. Set to `true` when the job was requested as expedited job. */
96+
private const val ARG_EXPEDITED = "expedited"
97+
9598
private const val ARG_UPLOAD = "upload"
9699

97100
private const val ARG_RESYNC = "resync"
@@ -163,6 +166,8 @@ class SyncWorker @AssistedInject constructor(
163166
.putString(ARG_AUTHORITY, authority)
164167
.putString(ARG_ACCOUNT_NAME, account.name)
165168
.putString(ARG_ACCOUNT_TYPE, account.type)
169+
if (expedited)
170+
argumentsBuilder.putBoolean(ARG_EXPEDITED, true)
166171
if (resync != NO_RESYNC)
167172
argumentsBuilder.putInt(ARG_RESYNC, resync)
168173
argumentsBuilder.putBoolean(ARG_UPLOAD, upload)
@@ -194,7 +199,7 @@ class SyncWorker @AssistedInject constructor(
194199
// enqueue and start syncing
195200
val name = workerName(account, authority)
196201
val request = workRequest.build()
197-
Logger.log.log(Level.INFO, "Enqueueing unique worker: $name, with tags: ${request.tags}")
202+
Logger.log.log(Level.INFO, "Enqueueing unique worker: $name, expedited = $expedited, tags = ${request.tags}")
198203
WorkManager.getInstance(context).enqueueUniqueWork(
199204
name,
200205
ExistingWorkPolicy.KEEP, // If sync is already running, just continue.
@@ -316,6 +321,7 @@ class SyncWorker @AssistedInject constructor(
316321
inputData.getString(ARG_ACCOUNT_TYPE) ?: throw IllegalArgumentException("$ARG_ACCOUNT_TYPE required")
317322
)
318323
val authority = inputData.getString(ARG_AUTHORITY) ?: throw IllegalArgumentException("$ARG_AUTHORITY required")
324+
val expedited = inputData.getBoolean(ARG_EXPEDITED, false)
319325

320326
// this is a long-running worker
321327
try {
@@ -338,7 +344,7 @@ class SyncWorker @AssistedInject constructor(
338344
// What are we going to sync? Select syncer based on authority
339345
val syncer: Syncer = when (authority) {
340346
applicationContext.getString(R.string.address_books_authority) ->
341-
AddressBookSyncer(applicationContext)
347+
AddressBookSyncer(applicationContext, expedited)
342348
CalendarContract.AUTHORITY ->
343349
CalendarSyncer(applicationContext)
344350
ContactsContract.AUTHORITY ->
@@ -456,11 +462,10 @@ class SyncWorker @AssistedInject constructor(
456462
.setPriority(NotificationCompat.PRIORITY_LOW)
457463
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED)
458464
.build()
459-
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
465+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
460466
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
461-
} else {
467+
else
462468
ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)
463-
}
464469
}
465470

466471
}

0 commit comments

Comments
 (0)