@@ -92,6 +92,9 @@ class SyncWorker @AssistedInject constructor(
92
92
internal const val ARG_ACCOUNT_TYPE = " accountType"
93
93
internal const val ARG_AUTHORITY = " authority"
94
94
95
+ /* * Boolean. Set to `true` when the job was requested as expedited job. */
96
+ private const val ARG_EXPEDITED = " expedited"
97
+
95
98
private const val ARG_UPLOAD = " upload"
96
99
97
100
private const val ARG_RESYNC = " resync"
@@ -163,6 +166,8 @@ class SyncWorker @AssistedInject constructor(
163
166
.putString(ARG_AUTHORITY , authority)
164
167
.putString(ARG_ACCOUNT_NAME , account.name)
165
168
.putString(ARG_ACCOUNT_TYPE , account.type)
169
+ if (expedited)
170
+ argumentsBuilder.putBoolean(ARG_EXPEDITED , true )
166
171
if (resync != NO_RESYNC )
167
172
argumentsBuilder.putInt(ARG_RESYNC , resync)
168
173
argumentsBuilder.putBoolean(ARG_UPLOAD , upload)
@@ -194,7 +199,7 @@ class SyncWorker @AssistedInject constructor(
194
199
// enqueue and start syncing
195
200
val name = workerName(account, authority)
196
201
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} " )
198
203
WorkManager .getInstance(context).enqueueUniqueWork(
199
204
name,
200
205
ExistingWorkPolicy .KEEP , // If sync is already running, just continue.
@@ -316,6 +321,7 @@ class SyncWorker @AssistedInject constructor(
316
321
inputData.getString(ARG_ACCOUNT_TYPE ) ? : throw IllegalArgumentException (" $ARG_ACCOUNT_TYPE required" )
317
322
)
318
323
val authority = inputData.getString(ARG_AUTHORITY ) ? : throw IllegalArgumentException (" $ARG_AUTHORITY required" )
324
+ val expedited = inputData.getBoolean(ARG_EXPEDITED , false )
319
325
320
326
// this is a long-running worker
321
327
try {
@@ -338,7 +344,7 @@ class SyncWorker @AssistedInject constructor(
338
344
// What are we going to sync? Select syncer based on authority
339
345
val syncer: Syncer = when (authority) {
340
346
applicationContext.getString(R .string.address_books_authority) ->
341
- AddressBookSyncer (applicationContext)
347
+ AddressBookSyncer (applicationContext, expedited )
342
348
CalendarContract .AUTHORITY ->
343
349
CalendarSyncer (applicationContext)
344
350
ContactsContract .AUTHORITY ->
@@ -456,11 +462,10 @@ class SyncWorker @AssistedInject constructor(
456
462
.setPriority(NotificationCompat .PRIORITY_LOW )
457
463
.setForegroundServiceBehavior(NotificationCompat .FOREGROUND_SERVICE_DEFERRED )
458
464
.build()
459
- return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
465
+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q )
460
466
ForegroundInfo (NotificationUtils .NOTIFY_SYNC_EXPEDITED , notification, ServiceInfo .FOREGROUND_SERVICE_TYPE_DATA_SYNC )
461
- } else {
467
+ else
462
468
ForegroundInfo (NotificationUtils .NOTIFY_SYNC_EXPEDITED , notification)
463
- }
464
469
}
465
470
466
471
}
0 commit comments