Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync workers: use data type enum instead of specific authority #1177

Merged
merged 28 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e777a4c
Introduce SyncDataType for Workers
rfc2822 Dec 17, 2024
71f0ca1
Fix tests, remove SyncWorkerManager.enqueueOneTime(authority)
rfc2822 Dec 17, 2024
a08db1a
Merge branch 'main-ose' into sync-domains-2
rfc2822 Dec 24, 2024
a0e45c0
TasksAppManager.currentProviderFlow(): return Flow instead of StateFlow
rfc2822 Dec 24, 2024
f9b8e0b
Simplify TasksAppManager and TasksAppWatcher
rfc2822 Dec 24, 2024
335a1a0
[WIP] AutomaticSyncManager
rfc2822 Dec 24, 2024
c81bcf7
Merge branch 'main-ose' into sync-domains-2
rfc2822 Dec 24, 2024
1ca0f55
[WIP] AutomaticSyncManager
rfc2822 Dec 25, 2024
02b1a3f
Merge branch 'main-ose' into sync-domains-2
rfc2822 Dec 25, 2024
27be589
AccountSettings: optimize imports
rfc2822 Dec 25, 2024
67bc53f
SyncWorkManager: remove deprecated methods
rfc2822 Dec 25, 2024
38ee3ba
AutomaticSyncManager: disable unused authorities in sync framework
rfc2822 Dec 25, 2024
99364fe
Add migration draft
rfc2822 Dec 25, 2024
96779b4
AccountSettings: minor changes
rfc2822 Dec 25, 2024
e7c3abd
Migration, BaseSyncWorker: use sync data type
rfc2822 Dec 25, 2024
2729055
Tests, set default sync interval when tasks app is installed, notify …
rfc2822 Dec 25, 2024
52f9441
Remove deprecated AccountSettings methods
rfc2822 Dec 25, 2024
a63322e
Merge branch 'main-ose' into sync-domains-2
rfc2822 Dec 25, 2024
d7b5c4a
Merge branch 'main-ose' into sync-domains-2
rfc2822 Dec 25, 2024
802a587
AccountSettings: actually increase version number
rfc2822 Dec 25, 2024
3a44c0a
Use automaticSyncManager.updateAutomaticSync where applicable; better…
rfc2822 Dec 26, 2024
294073e
KDoc
rfc2822 Dec 26, 2024
dc50917
Remove deprecated SyncWorkerManager.syncAuthorities; fix cancelAllWork
rfc2822 Dec 26, 2024
9cf5b22
AccountSettings: minor changes
rfc2822 Dec 26, 2024
226464f
TasksAppManager: show notification on missing permissions; always upd…
rfc2822 Dec 26, 2024
e114511
AutomaticSyncWorker: only provide updateAutomaticSync() as public method
rfc2822 Dec 26, 2024
ba200d0
AccountSettings: simplify setSyncInterval
rfc2822 Dec 26, 2024
78c6194
AutomaticSyncManager: disable automatic task sync when no tasks provi…
rfc2822 Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify TasksAppManager and TasksAppWatcher
  • Loading branch information
rfc2822 committed Dec 24, 2024
commit f9b8e0b05540fe2df7c51c73d6082e8639178813
4 changes: 2 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ object Settings {
const val PREFERRED_THEME_DEFAULT = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM

/**
* Selected tasks app. When at least one tasks app is installed, this setting is set to its authority.
* Selected tasks app. When at least one tasks app is installed, this setting is set to its sync authority.
* In case of multiple available tasks app, the user can choose one and this setting will reflect the selected one.
*
* If no tasks app is available, this setting is not set.
* This setting may even be set if the corresponding tasks app is not installed because it only reflects the user's choice.
*/
const val SELECTED_TASKS_PROVIDER = "preferred_tasks_provider"

Expand Down
18 changes: 6 additions & 12 deletions app/src/main/kotlin/at/bitfire/davdroid/startup/TasksAppWatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,14 @@ class TasksAppWatcher @Inject constructor(

if (currentProvider == null) {
// Iterate through all supported providers and select one, if available.
var providerSelected = false
for (provider in TaskProvider.ProviderName.entries) {
val available = context.packageManager.resolveContentProvider(provider.authority, 0) != null
if (available) {
logger.info("Selecting new tasks provider: $provider")
manager.selectProvider(provider)
providerSelected = true
break
var newProvider = TaskProvider.ProviderName.entries
.firstOrNull { provider ->
context.packageManager.resolveContentProvider(provider.authority, 0) != null
}
}

if (!providerSelected)
// no provider available (anymore), also clear setting and sync
manager.selectProvider(null)
// Select provider or clear setting and sync if now provider available
logger.info("Selecting new tasks provider: $newProvider")
manager.selectProvider(null)
}
}

Expand Down
25 changes: 11 additions & 14 deletions app/src/main/kotlin/at/bitfire/davdroid/sync/TasksAppManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class TasksAppManager @Inject constructor(
) {

/**
* Gets the currently selected tasks app.
* Gets the currently selected tasks app, if installed.
*
* @return currently selected tasks app (when installed), or `null` if no tasks app is selected or the selected app is not installed
*/
fun currentProvider(): ProviderName? {
val preferredAuthority = settingsManager.getString(Settings.SELECTED_TASKS_PROVIDER) ?: return null
return preferredAuthorityToProviderName(preferredAuthority)
val authority = settingsManager.getString(Settings.SELECTED_TASKS_PROVIDER) ?: return null
return authorityToProviderName(authority)
}

/**
Expand All @@ -61,22 +61,19 @@ class TasksAppManager @Inject constructor(
fun currentProviderFlow(): Flow<ProviderName?> {
return settingsManager.getStringFlow(Settings.SELECTED_TASKS_PROVIDER).map { preferred ->
if (preferred != null)
preferredAuthorityToProviderName(preferred)
authorityToProviderName(preferred)
else
null
}
}

private fun preferredAuthorityToProviderName(preferredAuthority: String): ProviderName? {
val packageManager = context.packageManager
ProviderName.entries.toTypedArray()
.sortedByDescending { it.authority == preferredAuthority }
.forEach { providerName ->
if (packageManager.resolveContentProvider(providerName.authority, 0) != null)
return providerName
}
return null
}
/**
* Converts an authority to a [ProviderName], if the authority is known and the provider is installed.
*/
private fun authorityToProviderName(authority: String): ProviderName? =
ProviderName.entries
.firstOrNull { it.authority == authority }
.takeIf { context.packageManager.resolveContentProvider(authority, 0) != null }


/**
Expand Down
Loading