mirror of
https://github.com/etesync/android
synced 2025-02-02 02:41:31 +00:00
Fix issue with OpenTasks causing a lot of syncs in some rare cases.
We weren't setting a default sync interval which meant that in some cases it was just syncing every 10 seconds. This fix also fixes #66.
This commit is contained in:
parent
c6472fe220
commit
db8667e84a
@ -12,10 +12,7 @@ import android.accounts.AccountManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Application
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.*
|
||||
import android.database.DatabaseUtils
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.graphics.Bitmap
|
||||
@ -48,6 +45,7 @@ import io.requery.sql.EntityDataStore
|
||||
import okhttp3.internal.tls.OkHostnameVerifier
|
||||
import org.acra.ACRA
|
||||
import org.apache.commons.lang3.time.DateFormatUtils
|
||||
import org.jetbrains.anko.doAsync
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
@ -93,6 +91,19 @@ class App : Application() {
|
||||
addressBooksAuthority = getString(R.string.address_books_authority)
|
||||
|
||||
loadLanguage()
|
||||
|
||||
// don't block UI for some background checks
|
||||
doAsync {
|
||||
// watch installed/removed apps
|
||||
val tasksFilter = IntentFilter()
|
||||
tasksFilter.addAction(Intent.ACTION_PACKAGE_ADDED)
|
||||
tasksFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
|
||||
tasksFilter.addDataScheme("package")
|
||||
registerReceiver(PackageChangedReceiver(), tasksFilter)
|
||||
|
||||
// check whether a tasks app is currently installed
|
||||
PackageChangedReceiver.updateTaskSync(this@App)
|
||||
}
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context) {
|
||||
|
@ -8,11 +8,14 @@
|
||||
|
||||
package com.etesync.syncadapter
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
import android.provider.CalendarContract
|
||||
import at.bitfire.ical4android.TaskProvider
|
||||
import com.etesync.syncadapter.resource.LocalTaskList
|
||||
|
||||
class PackageChangedReceiver : BroadcastReceiver() {
|
||||
@ -29,8 +32,21 @@ class PackageChangedReceiver : BroadcastReceiver() {
|
||||
val tasksInstalled = LocalTaskList.tasksProviderAvailable(context)
|
||||
App.log.info("Package (un)installed; OpenTasks provider now available = $tasksInstalled")
|
||||
|
||||
// check all accounts and (de)activate OpenTasks if a CalDAV service is defined
|
||||
// FIXME: Do something if we ever bring back tasks.
|
||||
for (account in AccountManager.get(context).getAccountsByType(App.accountType)) {
|
||||
val settings = AccountSettings(context, account)
|
||||
val calendarSyncInterval = settings.getSyncInterval(CalendarContract.AUTHORITY)
|
||||
|
||||
if (tasksInstalled) {
|
||||
if (calendarSyncInterval == null) {
|
||||
// do nothing atm
|
||||
} else if (ContentResolver.getIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority) <= 0) {
|
||||
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1)
|
||||
settings.setSyncInterval(TaskProvider.ProviderName.OpenTasks.authority, calendarSyncInterval)
|
||||
}
|
||||
} else {
|
||||
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import android.content.SyncResult
|
||||
import android.database.sqlite.SQLiteException
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.CalendarContract
|
||||
import at.bitfire.ical4android.AndroidTaskList
|
||||
import at.bitfire.ical4android.TaskProvider
|
||||
import com.etesync.syncadapter.*
|
||||
@ -63,6 +64,7 @@ class TasksSyncAdapterService: SyncAdapterService() {
|
||||
if (!extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL) && !checkSyncConditions(accountSettings))
|
||||
return
|
||||
|
||||
|
||||
RefreshCollections(account, CollectionInfo.Type.TASKS).run()
|
||||
|
||||
updateLocalTaskLists(taskProvider, account, accountSettings)
|
||||
|
Loading…
Reference in New Issue
Block a user