SyncWorker "soft error (max retries reached)" notification confusing for users (bitfireAT/davx5#353)

* Sync error notification dismiss

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* FIXME

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Added click intent

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Delayed error info

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Added tag for max retries

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Reduced priority

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Removed max retries tag

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Using account name as tag

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Added authority to notification tag

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Added account type to notification tag

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

* Changed priority to min

Signed-off-by: Arnau Mora <arnyminerz@proton.me>

---------

Signed-off-by: Arnau Mora <arnyminerz@proton.me>
This commit is contained in:
Arnau Mora 2023-08-24 16:28:18 +02:00 committed by Ricki Hirner
parent bd7b2714d2
commit 795ae49da4
No known key found for this signature in database
GPG key ID: 79A019FCAAEDD3AA

View file

@ -5,6 +5,7 @@
package at.bitfire.davdroid.syncadapter
import android.accounts.Account
import android.app.PendingIntent
import android.content.ContentProviderClient
import android.content.ContentResolver
import android.content.Context
@ -42,6 +43,7 @@ import androidx.work.WorkerParameters
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.settings.AccountSettings
import at.bitfire.davdroid.ui.DebugInfoActivity
import at.bitfire.davdroid.ui.NotificationUtils
import at.bitfire.davdroid.ui.NotificationUtils.notifyIfPossible
import at.bitfire.davdroid.ui.account.WifiPermissionsActivity
@ -360,6 +362,8 @@ class SyncWorker @AssistedInject constructor(
.putString("syncResultStats", result.stats.toString())
.build()
val softErrorNotificationTag = account.type + "-" + account.name + "-" + authority
// On soft errors the sync is retried a few times before considered failed
if (result.hasSoftError()) {
Logger.log.warning("Soft error while syncing: result=$result, stats=${result.stats}")
@ -371,6 +375,7 @@ class SyncWorker @AssistedInject constructor(
Logger.log.warning("Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS). Treating as failed")
notificationManager.notifyIfPossible(
softErrorNotificationTag,
NotificationUtils.NOTIFY_SYNC_ERROR,
NotificationUtils.newBuilder(applicationContext, NotificationUtils.CHANNEL_SYNC_IO_ERRORS)
.setSmallIcon(R.drawable.ic_sync_problem_notify)
@ -378,7 +383,7 @@ class SyncWorker @AssistedInject constructor(
.setContentText(applicationContext.getString(R.string.sync_error_retry_limit_reached))
.setSubText(account.name)
.setOnlyAlertOnce(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.build()
)
@ -386,6 +391,12 @@ class SyncWorker @AssistedInject constructor(
return Result.failure(syncResult)
}
// If no soft error found, dismiss sync error notification
notificationManager.cancel(
softErrorNotificationTag,
NotificationUtils.NOTIFY_SYNC_ERROR
)
// On a hard error - fail with an error message
// Note: SyncManager should have notified the user
if (result.hasHardError()) {