From 2417f77a39d9de76d8e60b61aa38cb77c26643ab Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 3 Sep 2020 08:32:39 +0300 Subject: [PATCH] Sync: handle permission denied sync errors. --- .../syncadapter/SyncNotification.kt | 31 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt index 11f55848..0c478331 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt @@ -11,6 +11,7 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import at.bitfire.ical4android.CalendarStorageException import at.bitfire.vcard4android.ContactsStorageException +import com.etebase.client.exceptions.* import com.etesync.syncadapter.AccountSettings import com.etesync.syncadapter.Constants import com.etesync.syncadapter.R @@ -27,7 +28,8 @@ class SyncNotification(internal val context: Context, internal val notificationT internal val notificationManager: NotificationManagerCompat lateinit var detailsIntent: Intent internal set - internal var messageString: Int = 0 + internal var messageInt: Int = 0 + internal var messageString: String? = null private var throwable: Throwable? = null @@ -37,30 +39,33 @@ class SyncNotification(internal val context: Context, internal val notificationT fun setThrowable(e: Throwable) { throwable = e - if (e is Exceptions.UnauthorizedException) { + if (e is Exceptions.UnauthorizedException || e is UnauthorizedException) { Logger.log.log(Level.SEVERE, "Not authorized anymore", e) - messageString = R.string.sync_error_unauthorized + messageInt = R.string.sync_error_unauthorized } else if (e is Exceptions.UserInactiveException) { Logger.log.log(Level.SEVERE, "User inactive") - messageString = R.string.sync_error_user_inactive - } else if (e is Exceptions.ServiceUnavailableException) { + messageInt = R.string.sync_error_user_inactive + } else if (e is Exceptions.ServiceUnavailableException || e is TemporaryServerErrorException) { Logger.log.log(Level.SEVERE, "Service unavailable") - messageString = R.string.sync_error_unavailable + messageInt = R.string.sync_error_unavailable } else if (e is Exceptions.ReadOnlyException) { Logger.log.log(Level.SEVERE, "Journal is read only", e) - messageString = R.string.sync_error_journal_readonly - } else if (e is Exceptions.HttpException) { + messageInt = R.string.sync_error_journal_readonly + } else if (e is PermissionDeniedException) { + Logger.log.log(Level.SEVERE, "Permission denied", e) + messageString = context.getString(R.string.sync_error_permission_denied, e.localizedMessage) + } else if (e is Exceptions.HttpException || e is ServerErrorException) { Logger.log.log(Level.SEVERE, "HTTP Exception during sync", e) - messageString = R.string.sync_error_http_dav + messageInt = R.string.sync_error_http_dav } else if (e is CalendarStorageException || e is ContactsStorageException || e is SQLiteException) { Logger.log.log(Level.SEVERE, "Couldn't access local storage", e) - messageString = R.string.sync_error_local_storage + messageInt = R.string.sync_error_local_storage } else if (e is Exceptions.IntegrityException) { Logger.log.log(Level.SEVERE, "Integrity error", e) - messageString = R.string.sync_error_integrity + messageInt = R.string.sync_error_integrity } else { Logger.log.log(Level.SEVERE, "Unknown sync error", e) - messageString = R.string.sync_error + messageInt = R.string.sync_error } detailsIntent = Intent(context, NotificationHandlerActivity::class.java) @@ -69,7 +74,7 @@ class SyncNotification(internal val context: Context, internal val notificationT } fun notify(title: String, state: String) { - val message = context.getString(messageString, state) + val message = messageString ?: context.getString(messageInt, state) notify(title, message, null, detailsIntent) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 388ff1c6..49d5e0b9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -359,6 +359,7 @@ Could not connect to server while %s Database error while %s Journal is read only + Permission denied: %s preparing synchronization syncronizing journals preparing for fetch