Disable pending sync indicator on Android 14+ (#1689)

* Disable pending sync indicator on Android 14+

* Disable forever pending sync workaround on Android 14+
This commit is contained in:
Sunik Kupfer
2025-09-03 15:32:29 +02:00
committed by GitHub
parent beccc7a0d4
commit 48cbd4a05d
2 changed files with 12 additions and 7 deletions

View File

@@ -11,7 +11,6 @@ import android.content.ContentProviderClient
import android.content.ContentResolver
import android.content.Context
import android.content.SyncResult
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import androidx.work.WorkInfo
@@ -60,7 +59,6 @@ class SyncAdapterImpl @Inject constructor(
@ApplicationContext context: Context,
private val logger: Logger,
private val syncConditionsFactory: SyncConditions.Factory,
private val syncFrameworkIntegration: SyncFrameworkIntegration,
private val syncWorkerManager: SyncWorkerManager
): AbstractThreadedSyncAdapter(
/* context = */ context,
@@ -119,11 +117,11 @@ class SyncAdapterImpl @Inject constructor(
// Android 14+ does not handle pending sync state correctly.
// As a defensive workaround, we can cancel specifically this still pending sync only
// See: https://github.com/bitfireAT/davx5-ose/issues/1458
if (Build.VERSION.SDK_INT >= 34) {
logger.fine("Android 14+ bug: Canceling forever pending sync adapter framework sync request for " +
"account=$accountOrAddressBookAccount authority=$authority upload=$upload")
syncFrameworkIntegration.cancelSync(accountOrAddressBookAccount, authority, extras)
}
// if (Build.VERSION.SDK_INT >= 34) {
// logger.fine("Android 14+ bug: Canceling forever pending sync adapter framework sync request for " +
// "account=$accountOrAddressBookAccount authority=$authority upload=$upload")
// syncFrameworkIntegration.cancelSync(accountOrAddressBookAccount, authority, extras)
// }
/* Because we are not allowed to observe worker state on a background thread, we can not
use it to block the sync adapter. Instead we use a Flow to get notified when the sync

View File

@@ -8,6 +8,7 @@ import android.accounts.Account
import android.content.ContentResolver
import android.content.Context
import android.content.SyncRequest
import android.os.Build
import android.os.Bundle
import androidx.annotation.WorkerThread
import at.bitfire.davdroid.resource.LocalAddressBookStore
@@ -192,6 +193,12 @@ class SyncFrameworkIntegration @Inject constructor(
*/
@OptIn(ExperimentalCoroutinesApi::class)
fun isSyncPending(account: Account, dataTypes: Iterable<SyncDataType>): Flow<Boolean> {
// Android 14+ does not handle pending sync state correctly.
// For now we simply always return false
// See also sync cancellation in [SyncAdapterImpl.onPerformSync]
if (Build.VERSION.SDK_INT >= 34)
return flowOf(false)
// Determine the pending state for each data type of the account as separate flows
val pendingStateFlows: List<Flow<Boolean>> = dataTypes.mapNotNull { dataType ->
// Map datatype to authority