-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync workers: use data type enum instead of specific authority (#1177)
* Introduce SyncDataType for Workers * Fix tests, remove SyncWorkerManager.enqueueOneTime(authority) * TasksAppManager.currentProviderFlow(): return Flow instead of StateFlow * Simplify TasksAppManager and TasksAppWatcher * [WIP] AutomaticSyncManager * [WIP] AutomaticSyncManager * AccountSettings: optimize imports * SyncWorkManager: remove deprecated methods * AutomaticSyncManager: disable unused authorities in sync framework * Add migration draft * AccountSettings: minor changes * Migration, BaseSyncWorker: use sync data type * Tests, set default sync interval when tasks app is installed, notify on missing tasks app permission during sync * Remove deprecated AccountSettings methods * AccountSettings: actually increase version number * Use automaticSyncManager.updateAutomaticSync where applicable; better handle manual sync interval * KDoc * Remove deprecated SyncWorkerManager.syncAuthorities; fix cancelAllWork * AccountSettings: minor changes * TasksAppManager: show notification on missing permissions; always update automatic syncs * AutomaticSyncWorker: only provide updateAutomaticSync() as public method * AccountSettings: simplify setSyncInterval * AutomaticSyncManager: disable automatic task sync when no tasks provider is available
- Loading branch information
Showing
31 changed files
with
589 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...droidTest/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration19Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details. | ||
*/ | ||
|
||
package at.bitfire.davdroid.settings.migration | ||
|
||
import android.accounts.Account | ||
import android.content.Context | ||
import android.util.Log | ||
import androidx.hilt.work.HiltWorkerFactory | ||
import androidx.work.Configuration | ||
import androidx.work.WorkManager | ||
import androidx.work.testing.WorkManagerTestInitHelper | ||
import at.bitfire.davdroid.R | ||
import at.bitfire.davdroid.sync.AutomaticSyncManager | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.impl.annotations.InjectMockKs | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.impl.annotations.SpyK | ||
import io.mockk.mockkObject | ||
import io.mockk.unmockkAll | ||
import io.mockk.verify | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidTest | ||
class AccountSettingsMigration19Test { | ||
|
||
@Inject @ApplicationContext | ||
@SpyK | ||
lateinit var context: Context | ||
|
||
@MockK(relaxed = true) | ||
lateinit var automaticSyncManager: AutomaticSyncManager | ||
|
||
@InjectMockKs | ||
lateinit var migration: AccountSettingsMigration19 | ||
|
||
@Inject | ||
lateinit var workerFactory: HiltWorkerFactory | ||
|
||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
|
||
// Initialize WorkManager for instrumentation tests. | ||
val config = Configuration.Builder() | ||
.setMinimumLoggingLevel(Log.DEBUG) | ||
.setWorkerFactory(workerFactory) | ||
.build() | ||
WorkManagerTestInitHelper.initializeTestWorkManager(context, config) | ||
|
||
MockKAnnotations.init(this) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
unmockkAll() | ||
} | ||
|
||
|
||
@Test | ||
fun testMigrate_CancelsOldWorkersAndUpdatesAutomaticSync() { | ||
val workManager = WorkManager.getInstance(context) | ||
mockkObject(workManager) | ||
|
||
val account = Account("Some", "Test") | ||
migration.migrate(account) | ||
|
||
val addressBookAuthority = context.getString(R.string.address_books_authority) | ||
verify { | ||
workManager.cancelUniqueWork("periodic-sync $addressBookAuthority Test/Some") | ||
workManager.cancelUniqueWork("periodic-sync com.android.calendar Test/Some") | ||
workManager.cancelUniqueWork("periodic-sync at.techbee.jtx.provider Test/Some") | ||
workManager.cancelUniqueWork("periodic-sync org.dmfs.tasks Test/Some") | ||
workManager.cancelUniqueWork("periodic-sync org.tasks.opentasks Test/Some") | ||
|
||
automaticSyncManager.updateAutomaticSync(account) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.