Skip to content

Added automatic push distributor selection#1774

Draft
ArnyminerZ wants to merge 23 commits intomainfrom
1737-enable-push-by-default
Draft

Added automatic push distributor selection#1774
ArnyminerZ wants to merge 23 commits intomainfrom
1737-enable-push-by-default

Conversation

@ArnyminerZ
Copy link
Member

@ArnyminerZ ArnyminerZ commented Oct 25, 2025

Purpose

See #1737, but basically, Push is basically stable enough to at least select a distributor by default.

In any case, if one doesn't trust it, the server admin should simply not install support for push on the server, and the distributor will be unused.

Short description

  • Added automatic push distributor selection

    • Added a new optionally injectable class called PushDistributorDefaults. It contains a preferred distributor.
    • For OSE, no distributor has preference.
    • For Play Store builds we might want to pre-select FCM for example, or for managed. This can be set with the DistributorPreferences implementation.
  • Added a new settings entry which will be set to true whenever the user manually disables push (because it will be enabled by default). If this setting is true, no push distributor will be automatically selected.

  • On the push distributor selection dialog, the preferred distributor, if any, is marked with "Recommended"

    Screenshot image

We still have to add the individual implementations for each flavor on bitfireAt/davx5.

  • Subscriptions are invalidated when the push distributor is changed to make sure they're again registered with the correct endpoint.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@ArnyminerZ ArnyminerZ self-assigned this Oct 25, 2025
@ArnyminerZ ArnyminerZ requested a review from a team as a code owner October 25, 2025 10:58
@ArnyminerZ ArnyminerZ added pr-feature Implements a new feature or functionality (only for PRs) push Related to WebDAV-Push labels Oct 25, 2025
@ArnyminerZ ArnyminerZ linked an issue Oct 25, 2025 that may be closed by this pull request
3 tasks
@sunkup sunkup force-pushed the 1737-enable-push-by-default branch from adfee4b to 09f359d Compare November 20, 2025 10:58
@sunkup
Copy link
Member

sunkup commented Nov 20, 2025

I will change to draft for now and we can reopen when we want to merge it - that is when we know in which version it will be added.

@sunkup sunkup marked this pull request as draft November 20, 2025 11:18
@rfc2822 rfc2822 force-pushed the 1737-enable-push-by-default branch from d4c00a0 to 6e0cde7 Compare December 11, 2025 14:33
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will finally be time 😄

As I understand it, the basic idea is to check/update the push distributor whenever the PushRegistrationWorker is run, instead of setting it explicitly from the UI.

This sounds good to me! However some notes.

(Also please fix conflicts)

# Conflicts:
#	app/src/ose/kotlin/at/bitfire/davdroid/di/OseFlavorModule.kt
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
@ArnyminerZ
Copy link
Member Author

ArnyminerZ commented Jan 29, 2026

