From 143092ecf3ef393d58cbcc34c50f9b764d6e0e83 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 13 Feb 2019 18:41:21 +0000 Subject: [PATCH] Don't pop up notifications when server is under maintenance. --- .../com/etesync/syncadapter/journalmanager/Exceptions.kt | 6 +++++- .../syncadapter/AddressBooksSyncAdapterService.kt | 2 ++ .../syncadapter/syncadapter/CalendarsSyncAdapterService.kt | 2 ++ .../java/com/etesync/syncadapter/syncadapter/SyncManager.kt | 2 ++ .../syncadapter/syncadapter/TasksSyncAdapterService.kt | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.kt b/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.kt index 508189e9..bc359cc3 100644 --- a/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.kt +++ b/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.kt @@ -18,7 +18,7 @@ class Exceptions { class BadGatewayException(response: Response, message: String) : HttpException(response, message) - class ServiceUnavailableException : HttpException { + class ServiceUnavailableException : IgnorableHttpException { var retryAfter: Long = 0 constructor(message: String) : super(message) { @@ -32,6 +32,10 @@ class Exceptions { class IntegrityException(message: String) : GeneralSecurityException(message) + open class IgnorableHttpException : HttpException { + constructor(message: String) : super(message) + constructor(response: Response, message: String) : super(response, message) + } open class GenericCryptoException(message: String) : Exception(message) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt index d3cef1e4..ab1d4527 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt @@ -72,6 +72,8 @@ class AddressBooksSyncAdapterService : SyncAdapterService() { } catch (e: Exceptions.ServiceUnavailableException) { syncResult.stats.numIoExceptions++ syncResult.delayUntil = if (e.retryAfter > 0) e.retryAfter else Constants.DEFAULT_RETRY_DELAY + } catch (e: Exceptions.IgnorableHttpException) { + // Ignore } catch (e: Exception) { if (e is ContactsStorageException || e is SQLiteException) { App.log.log(Level.SEVERE, "Couldn't prepare local address books", e) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt index bbb3ea64..d56ee5f1 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarsSyncAdapterService.kt @@ -60,6 +60,8 @@ class CalendarsSyncAdapterService : SyncAdapterService() { } catch (e: Exceptions.ServiceUnavailableException) { syncResult.stats.numIoExceptions++ syncResult.delayUntil = if (e.retryAfter > 0) e.retryAfter else Constants.DEFAULT_RETRY_DELAY + } catch (e: Exceptions.IgnorableHttpException) { + // Ignore } catch (e: Exception) { if (e is CalendarStorageException || e is SQLiteException) { App.log.log(Level.SEVERE, "Couldn't prepare local calendars", e) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt index a9e4a69c..b17068b3 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt @@ -187,6 +187,8 @@ constructor(protected val context: Context, protected val account: Account, prot } catch (e: InterruptedException) { // Restart sync if interrupted syncResult.fullSyncRequested = true + } catch (e: Exceptions.IgnorableHttpException) { + // Ignore } catch (e: Exception) { if (e is Exceptions.UnauthorizedException) { syncResult.stats.numAuthExceptions++ diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt index 676d1fa2..000203b4 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt @@ -77,6 +77,8 @@ class TasksSyncAdapterService: SyncAdapterService() { } catch (e: Exceptions.ServiceUnavailableException) { syncResult.stats.numIoExceptions++ syncResult.delayUntil = if (e.retryAfter > 0) e.retryAfter else Constants.DEFAULT_RETRY_DELAY + } catch (e: Exceptions.IgnorableHttpException) { + // Ignore } catch (e: Exception) { if (e is SQLiteException) { App.log.log(Level.SEVERE, "Couldn't prepare local task list", e)