mirror of
https://github.com/bitfireAT/davx5-ose.git
synced 2025-12-23 23:17:50 -05:00
Cancel syncs for calendar, tasks, and contacts separately
This commit is contained in:
@@ -6,6 +6,7 @@ package at.bitfire.davdroid.ui
|
|||||||
|
|
||||||
import android.accounts.Account
|
import android.accounts.Account
|
||||||
import android.accounts.AccountManager
|
import android.accounts.AccountManager
|
||||||
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
@@ -15,7 +16,6 @@ import android.net.Network
|
|||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
@@ -305,11 +305,14 @@ class AccountsModel @AssistedInject constructor(
|
|||||||
val calendarAccountType = context.getString(R.string.account_type)
|
val calendarAccountType = context.getString(R.string.account_type)
|
||||||
val addressBookAccountType = context.getString(R.string.account_type_address_book)
|
val addressBookAccountType = context.getString(R.string.account_type_address_book)
|
||||||
|
|
||||||
// Cancel any (after an update) possibly forever pending calendar (+tasks) account syncs
|
// Cancel any (after an update) possibly forever pending calendar account syncs
|
||||||
cancelSyncs(calendarAccountType, CalendarContract.AUTHORITY)
|
cancelSyncs(calendarAccountType, SyncDataType.EVENTS.possibleAuthorities())
|
||||||
|
|
||||||
|
// Cancel any (after an update) possibly forever pending tasks account syncs
|
||||||
|
cancelSyncs(calendarAccountType, SyncDataType.TASKS.possibleAuthorities())
|
||||||
|
|
||||||
// Cancel any (after an update) possibly forever pending address book account syncs
|
// Cancel any (after an update) possibly forever pending address book account syncs
|
||||||
cancelSyncs(addressBookAccountType, ContactsContract.AUTHORITY)
|
cancelSyncs(addressBookAccountType, SyncDataType.CONTACTS.possibleAuthorities())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,12 +320,13 @@ class AccountsModel @AssistedInject constructor(
|
|||||||
* Cancels any (possibly forever pending) syncs for the accounts of given account type for all
|
* Cancels any (possibly forever pending) syncs for the accounts of given account type for all
|
||||||
* authorities.
|
* authorities.
|
||||||
*/
|
*/
|
||||||
private fun cancelSyncs(accountType: String, authority: String) {
|
private fun cancelSyncs(accountType: String, authorities: List<String>) {
|
||||||
val accountManager = AccountManager.get(context)
|
val accountManager = AccountManager.get(context)
|
||||||
accountManager.getAccountsByType(accountType).forEach { account ->
|
accountManager.getAccountsByType(accountType).forEach { account ->
|
||||||
val extras = Bundle()
|
logger.info("Android 14+: Canceling all (possibly forever pending) syncs for $account")
|
||||||
logger.info("Android 14+: Canceling all (possibly forever pending) syncs for $account and $authority with $extras")
|
for (authority in authorities)
|
||||||
syncFrameWork.cancelSync(account, authority, extras)
|
ContentResolver.cancelSync(account, authority)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user