@@ -290,81 +290,68 @@ abstract class BaseSyncWorker(
290
290
// Comes in through SyncAdapterService and is used only by ContactsSyncManager for an Android 7 workaround.
291
291
extras.add(ContentResolver .SYNC_EXTRAS_UPLOAD )
292
292
293
- // acquire ContentProviderClient of authority to be synced
294
- try {
295
- applicationContext.contentResolver.acquireContentProviderClient(authority)
296
- } catch (e: SecurityException ) {
297
- Logger .log.log(Level .WARNING , " Missing permissions to acquire ContentProviderClient for $authority " , e)
298
- null
299
- }.use { provider ->
300
- if (provider == null ) {
301
- Logger .log.warning(" Couldn't acquire ContentProviderClient for $authority " )
302
- return @withContext Result .failure()
303
- }
304
-
305
- val result = SyncResult ()
306
- // Start syncing. We still use the sync adapter framework's SyncResult to pass the sync results, but this
307
- // is only for legacy reasons and can be replaced by an own result class in the future.
308
- runInterruptible {
309
- syncer.onPerformSync(account, extras.toTypedArray(), authority, provider, result)
310
- }
293
+ val result = SyncResult ()
294
+ // Start syncing. We still use the sync adapter framework's SyncResult to pass the sync results, but this
295
+ // is only for legacy reasons and can be replaced by an own result class in the future.
296
+ runInterruptible {
297
+ syncer.onPerformSync(account, extras.toTypedArray(), authority, result)
298
+ }
311
299
312
- // Check for errors
313
- if (result.hasError()) {
314
- val syncResult = Data .Builder ()
315
- .putString(" syncresult" , result.toString())
316
- .putString(" syncResultStats" , result.stats.toString())
317
- .build()
318
-
319
- val softErrorNotificationTag = account.type + " -" + account.name + " -" + authority
320
-
321
- // On soft errors the sync is retried a few times before considered failed
322
- if (result.hasSoftError()) {
323
- Logger .log.warning(" Soft error while syncing: result=$result , stats=${result.stats} " )
324
- if (runAttemptCount < MAX_RUN_ATTEMPTS ) {
325
- val blockDuration = result.delayUntil - System .currentTimeMillis() / 1000
326
- Logger .log.warning(" Waiting for $blockDuration seconds, before retrying ..." )
327
-
328
- // We block the SyncWorker here so that it won't be started by the sync framework immediately again.
329
- // This should be replaced by proper work scheduling as soon as we don't depend on the sync framework anymore.
330
- if (blockDuration > 0 )
331
- delay(blockDuration * 1000 )
332
-
333
- Logger .log.warning(" Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS )" )
334
- return @withContext Result .retry()
335
- }
336
-
337
- Logger .log.warning(" Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS ). Treating as failed" )
338
-
339
- notificationManager.notifyIfPossible(
340
- softErrorNotificationTag,
341
- NotificationUtils .NOTIFY_SYNC_ERROR ,
342
- NotificationUtils .newBuilder(applicationContext, NotificationUtils .CHANNEL_SYNC_IO_ERRORS )
343
- .setSmallIcon(R .drawable.ic_sync_problem_notify)
344
- .setContentTitle(account.name)
345
- .setContentText(applicationContext.getString(R .string.sync_error_retry_limit_reached))
346
- .setSubText(account.name)
347
- .setOnlyAlertOnce(true )
348
- .setPriority(NotificationCompat .PRIORITY_MIN )
349
- .setCategory(NotificationCompat .CATEGORY_ERROR )
350
- .build()
351
- )
352
-
353
- return @withContext Result .failure(syncResult)
300
+ // Check for errors
301
+ if (result.hasError()) {
302
+ val syncResult = Data .Builder ()
303
+ .putString(" syncresult" , result.toString())
304
+ .putString(" syncResultStats" , result.stats.toString())
305
+ .build()
306
+
307
+ val softErrorNotificationTag = account.type + " -" + account.name + " -" + authority
308
+
309
+ // On soft errors the sync is retried a few times before considered failed
310
+ if (result.hasSoftError()) {
311
+ Logger .log.warning(" Soft error while syncing: result=$result , stats=${result.stats} " )
312
+ if (runAttemptCount < MAX_RUN_ATTEMPTS ) {
313
+ val blockDuration = result.delayUntil - System .currentTimeMillis() / 1000
314
+ Logger .log.warning(" Waiting for $blockDuration seconds, before retrying ..." )
315
+
316
+ // We block the SyncWorker here so that it won't be started by the sync framework immediately again.
317
+ // This should be replaced by proper work scheduling as soon as we don't depend on the sync framework anymore.
318
+ if (blockDuration > 0 )
319
+ delay(blockDuration * 1000 )
320
+
321
+ Logger .log.warning(" Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS )" )
322
+ return @withContext Result .retry()
354
323
}
355
324
356
- // If no soft error found, dismiss sync error notification
357
- notificationManager.cancel(
325
+ Logger .log.warning(" Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS ). Treating as failed" )
326
+
327
+ notificationManager.notifyIfPossible(
358
328
softErrorNotificationTag,
359
- NotificationUtils .NOTIFY_SYNC_ERROR
329
+ NotificationUtils .NOTIFY_SYNC_ERROR ,
330
+ NotificationUtils .newBuilder(applicationContext, NotificationUtils .CHANNEL_SYNC_IO_ERRORS )
331
+ .setSmallIcon(R .drawable.ic_sync_problem_notify)
332
+ .setContentTitle(account.name)
333
+ .setContentText(applicationContext.getString(R .string.sync_error_retry_limit_reached))
334
+ .setSubText(account.name)
335
+ .setOnlyAlertOnce(true )
336
+ .setPriority(NotificationCompat .PRIORITY_MIN )
337
+ .setCategory(NotificationCompat .CATEGORY_ERROR )
338
+ .build()
360
339
)
361
340
362
- // On a hard error - fail with an error message
363
- // Note: SyncManager should have notified the user
364
- if (result.hasHardError()) {
365
- Logger .log.warning(" Hard error while syncing: result=$result , stats=${result.stats} " )
366
- return @withContext Result .failure(syncResult)
367
- }
341
+ return @withContext Result .failure(syncResult)
342
+ }
343
+
344
+ // If no soft error found, dismiss sync error notification
345
+ notificationManager.cancel(
346
+ softErrorNotificationTag,
347
+ NotificationUtils .NOTIFY_SYNC_ERROR
348
+ )
349
+
350
+ // On a hard error - fail with an error message
351
+ // Note: SyncManager should have notified the user
352
+ if (result.hasHardError()) {
353
+ Logger .log.warning(" Hard error while syncing: result=$result , stats=${result.stats} " )
354
+ return @withContext Result .failure(syncResult)
368
355
}
369
356
}
370
357
0 commit comments