diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt index 8efd63168117130b56c14f93fc6424736b8e26a4..53e5abee43c6691c83a250c0e6ae639afe5bbf55 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/RefreshCollectionsWorker.kt @@ -168,11 +168,16 @@ class RefreshCollectionsWorker @AssistedInject constructor( } val serviceId: Long = inputData.getLong(ARG_SERVICE_ID, -1) - val service = db.serviceDao().get(serviceId) - ?: throw IllegalArgumentException("Service #$serviceId not found") - val account = Account(service.accountName, service.accountType) override fun doWork(): Result { + val service = db.serviceDao().get(serviceId) + if (service == null) { + Logger.log.severe("Service #$serviceId not found") + return Result.failure() + } + + val account = Account(service.accountName, service.accountType) + try { Logger.log.info("Refreshing ${service.type} collections of service #$service") @@ -213,7 +218,8 @@ class RefreshCollectionsWorker @AssistedInject constructor( .putExtra(SettingsActivity.EXTRA_ACCOUNT, account) notifyRefreshError( applicationContext.getString(R.string.sync_error_authentication_failed), - settingsIntent + settingsIntent, + account.name ) return Result.failure() } catch (e: Exception) { @@ -225,7 +231,8 @@ class RefreshCollectionsWorker @AssistedInject constructor( .build() notifyRefreshError( applicationContext.getString(R.string.refresh_collections_worker_refresh_couldnt_refresh), - debugIntent + debugIntent, + account.name ) return Result.failure() } @@ -250,7 +257,7 @@ class RefreshCollectionsWorker @AssistedInject constructor( completer.set(ForegroundInfo(NotificationUtils.NOTIFY_SYNC_EXPEDITED, notification)) } - private fun notifyRefreshError(contentText: String, contentIntent: Intent) { + private fun notifyRefreshError(contentText: String, contentIntent: Intent, accountName: String) { val notify = NotificationUtils.newBuilder(applicationContext, NotificationUtils.CHANNEL_GENERAL) .setSmallIcon(R.drawable.ic_sync_problem_notify) @@ -264,7 +271,7 @@ class RefreshCollectionsWorker @AssistedInject constructor( PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) ) - .setSubText(account.name) + .setSubText(accountName) .setCategory(NotificationCompat.CATEGORY_ERROR) .build() NotificationManagerCompat.from(applicationContext)