Loading app/src/androidTest/AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ <application> <service android:name=".syncadapter.NullAuthenticatorService" android:name=".syncadapter.AddressBookAuthenticatorService" android:exported="false"> <intent-filter> <action android:name="android.accounts.AccountAuthenticator"/> Loading app/src/main/AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -208,7 +208,7 @@ <!-- account type "DAVx⁵ Address book" --> <service android:name=".syncadapter.NullAuthenticatorService" android:name=".syncadapter.AddressBookAuthenticatorService" android:exported="true"> <!-- Since Android 11, this must be true so that Google Contacts shows the address book accounts --> <intent-filter> <action android:name="android.accounts.AccountAuthenticator"/> Loading app/src/main/java/at/bitfire/davdroid/App.kt +12 −9 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import androidx.appcompat.content.res.AppCompatResources import androidx.core.graphics.drawable.toBitmap import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils import at.bitfire.davdroid.ui.DebugInfoActivity import at.bitfire.davdroid.ui.NotificationUtils import at.bitfire.davdroid.ui.UiUtils Loading Loading @@ -63,23 +64,25 @@ class App: Application(), Thread.UncaughtExceptionHandler { // don't block UI for some background checks thread { // create/update app shortcuts UiUtils.updateShortcuts(this) // watch for account changes/deletions AccountUtils.registerAccountsUpdateListener(this) // watch installed/removed apps TasksWatcher(this) // foreground service (possible workaround for devices which prevent DAVx5 from being started) ForegroundService.startIfActive(this) // watch storage because low storage means synchronization is stopped StorageLowReceiver.getInstance(this) // watch installed/removed apps TasksWatcher.watch(this) // check whether a tasks app is currently installed TasksWatcher.updateTaskSync(this) // watch storage because low storage means synchronization is stopped StorageLowReceiver.getInstance(this) // create/update app shortcuts UiUtils.updateShortcuts(this) // check/repair sync intervals AccountSettings.repairSyncIntervals(this) // foreground service (possible workaround for devices which prevent DAVx5 from being started) ForegroundService.startIfActive(this) } } Loading app/src/main/java/at/bitfire/davdroid/TasksWatcher.kt +4 −1 Original line number Diff line number Diff line Loading @@ -22,12 +22,15 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class TasksWatcher( class TasksWatcher protected constructor( context: Context ): PackageChangedReceiver(context) { companion object { fun watch(context: Context) = TasksWatcher(context) @WorkerThread fun updateTaskSync(context: Context) { val tasksProvider = TaskUtils.currentProvider(context) Loading app/src/main/java/at/bitfire/davdroid/syncadapter/AccountAuthenticatorService.kt +6 −24 Original line number Diff line number Diff line Loading @@ -3,51 +3,32 @@ **************************************************************************************************/ package at.bitfire.davdroid.syncadapter import android.accounts.* import android.accounts.AbstractAccountAuthenticator import android.accounts.Account import android.accounts.AccountAuthenticatorResponse import android.accounts.AccountManager import android.app.Service import android.content.Context import android.content.Intent import android.os.Bundle import at.bitfire.davdroid.ui.setup.LoginActivity import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch /** * Account authenticator for the main DAVx5 account type. * * Gets started when a DAVx5 account is removed, too, so it also watches for account removals * and contains the corresponding cleanup code. */ class AccountAuthenticatorService: Service(), OnAccountsUpdateListener { class AccountAuthenticatorService: Service() { private lateinit var accountManager: AccountManager private lateinit var accountAuthenticator: AccountAuthenticator override fun onCreate() { accountManager = AccountManager.get(this) accountManager.addOnAccountsUpdatedListener(this, null, true) accountAuthenticator = AccountAuthenticator(this) } override fun onDestroy() { super.onDestroy() accountManager.removeOnAccountsUpdatedListener(this) } override fun onBind(intent: Intent?) = accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT } override fun onAccountsUpdated(accounts: Array<out Account>?) { CoroutineScope(Dispatchers.Default).launch { AccountUtils.cleanupAccounts(this@AccountAuthenticatorService) } } private class AccountAuthenticator( val context: Context ): AbstractAccountAuthenticator(context) { Loading @@ -68,4 +49,5 @@ class AccountAuthenticatorService: Service(), OnAccountsUpdateListener { override fun hasFeatures(p0: AccountAuthenticatorResponse?, p1: Account?, p2: Array<out String>?) = null } } Loading
app/src/androidTest/AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ <application> <service android:name=".syncadapter.NullAuthenticatorService" android:name=".syncadapter.AddressBookAuthenticatorService" android:exported="false"> <intent-filter> <action android:name="android.accounts.AccountAuthenticator"/> Loading
app/src/main/AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -208,7 +208,7 @@ <!-- account type "DAVx⁵ Address book" --> <service android:name=".syncadapter.NullAuthenticatorService" android:name=".syncadapter.AddressBookAuthenticatorService" android:exported="true"> <!-- Since Android 11, this must be true so that Google Contacts shows the address book accounts --> <intent-filter> <action android:name="android.accounts.AccountAuthenticator"/> Loading
app/src/main/java/at/bitfire/davdroid/App.kt +12 −9 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import androidx.appcompat.content.res.AppCompatResources import androidx.core.graphics.drawable.toBitmap import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils import at.bitfire.davdroid.ui.DebugInfoActivity import at.bitfire.davdroid.ui.NotificationUtils import at.bitfire.davdroid.ui.UiUtils Loading Loading @@ -63,23 +64,25 @@ class App: Application(), Thread.UncaughtExceptionHandler { // don't block UI for some background checks thread { // create/update app shortcuts UiUtils.updateShortcuts(this) // watch for account changes/deletions AccountUtils.registerAccountsUpdateListener(this) // watch installed/removed apps TasksWatcher(this) // foreground service (possible workaround for devices which prevent DAVx5 from being started) ForegroundService.startIfActive(this) // watch storage because low storage means synchronization is stopped StorageLowReceiver.getInstance(this) // watch installed/removed apps TasksWatcher.watch(this) // check whether a tasks app is currently installed TasksWatcher.updateTaskSync(this) // watch storage because low storage means synchronization is stopped StorageLowReceiver.getInstance(this) // create/update app shortcuts UiUtils.updateShortcuts(this) // check/repair sync intervals AccountSettings.repairSyncIntervals(this) // foreground service (possible workaround for devices which prevent DAVx5 from being started) ForegroundService.startIfActive(this) } } Loading
app/src/main/java/at/bitfire/davdroid/TasksWatcher.kt +4 −1 Original line number Diff line number Diff line Loading @@ -22,12 +22,15 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class TasksWatcher( class TasksWatcher protected constructor( context: Context ): PackageChangedReceiver(context) { companion object { fun watch(context: Context) = TasksWatcher(context) @WorkerThread fun updateTaskSync(context: Context) { val tasksProvider = TaskUtils.currentProvider(context) Loading
app/src/main/java/at/bitfire/davdroid/syncadapter/AccountAuthenticatorService.kt +6 −24 Original line number Diff line number Diff line Loading @@ -3,51 +3,32 @@ **************************************************************************************************/ package at.bitfire.davdroid.syncadapter import android.accounts.* import android.accounts.AbstractAccountAuthenticator import android.accounts.Account import android.accounts.AccountAuthenticatorResponse import android.accounts.AccountManager import android.app.Service import android.content.Context import android.content.Intent import android.os.Bundle import at.bitfire.davdroid.ui.setup.LoginActivity import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch /** * Account authenticator for the main DAVx5 account type. * * Gets started when a DAVx5 account is removed, too, so it also watches for account removals * and contains the corresponding cleanup code. */ class AccountAuthenticatorService: Service(), OnAccountsUpdateListener { class AccountAuthenticatorService: Service() { private lateinit var accountManager: AccountManager private lateinit var accountAuthenticator: AccountAuthenticator override fun onCreate() { accountManager = AccountManager.get(this) accountManager.addOnAccountsUpdatedListener(this, null, true) accountAuthenticator = AccountAuthenticator(this) } override fun onDestroy() { super.onDestroy() accountManager.removeOnAccountsUpdatedListener(this) } override fun onBind(intent: Intent?) = accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT } override fun onAccountsUpdated(accounts: Array<out Account>?) { CoroutineScope(Dispatchers.Default).launch { AccountUtils.cleanupAccounts(this@AccountAuthenticatorService) } } private class AccountAuthenticator( val context: Context ): AbstractAccountAuthenticator(context) { Loading @@ -68,4 +49,5 @@ class AccountAuthenticatorService: Service(), OnAccountsUpdateListener { override fun hasFeatures(p0: AccountAuthenticatorResponse?, p1: Account?, p2: Array<out String>?) = null } }