Sync: handle permission denied sync errors.

pull/131/head
Tom Hacohen 4 years ago
parent 5f8ca4326b
commit 2417f77a39

@ -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)
}

@ -359,6 +359,7 @@
<string name="sync_error_unavailable">Could not connect to server while %s</string>
<string name="sync_error_local_storage">Database error while %s</string>
<string name="sync_error_journal_readonly">Journal is read only</string>
<string name="sync_error_permission_denied">Permission denied: %s</string>
<string name="sync_phase_prepare">preparing synchronization</string>
<string name="sync_phase_journals">syncronizing journals</string>
<string name="sync_phase_prepare_fetch">preparing for fetch</string>

Loading…
Cancel
Save