Commit d69f84da authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Set 15 minutes period for Google Accounts DAV syncs

We keep facing errors with Google Accounts mail, calendar,
contacts and tasks. This commit helps being less agressive on
Google servers which could potentially limit the sync requests.
parent fcee1f26
Pipeline #192010 passed with stage
in 3 minutes and 14 seconds
......@@ -199,6 +199,11 @@ class AccountDetailsFragment : Fragment() {
val name = MutableLiveData<String>()
val nameError = MutableLiveData<String>()
companion object {
const val GOOGLE_ACCOUNT_TYPE = "e.foundation.webdav.google"
const val GOOGLE_ACCOUNT_DEFAULT_SYNC_PERIOD_IN_S = 15 * 60L
}
fun createAccount(
activity: Activity,
name: String,
......@@ -333,9 +338,10 @@ class AccountDetailsFragment : Fragment() {
context.startService(refreshIntent)
// contact sync is automatically enabled by isAlwaysSyncable="true" in res/xml/sync_address_books.xml
val syncInterval = provideSyncInterval(accountType, Constants.DEFAULT_CALENDAR_SYNC_INTERVAL)
accountSettings.setSyncInterval(
context.getString(R.string.address_books_authority),
Constants.DEFAULT_CALENDAR_SYNC_INTERVAL
syncInterval
)
} else
ContentResolver.setIsSyncable(
......@@ -361,9 +367,10 @@ class AccountDetailsFragment : Fragment() {
context.startService(refreshIntent)
// calendar sync is automatically enabled by isAlwaysSyncable="true" in res/xml/sync_calendars.xml
val syncInterval = provideSyncInterval(accountType, Constants.DEFAULT_CALENDAR_SYNC_INTERVAL)
accountSettings.setSyncInterval(
CalendarContract.AUTHORITY,
Constants.DEFAULT_CALENDAR_SYNC_INTERVAL
syncInterval
)
// enable task sync if OpenTasks is installed
......@@ -374,9 +381,10 @@ class AccountDetailsFragment : Fragment() {
TaskProvider.ProviderName.OpenTasks.authority,
1
)
val syncInterval = provideSyncInterval(accountType, Constants.DEFAULT_CALENDAR_SYNC_INTERVAL)
accountSettings.setSyncInterval(
TaskProvider.ProviderName.OpenTasks.authority,
Constants.DEFAULT_CALENDAR_SYNC_INTERVAL
syncInterval
)
}
} else {
......@@ -398,6 +406,13 @@ class AccountDetailsFragment : Fragment() {
return result
}
private fun provideSyncInterval(type: String, fallback: Long): Long {
if (type == GOOGLE_ACCOUNT_TYPE) {
return GOOGLE_ACCOUNT_DEFAULT_SYNC_PERIOD_IN_S
}
return fallback
}
private fun insertService(
db: AppDatabase,
accountName: String,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment