Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry sync on DeadObjectException #503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions app/src/main/java/at/bitfire/icsdroid/BaseSyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.bitfire.icsdroid
import android.content.ContentProviderClient
import android.content.ContentUris
import android.content.Context
import android.os.DeadObjectException
import android.util.Log
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
Expand Down Expand Up @@ -47,13 +48,12 @@ open class BaseSyncWorker(
val onlyMigrate = inputData.getBoolean(ONLY_MIGRATE, false)
Log.i(Constants.TAG, "Synchronizing (forceReSync=$forceReSync,onlyMigrate=$onlyMigrate)")

provider =
try {
LocalCalendar.getCalendarProvider(applicationContext)
} catch (e: SecurityException) {
NotificationUtils.showCalendarPermissionNotification(applicationContext)
return Result.failure()
}
provider = try {
LocalCalendar.getCalendarProvider(applicationContext)
} catch (_: SecurityException) {
NotificationUtils.showCalendarPermissionNotification(applicationContext)
return Result.failure()
}

var syncFailed = false

Expand Down Expand Up @@ -88,6 +88,12 @@ open class BaseSyncWorker(
syncFailed = true
}
}
} catch (e: DeadObjectException) {
/* May happen when the remote process dies or (since Android 14) when IPC (for instance
with the calendar provider) is suddenly forbidden because our sync process was demoted
from a "service process" to a "cached process". */
Log.e(Constants.TAG, "Received DeadObjectException, treating as soft error", e)
return Result.retry()
} catch (e: InterruptedException) {
Log.e(Constants.TAG, "Thread interrupted", e)
return Result.retry()
Expand Down Expand Up @@ -183,8 +189,7 @@ open class BaseSyncWorker(
"Creating local calendar from subscription #${subscription.id}"
)
// create local calendar
val uri =
AndroidCalendar.create(account, provider, subscription.toCalendarProperties())
val uri = AndroidCalendar.create(account, provider, subscription.toCalendarProperties())
// update calendar ID in DB
val newCalendarId = ContentUris.parseId(uri)
subscriptionsDao.updateCalendarId(subscription.id, newCalendarId)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ androidx-test-rules = "1.6.1"
androidx-test-runner = "1.6.2"
androidx-work = "2.10.0"
bitfire-cert4android = "f0964cb"
bitfire-ical4android = "12df9bf"
bitfire-ical4android = "883954c"
compose-dialogs = "1.3.0"
compose-material = "1.7.7"
compose-material3 = "1.3.1"
Expand Down