From 25ba6e98ec7a468ad132ad05e5a7e593eec9f9b9 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 17 Jul 2024 18:11:20 +0600 Subject: [PATCH 1/9] feat: add flag to detect authFailure on performSync stage --- .../davdroid/settings/AccountSettings.kt | 17 +++++++++++++++++ .../bitfire/davdroid/syncadapter/SyncManager.kt | 7 ++++++- .../bitfire/davdroid/syncadapter/SyncWorker.kt | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/settings/AccountSettings.kt b/app/src/main/kotlin/at/bitfire/davdroid/settings/AccountSettings.kt index f13aa8f6c..a3fb1d3ad 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/settings/AccountSettings.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/settings/AccountSettings.kt @@ -124,6 +124,8 @@ class AccountSettings( const val COOKIE_KEY = NCAccountUtils.Constants.KEY_OKHTTP_COOKIES const val COOKIE_SEPARATOR = NCAccountUtils.Constants.OKHTTP_COOKIE_SEPARATOR + const val AUTH_EXCEPTION_DETECTED = "auth_exception_detected" + /** Static property to indicate whether AccountSettings migration is currently running. * **Access must be `synchronized` with `AccountSettings::class.java`.** */ @Volatile @@ -647,6 +649,21 @@ class AccountSettings( ).isNullOrBlank() } + fun noAuthExceptionDetected(): Boolean { + return accountManager.getUserData( + account, + AUTH_EXCEPTION_DETECTED + ).isNullOrBlank() + } + + fun updateAuthExceptionDetectedStatus(detected: Boolean) { + accountManager.setUserData( + account, + AUTH_EXCEPTION_DETECTED, + if (detected) true.toString() else null + ) + } + fun clearCookie() { accountManager.setUserData(account, COOKIE_KEY, null) accountManager.setUserData( diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 2a6688353..70ba93d2b 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -385,6 +385,11 @@ abstract class SyncManager, out CollectionType: L return@unwrapExceptions } + is UnauthorizedException -> { + notifyException(e, local, remote) + return@unwrapExceptions + } + // all others else -> { // sometimes sync is kicked in when no network is not available. @@ -855,7 +860,7 @@ abstract class SyncManager, out CollectionType: L syncResult.stats.numAuthExceptions++ // persistent session cookie is present. Probably the session is outDated. no need to show the notification - if (accountSettings.containsPersistentCookie()) { + if (accountSettings.containsPersistentCookie() && accountSettings.noAuthExceptionDetected()) { Logger.log.log(Level.FINE, "Authorization error. Session outDated") return } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt index 50f1fd842..e9e42ff0b 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt @@ -383,6 +383,7 @@ class SyncWorker @AssistedInject constructor( if (isCookiePresent && result.stats.numAuthExceptions > 0) { // probably the session is outDated. retry without the sessionCookie accountSettings.clearCookie() + accountSettings.updateAuthExceptionDetectedStatus(detected = true) return Result.retry() } @@ -435,6 +436,8 @@ class SyncWorker @AssistedInject constructor( } } + accountSettings.updateAuthExceptionDetectedStatus(detected = false) + return Result.success() } -- GitLab From 4e0c199e8596541a07224c67c0a3eb8afe2a5753 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 5 Jul 2024 10:29:04 +0200 Subject: [PATCH 2/9] chore: add string value for warning --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f0de7346..6224f545e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -538,7 +538,7 @@ Additional permissions required %s too old Minimum required version: %1$s - Authentication failed (check login credentials) + Your login/password is incorrect, please login again. Network or I/O error – %s HTTP server error – %s Local storage error – %s -- GitLab From f97a5db266ed9c580a918768f952da04c7260526 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 17 Jul 2024 16:41:18 +0200 Subject: [PATCH 3/9] chore: remove duplicated useless code --- .../at/bitfire/davdroid/syncadapter/SyncManager.kt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 70ba93d2b..737760672 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -206,17 +206,7 @@ abstract class SyncManager, out CollectionType: L clientSecret = clientSecretString ) ) - - accountSettings.credentials( - Credentials( - account.name, - null, - authState, - null, - clientSecret = clientSecretString - ) - ) - + executor.execute { performSync(DEFAULT_RETRY_AFTER, DEFAULT_SECOND_RETRY_AFTER, DEFAULT_MAX_RETRY_TIME) } -- GitLab From c571ea57aa2a15e197359cf8aa96f8d51abaefe3 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 17 Jul 2024 16:58:53 +0200 Subject: [PATCH 4/9] feat: change title for notification when we faced Unathorized issue --- .../kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt | 7 ++++--- app/src/main/res/values/strings.xml | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 737760672..d73d97d04 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -206,7 +206,7 @@ abstract class SyncManager, out CollectionType: L clientSecret = clientSecretString ) ) - + executor.execute { performSync(DEFAULT_RETRY_AFTER, DEFAULT_SECOND_RETRY_AFTER, DEFAULT_MAX_RETRY_TIME) } @@ -837,7 +837,7 @@ abstract class SyncManager, out CollectionType: L private fun notifyException(e: Throwable, local: ResourceType?, remote: HttpUrl?) { val message: String - + var title: String = localCollection.title when (e) { is IOException, is InterruptedIOException -> { @@ -846,6 +846,7 @@ abstract class SyncManager, out CollectionType: L syncResult.stats.numIoExceptions++ } is UnauthorizedException -> { + title = context.getString(R.string.sync_error_authentification_failed_title, accountSettings.credentials().userName) message = context.getString(R.string.sync_error_authentication_failed) syncResult.stats.numAuthExceptions++ @@ -915,7 +916,7 @@ abstract class SyncManager, out CollectionType: L val builder = NotificationUtils.newBuilder(context, channel) builder .setSmallIcon(R.drawable.ic_sync_problem_notify) - .setContentTitle(localCollection.title) + .setContentTitle(title) .setContentText(message) .setStyle(NotificationCompat.BigTextStyle(builder).bigText(message)) .setSubText(mainAccount.name) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6224f545e..47579443b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -538,6 +538,7 @@ Additional permissions required %s too old Minimum required version: %1$s + Your account %1$s Your login/password is incorrect, please login again. Network or I/O error – %s HTTP server error – %s -- GitLab From 401561b4195eeb04809393de174af7a4425d8626 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Thu, 25 Jul 2024 10:33:37 +0600 Subject: [PATCH 5/9] resolved conflict --- .../davdroid/syncadapter/SyncManager.kt | 18 +++++++++++++----- .../bitfire/davdroid/syncadapter/SyncWorker.kt | 15 ++++++++------- .../at/bitfire/davdroid/syncadapter/Syncer.kt | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index d73d97d04..716fc8908 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -223,11 +223,13 @@ abstract class SyncManager, out CollectionType: L * @param maxRetryTime optional param, in seconds. On unhandled exception, max time the method should retry. */ fun performSync(retryAfter: Int, secondRetryAfter: Int, maxRetryTime: Int) { + + Logger.log.info("===> perforSync from SyncManager") // dismiss previous error notifications notificationManager.cancel(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR) unwrapExceptions({ - Logger.log.info("Preparing synchronization") + Logger.log.info("===> Preparing synchronization") if (!prepare()) { Logger.log.info("No reason to synchronize, aborting") return@unwrapExceptions @@ -243,7 +245,7 @@ abstract class SyncManager, out CollectionType: L } } - Logger.log.info("Querying server capabilities") + Logger.log.info("===> Querying server capabilities") var remoteSyncState = queryCapabilities() Logger.log.info("Processing local deletes/updates") @@ -342,8 +344,9 @@ abstract class SyncManager, out CollectionType: L } } else - Logger.log.info("Remote collection didn't change, no reason to sync") + Logger.log.info("===> Remote collection didn't change, no reason to sync") }, { e, local, remote -> + Logger.log.info("===> SyncManager exception: $e") when (e) { // sync was cancelled or account has been removed: re-throw to SyncAdapterService (now BaseSyncer) is InterruptedException, @@ -376,6 +379,7 @@ abstract class SyncManager, out CollectionType: L } is UnauthorizedException -> { + Logger.log.log(Level.WARNING, "===> Got 401 Unauthorized", e) notifyException(e, local, remote) return@unwrapExceptions } @@ -847,6 +851,7 @@ abstract class SyncManager, out CollectionType: L } is UnauthorizedException -> { title = context.getString(R.string.sync_error_authentification_failed_title, accountSettings.credentials().userName) + Logger.log.log(Level.WARNING, "===> notifyException Got 401 Unauthorized", e) message = context.getString(R.string.sync_error_authentication_failed) syncResult.stats.numAuthExceptions++ @@ -860,11 +865,11 @@ abstract class SyncManager, out CollectionType: L /* TODO Investigate deeper why this exception sometimes happens * https://gitlab.e.foundation/e/backlog/-/issues/3430 */ - Logger.log.log(Level.WARNING, "Authorization error. Do not notify the user") + Logger.log.log(Level.WARNING, "===> Authorization error. Do not notify the user") return } - Logger.log.log(Level.SEVERE, "Not authorized anymore", e) + Logger.log.log(Level.SEVERE, "===> Not authorized anymore", e) } is HttpException, is DavException -> { Logger.log.log(Level.SEVERE, "HTTP/DAV exception", e) @@ -883,6 +888,8 @@ abstract class SyncManager, out CollectionType: L } } + Logger.log.info("===> Notification sent") + val contentIntent: Intent var viewItemAction: NotificationCompat.Action? = null @@ -927,6 +934,7 @@ abstract class SyncManager, out CollectionType: L viewItemAction?.let { builder.addAction(it) } notificationManager.notifyIfPossible(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build()) + Logger.log.info("===> Notification sent") } private fun buildDebugInfoIntent(e: Throwable, local: ResourceType?, remote: HttpUrl?) = diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt index e9e42ff0b..c9c8fe854 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt @@ -363,10 +363,11 @@ class SyncWorker @AssistedInject constructor( val isCookiePresent = accountSettings.containsPersistentCookie() try { + Logger.log.log(Level.INFO, "===> Starting onPerformSync for $account") syncThread = Thread.currentThread() syncer.onPerformSync(account, extras.toTypedArray(), authority, provider, result) } catch (e: SecurityException) { - Logger.log.log(Level.WARNING, "Security exception when opening content provider for $authority") + Logger.log.log(Level.WARNING, "===> Security exception when opening content provider for $authority") } finally { provider.close() } @@ -389,21 +390,21 @@ class SyncWorker @AssistedInject constructor( // 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}") + Logger.log.warning("===> Soft error while syncing: result=$result, stats=${result.stats}") if (runAttemptCount < MAX_RUN_ATTEMPTS) { val blockDuration = result.delayUntil - System.currentTimeMillis()/1000 - Logger.log.warning("Waiting for $blockDuration seconds, before retrying ...") + Logger.log.warning("===> Waiting for $blockDuration seconds, before retrying ...") // We block the SyncWorker here so that it won't be started by the sync framework immediately again. // This should be replaced by proper work scheduling as soon as we don't depend on the sync framework anymore. if (blockDuration > 0) Thread.sleep(blockDuration*1000) - Logger.log.warning("Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS)") + Logger.log.warning("===> Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS)") return Result.retry() } - Logger.log.warning("Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS). Treating as failed") + Logger.log.warning("===> Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS). Treating as failed") notificationManager.notifyIfPossible( softErrorNotificationTag, @@ -431,13 +432,13 @@ class SyncWorker @AssistedInject constructor( // On a hard error - fail with an error message // Note: SyncManager should have notified the user if (result.hasHardError()) { - Logger.log.warning("Hard error while syncing: result=$result, stats=${result.stats}") + Logger.log.warning("===> Hard error while syncing: result=$result, stats=${result.stats}") return Result.failure(syncResult) } } accountSettings.updateAuthExceptionDetectedStatus(detected = false) - + Logger.log.warning("===> Sync completed successfully") return Result.success() } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt index 82101cdc4..d2fe96ba8 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt @@ -72,6 +72,7 @@ abstract class Syncer(val context: Context) { provider: ContentProviderClient, syncResult: SyncResult ) { + Logger.log.log(Level.INFO, "===> onPerformSync") Logger.log.log(Level.INFO, "$authority sync of $account initiated", extras.joinToString(", ")) val accountSettings by lazy { AccountSettings(context, account) } -- GitLab From ffd5f333f37d5bf74e7debcb0488e2b0c2ac882f Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 29 Jul 2024 14:29:48 +0600 Subject: [PATCH 6/9] fixed: duplicate notification for unauthorized user --- .../davdroid/syncadapter/SyncManager.kt | 22 +++++++++---------- .../davdroid/syncadapter/SyncWorker.kt | 16 +++++++------- .../at/bitfire/davdroid/syncadapter/Syncer.kt | 1 - 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 716fc8908..498181b62 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -224,12 +224,10 @@ abstract class SyncManager, out CollectionType: L */ fun performSync(retryAfter: Int, secondRetryAfter: Int, maxRetryTime: Int) { - Logger.log.info("===> perforSync from SyncManager") // dismiss previous error notifications notificationManager.cancel(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR) unwrapExceptions({ - Logger.log.info("===> Preparing synchronization") if (!prepare()) { Logger.log.info("No reason to synchronize, aborting") return@unwrapExceptions @@ -245,7 +243,6 @@ abstract class SyncManager, out CollectionType: L } } - Logger.log.info("===> Querying server capabilities") var remoteSyncState = queryCapabilities() Logger.log.info("Processing local deletes/updates") @@ -344,9 +341,9 @@ abstract class SyncManager, out CollectionType: L } } else - Logger.log.info("===> Remote collection didn't change, no reason to sync") + Logger.log.info("Remote collection didn't change, no reason to sync") }, { e, local, remote -> - Logger.log.info("===> SyncManager exception: $e") + Logger.log.info("SyncManager exception: $e") when (e) { // sync was cancelled or account has been removed: re-throw to SyncAdapterService (now BaseSyncer) is InterruptedException, @@ -379,7 +376,7 @@ abstract class SyncManager, out CollectionType: L } is UnauthorizedException -> { - Logger.log.log(Level.WARNING, "===> Got 401 Unauthorized", e) + Logger.log.log(Level.WARNING, "Got 401 Unauthorized", e) notifyException(e, local, remote) return@unwrapExceptions } @@ -842,6 +839,7 @@ abstract class SyncManager, out CollectionType: L private fun notifyException(e: Throwable, local: ResourceType?, remote: HttpUrl?) { val message: String var title: String = localCollection.title + var unauthorizedUserTag: String? = null when (e) { is IOException, is InterruptedIOException -> { @@ -851,7 +849,7 @@ abstract class SyncManager, out CollectionType: L } is UnauthorizedException -> { title = context.getString(R.string.sync_error_authentification_failed_title, accountSettings.credentials().userName) - Logger.log.log(Level.WARNING, "===> notifyException Got 401 Unauthorized", e) + unauthorizedUserTag = UnauthorizedException::class.simpleName message = context.getString(R.string.sync_error_authentication_failed) syncResult.stats.numAuthExceptions++ @@ -865,11 +863,11 @@ abstract class SyncManager, out CollectionType: L /* TODO Investigate deeper why this exception sometimes happens * https://gitlab.e.foundation/e/backlog/-/issues/3430 */ - Logger.log.log(Level.WARNING, "===> Authorization error. Do not notify the user") + Logger.log.log(Level.WARNING, "Authorization error. Do not notify the user") return } - Logger.log.log(Level.SEVERE, "===> Not authorized anymore", e) + Logger.log.log(Level.SEVERE, "Not authorized anymore", e) } is HttpException, is DavException -> { Logger.log.log(Level.SEVERE, "HTTP/DAV exception", e) @@ -888,7 +886,7 @@ abstract class SyncManager, out CollectionType: L } } - Logger.log.info("===> Notification sent") + Logger.log.info("Notification sent") val contentIntent: Intent var viewItemAction: NotificationCompat.Action? = null @@ -933,8 +931,8 @@ abstract class SyncManager, out CollectionType: L .setCategory(NotificationCompat.CATEGORY_ERROR) viewItemAction?.let { builder.addAction(it) } - notificationManager.notifyIfPossible(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build()) - Logger.log.info("===> Notification sent") + val tag = unauthorizedUserTag ?: notificationTag + notificationManager.notifyIfPossible(tag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build()) } private fun buildDebugInfoIntent(e: Throwable, local: ResourceType?, remote: HttpUrl?) = diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt index c9c8fe854..09cf6ae33 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt @@ -363,11 +363,11 @@ class SyncWorker @AssistedInject constructor( val isCookiePresent = accountSettings.containsPersistentCookie() try { - Logger.log.log(Level.INFO, "===> Starting onPerformSync for $account") + Logger.log.log(Level.INFO, "Starting onPerformSync for $account") syncThread = Thread.currentThread() syncer.onPerformSync(account, extras.toTypedArray(), authority, provider, result) } catch (e: SecurityException) { - Logger.log.log(Level.WARNING, "===> Security exception when opening content provider for $authority") + Logger.log.log(Level.WARNING, "Security exception when opening content provider for $authority") } finally { provider.close() } @@ -390,21 +390,21 @@ class SyncWorker @AssistedInject constructor( // 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}") + Logger.log.warning("Soft error while syncing: result=$result, stats=${result.stats}") if (runAttemptCount < MAX_RUN_ATTEMPTS) { val blockDuration = result.delayUntil - System.currentTimeMillis()/1000 - Logger.log.warning("===> Waiting for $blockDuration seconds, before retrying ...") + Logger.log.warning("Waiting for $blockDuration seconds, before retrying ...") // We block the SyncWorker here so that it won't be started by the sync framework immediately again. // This should be replaced by proper work scheduling as soon as we don't depend on the sync framework anymore. if (blockDuration > 0) Thread.sleep(blockDuration*1000) - Logger.log.warning("===> Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS)") + Logger.log.warning("Retrying on soft error (attempt $runAttemptCount of $MAX_RUN_ATTEMPTS)") return Result.retry() } - Logger.log.warning("===> Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS). Treating as failed") + Logger.log.warning("Max retries on soft errors reached ($runAttemptCount of $MAX_RUN_ATTEMPTS). Treating as failed") notificationManager.notifyIfPossible( softErrorNotificationTag, @@ -432,13 +432,13 @@ class SyncWorker @AssistedInject constructor( // On a hard error - fail with an error message // Note: SyncManager should have notified the user if (result.hasHardError()) { - Logger.log.warning("===> Hard error while syncing: result=$result, stats=${result.stats}") + Logger.log.warning("Hard error while syncing: result=$result, stats=${result.stats}") return Result.failure(syncResult) } } accountSettings.updateAuthExceptionDetectedStatus(detected = false) - Logger.log.warning("===> Sync completed successfully") + Logger.log.warning("Sync completed successfully") return Result.success() } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt index d2fe96ba8..82101cdc4 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/Syncer.kt @@ -72,7 +72,6 @@ abstract class Syncer(val context: Context) { provider: ContentProviderClient, syncResult: SyncResult ) { - Logger.log.log(Level.INFO, "===> onPerformSync") Logger.log.log(Level.INFO, "$authority sync of $account initiated", extras.joinToString(", ")) val accountSettings by lazy { AccountSettings(context, account) } -- GitLab From 40a25c2cad63e92f22635186b3aa78423c492a8b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 29 Jul 2024 12:25:47 +0200 Subject: [PATCH 7/9] refactor: update notification tag --- .../at/bitfire/davdroid/syncadapter/SyncManager.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 498181b62..c4868b2ad 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -96,7 +96,7 @@ abstract class SyncManager, out CollectionType: L companion object { const val DEBUG_INFO_MAX_RESOURCE_DUMP_SIZE = 100*FileUtils.ONE_KB.toInt() - + const val UNAUTHORIZED_NOTIFICATION_TAG = "Unauthorized" const val MAX_MULTIGET_RESOURCES = 10 const val DEFAULT_RETRY_AFTER = 5 @@ -839,7 +839,8 @@ abstract class SyncManager, out CollectionType: L private fun notifyException(e: Throwable, local: ResourceType?, remote: HttpUrl?) { val message: String var title: String = localCollection.title - var unauthorizedUserTag: String? = null + var tag: String = notificationTag + when (e) { is IOException, is InterruptedIOException -> { @@ -849,7 +850,7 @@ abstract class SyncManager, out CollectionType: L } is UnauthorizedException -> { title = context.getString(R.string.sync_error_authentification_failed_title, accountSettings.credentials().userName) - unauthorizedUserTag = UnauthorizedException::class.simpleName + tag = UNAUTHORIZED_NOTIFICATION_TAG message = context.getString(R.string.sync_error_authentication_failed) syncResult.stats.numAuthExceptions++ @@ -931,7 +932,7 @@ abstract class SyncManager, out CollectionType: L .setCategory(NotificationCompat.CATEGORY_ERROR) viewItemAction?.let { builder.addAction(it) } - val tag = unauthorizedUserTag ?: notificationTag + notificationManager.notifyIfPossible(tag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build()) } -- GitLab From 84f4e33051b9ea111699e68c8db7c402157c6230 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 29 Jul 2024 19:34:59 +0600 Subject: [PATCH 8/9] refactor: added logs --- .../main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index c4868b2ad..c370730a9 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -228,6 +228,7 @@ abstract class SyncManager, out CollectionType: L notificationManager.cancel(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR) unwrapExceptions({ + Logger.log.info("Preparing synchronization") if (!prepare()) { Logger.log.info("No reason to synchronize, aborting") return@unwrapExceptions @@ -243,6 +244,7 @@ abstract class SyncManager, out CollectionType: L } } + Logger.log.info("Querying server capabilities") var remoteSyncState = queryCapabilities() Logger.log.info("Processing local deletes/updates") -- GitLab From ef0530fff8b408ac5babe3ba74036282883d25b1 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 31 Jul 2024 11:55:28 +0200 Subject: [PATCH 9/9] chore: update logging level according to review --- .../main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt index 09cf6ae33..ab2b5a9a1 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncWorker.kt @@ -438,7 +438,7 @@ class SyncWorker @AssistedInject constructor( } accountSettings.updateAuthExceptionDetectedStatus(detected = false) - Logger.log.warning("Sync completed successfully") + Logger.log.info("Sync completed successfully") return Result.success() } -- GitLab