As agreed on the meeting, FCM pre-selection for gplay variant is kept. So this should be ready for now. We can keep it improving later (actual distributor pinging to make sure it's available)

Note: The gplay preference should be established on the private repo

@ArnyminerZ ArnyminerZ marked this pull request as ready for review January 29, 2026 12:01
@ArnyminerZ ArnyminerZ requested a review from rfc2822 February 2, 2026 09:29
# Conflicts:
#	core/src/androidTest/kotlin/at/bitfire/davdroid/di/TestFlavorModule.kt
#	core/src/main/kotlin/at/bitfire/davdroid/push/PushDistributorManager.kt
#	core/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt
#	core/src/main/kotlin/at/bitfire/davdroid/ui/AppSettingsModel.kt
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ requested review from cketti and removed request for rfc2822 March 18, 2026 11:20
@rfc2822 rfc2822 self-assigned this Mar 20, 2026
@rfc2822 rfc2822 removed request for cketti and sunkup March 20, 2026 15:08
rfc2822 added 4 commits March 20, 2026 16:15
- Simplify push disable setting from `EXPLICIT_PUSH_DISABLE` to `PUSH_DISABLE`
- Improve push distributor list UI with better labels and icons
- Remove unused imports and `AppTheme` wrapper from previews
- Refactor `PushRegistrationManager.update()` to explicitly handle distributor, subscriptions, and worker updates
- Add thread-safety documentation for `update()` and `update(serviceId)`
- Fix push distributor preference comparison in `AppSettingsModel`
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automatic UnifiedPush distributor selection with an opt-out flag, and updates the settings UI to surface a “Recommended” distributor.

Changes:

  • Introduces PushDistributorManager to auto-select a distributor (preferred/first available) unless the user explicitly disabled push.
  • Adds Settings.PUSH_DISABLE to prevent auto-selection after the user disables push.
  • Updates distributor selection UI to show a “Recommended” label and adjusts how distributor icons/names are derived.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
core/src/main/res/values/strings.xml Adds “Recommended” label string for the distributor picker UI.
core/src/main/kotlin/at/bitfire/davdroid/ui/AppSettingsScreen.kt Updates distributor picker list rendering to display “Recommended” and simplifies icon handling.
core/src/main/kotlin/at/bitfire/davdroid/ui/AppSettingsModel.kt Switches to PushDistributorManager, computes preferred flag per distributor, and persists PUSH_DISABLE when user disables push.
core/src/main/kotlin/at/bitfire/davdroid/settings/Settings.kt Adds PUSH_DISABLE setting key with documentation.
core/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt Delegates distributor selection to PushDistributorManager during update flows and updates docs.
core/src/main/kotlin/at/bitfire/davdroid/push/PushDistributorManager.kt New: centralizes distributor selection and opt-out behavior via settings.
core/src/main/kotlin/at/bitfire/davdroid/push/PushDistributorDefaults.kt New: interface for build-variant preferred distributor selection.
core/src/main/kotlin/at/bitfire/davdroid/di/PushDistributorDefaultsModule.kt New: Hilt optional binding for PushDistributorDefaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Move push disable setting logic to `PushDistributorManager.setPushDistributor()`
- Update comments and docstrings for clarity
- Rename `pushDistributorPreferences` to `pushDistributorDefaults` in DI module
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Cache icon bitmap in `AppSettingsScreen` to avoid recomputation
- Add `PushRegistrationManager` to `AppSettingsModel` and update registrations on distributor change
- Improve `PushDistributorManager.getCurrentDistributor()` docs to clarify behavior when distributor is uninstalled
@rfc2822 rfc2822 requested a review from sunkup March 20, 2026 16:43
@rfc2822 rfc2822 marked this pull request as draft March 21, 2026 08:47
@rfc2822 rfc2822 removed the request for review from sunkup March 21, 2026 08:48
rfc2822 added 2 commits March 21, 2026 10:22
- Rename `update()` to `updateDistributor()` for consistency
- Improve comments and docstrings in `PushRegistrationManager`
- Add documentation for UnifiedPush callback behavior
@rfc2822 rfc2822 marked this pull request as ready for review March 21, 2026 09:43
- Add `CollectionDao.invalidatePushSubscriptions()` to clear push subscription expires
- Update `PushDistributorManager` to invalidate subscriptions when distributor changes
- Use application scope in `AppSettingsModel` to prevent interruption during push distributor updates
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will do nothing in davx5-ose, because there is no hradcoded/injected preference?

Also, sounds like this implementation will be superseeded by: #2091 (comment) so maybe we should do that instead of merging something unfinished?

I am not quite sure what the requirements for accepting an implementation are. The issue #1737 does not really look agreed and settled yet.

Also, since we need to work on the flavors across repos, maybe some sub-issues would be good?

@ArnyminerZ
Copy link
Member Author

I'd discuss this further after seeing #2091 and the official guide.

@rfc2822 rfc2822 removed their assignment Mar 23, 2026
@rfc2822 rfc2822 marked this pull request as draft March 26, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Implements a new feature or functionality (only for PRs) push Related to WebDAV-Push

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Push] Changing push distributor doesn't register subscriptions again Enable Push by default (first available UnifiedPush provider)

4 participants