Commit Graph

46 Commits

Author SHA1 Message Date
Jorge Martin Espinosa
f77098ed47 Add network constraints for fetching notifications with WorkManager (#6305)
* Add `isNetworkBlocked` and `isInAirGappedEnvironment` to `NetworkMonitor`.

* Improve the DI of `SyncPendingNotificationsRequestBuilder` to simplify its usage.

* Only update `isInAirGappedEnvironment` in `DefaultNetworkManager` if the current build is an enterprise one.

* Add network constraints to `DefaultSyncPendingNotificationsRequestBuilder` based on the air-gapped status.

* Add a feature flag to disable the new check, in case it doesn't work as expected.
2026-03-10 12:44:31 +00:00
Jorge Martin Espinosa
721add707c Simplify push notification flow by using locally stored values for pending pushes (#6258)
* Create `PushRequest` in push history DB: this will be used to store requests for push notifications, either pending or completed ones.

* Rename `WorkManagerRequest` to `WorkManagerRequestBuilder`: make its `build` method return a list of `WorkManagerRequestWrapper`, which can be used to enqueue normal or unique workers.

* Rename `PerformDatabaseVacuumRequestBuilder` and adapt it to the new API.

* Adjust other components using `WorkManagerRequest`.

* Replace `SyncNotificationWorkManagerRequestBuilder` with `SyncPendingNotificationsRequestBuilder` and `FetchNotificationsWorker` with `FetchPendingNotificationsWorker`: this new pair of request builder and worker allow enqueuing requests for a session id and, once the worker runs, retrieve all the pending request data and use it to fetch the associated events. This simplifies quite a bit how this data had to be passed or grouped, since it's no longer necessary to do so

* Add new methods to `PushHistoryService` to modify the `PushDatabase`:

- insertOrUpdatePushRequest
- insertOrUpdatePushRequests
- getPendingPushRequests
- removeOldPushRequests

* Make `PushHandler` just handle incoming pushes: those will be inserted into the pending push request table in DB, then handled by the new worker. Once the process finished, a new `NotificationResultProcessor` will handle the results and what needs to be done with them (call ringing, displaying notifications, etc.)

* Add `requestType` optional parameter to `WorkManagerScheduler.cancel` so we can decide to only cancel some kinds of requests.

* Add migration to remove existing work manager requests for fetching notifications, since the previous worker class no longer exists.
2026-03-03 15:14:36 +00:00
Benoit Marty
ced5af18d0 Do not attempt to restore the pusher after 2 removal in a short time. 2025-11-13 23:15:00 +01:00
Benoit Marty
13854bb2c7 Ensure that disabling (resp. enabling) notification unregisters (resp. registers) the pusher 2025-11-13 17:50:21 +01:00
Benoit Marty
2b4d80df01 UnifiedPush: emit error when registration fails.
Note that I did not manage to have the method `onRegistrationFailed` invoked. If the network is not available for instance, unregistering the previous pusher will fail first.
2025-11-13 14:56:20 +01:00
Benoit Marty
185d4fadde Let notifications use avatar fallback.
Extract code which handles Matrix image to its own api / impl / test modules.
2025-11-12 11:28:42 +01:00
Benoit Marty
1292da2a72 Copyright: Add Element Creations Ltd. copyright 2025-11-10 11:05:05 +01:00
Benoit Marty
b748fcc631 Copyright: Add final period 2025-11-10 10:13:41 +01:00
Benoit Marty
0a0224b586 Copyright: run command uv run license-editor --repository ../element-x-android 2025-11-10 10:09:26 +01:00
Benoit Marty
fbecf8d34f Let DefaultNotificationDrawerManager use NotificationDisplayer instead of NotificationManagerCompat 2025-10-31 09:29:48 +01:00
Jorge Martin Espinosa
7facc40771 Split notifications for messages in threads (#5595)
* Separate thread notifications into their own notifications when the feature flag is enabled.

Otherwise, set the `threadId` to null so it'll behave as usual. It's done this way to avoid having to inject `FeatureFlagService` in several places.

* Add permalink navigation to threads from notifications, focusing on the latest event in the list of messages of the notification tapped

* Fix redactions in threads

* Clear notifications for a thread when visiting it

* Fix opening a thread happening twice, first because of the `openThreadId` value, then because of the `focusedEventId` one

* Make opening a room through a notification also focus on the latest event

* Add helper `NotificationCreator.messageTag` function

* Remove unused `ROOM_CALL_NOTIFICATION_ID`: `FOREGROUND_SERVICE_NOTIFICATION_ID`+ `ForegroundServiceType` is used instead

* Simplify `DefaultDeepLinkCreator`

* Make sure the main timeline focuses on the thread root id too when navigating to a thread

* Handle "Mark as read" action for thread notification, using `timeline.markAsRead`

* Log failures to mark rooms as read using the notification action

---------

Co-authored-by: Benoit Marty <benoit@matrix.org>
2025-10-30 15:15:00 +00:00
Benoit Marty
c53dabce16 Remove dependency on AppNavigationStateService from DefaultGetCurrentPushProvider 2025-10-23 15:03:04 +02:00
Jorge Martin Espinosa
597c9b473a Sync notifications using WorkManager (#5545)
* Initial implementation of notification sync using `WorkManager`

* Use custom `MetroWorkerFactory` to allow assisted injection in WorkManager Workers

* Add tests for `FetchNotificationWorker`. Create `FakeNotificationResolverQueue` to help testing.

* Add more tests, fix Konsist checks

* Add tests for `SyncNotificationWorkManagerRequest`

* Simplify `FakeNotificationResolverQueue`
2025-10-17 09:51:27 +00:00
Jorge Martin Espinosa
59a8aaebff Add shortcut suggestions for rooms, remove then when leaving (#5180)
* Report shortcut usage for outgoing messages

This patch adds support for creating and pushing dynamic
long-lived shortcuts for outgoing messages. This together
with an existing reference to the roomId used by the
shortcuts as an identifer allows conversations to be
prioritized.

See https://developer.android.com/training/sharing/direct-share-targets#report-usage-outgoing

* Simplify how to get the other user in a DM room

* Add initial avatar icons to shortcuts

* Remove room shortcuts when they're no longer joined

* Try using API 33 for the new tests. They worked locally with API 30, so it's weird the CI asks for a higher API version.

* Add observers for the pin code and session logout states. With this we can prevent new shortcuts from being created and remove existing ones when needed.

* Wrap all calls to `ShortcutManagerCompat` with `runCatchingExceptions` to avoid crashes

* Make `DefaultNotificationConversationService` a singleton.

---------

Co-authored-by: networkException <git@nwex.de>
Co-authored-by: ElementBot <android@element.io>
2025-08-19 16:02:51 +02:00
Benoit Marty
d8095faa43 Ensure that the battery optimization banner is not displayed after an internal clear cache. 2025-06-17 16:31:35 +02:00
Jorge Martin Espinosa
30067b2a50 Keep call notification ringing while a call is present in the room (#4634) 2025-05-09 11:38:43 +02:00
Benoit Marty
f916e4e3d4 Push: improve Push history screen, log and stored data (#4601)
* Add adb tools to help with doze mode and app standby

* Add info about the device state when an error occurs in push.

* Keep more events in the DB.

* Push history: add confirmation dialog when resetting the data

* Push history: add a filter to see only the errors

* Update screenshots

* Push history: print out invalid/ignored data received.

* Increase log level for push, to make such log more visible.
It also appears that sometimes Timber.d are not present in the rageshakes.

* Log priority

* Do not include device state for invalid/ignored event.

* Fix tests.

* Fix format issue.

* Fix mistake in code blocks and do not filter when not necessary.

* Improve formatting and add missing unit test.

* Reduce nesting of blocks.

---------

Co-authored-by: ElementBot <android@element.io>
2025-04-16 16:37:32 +02:00
Benoit Marty
a1d8322738 Introduce PushHistoryService to store data about the received push (#4573)
* Introduce PushHistoryService to store data about the received push

Add a push database.

* Update screenshots

* Improve preview.

* Update screenshots

* Add missing test.

* Add test for PushHistoryView

* Fix configuration issue.

Was: w: /libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt:35:27 Cannot access class 'PushProvider' in the expression type. While it may work, this case indicates a configuration mistake and can lead to avoidable compilation errors, so it may be forbidden soon. Check your module classpath for missing or conflicting dependencies.

---------

Co-authored-by: ElementBot <android@element.io>
2025-04-11 12:56:54 +02:00
Benoit Marty
3a09d1c4ca Migrate to coil3 2025-03-03 12:30:26 +01:00
Benoit Marty
05fc76822a Apply dual licenses: AGPL + Element Commercial to file headers.
2 replace all actions have been performed:
- "SPDX-License-Identifier: AGPL-3.0-only" to "SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial"
- "Please see LICENSE in the repository root for full details." to "Please see LICENSE files in the repository root for full details."
2025-01-07 10:05:04 +01:00
Benoit Marty
40e727f2e4 Change signature of selectPushProvider and add missing unit test. 2024-11-15 15:13:24 +01:00
Benoit Marty
2b016227e9 Migrate license to AGPL.
Run script `uv run license-editor --repository ../element-x-android`
2024-09-06 17:19:19 +02:00
Benoit Marty
2585f8ba52 Rename interface NotificationDrawerManager to NotificationCleaner since it actually contains only method to remove notifications. 2024-07-16 11:24:41 +02:00
Benoit Marty
775cb89993 Fix image not rendering after clearing cache. 2024-06-24 13:58:15 +02:00
Benoit Marty
83bfa3d9fc Update test after merging develop. 2024-06-18 10:33:07 +02:00
Benoit Marty
622cc35616 Store the first provider even if no distributor is available, else error in troubleshoot test will not be accurate.
Also when registering for the first time, pick the fist available provider with at least one distributor.
2024-06-17 17:36:39 +02:00
Benoit Marty
366d6c017d Add ability to not show the pusher registration again. 2024-06-17 11:38:32 +02:00
Benoit Marty
3eaf780087 Add test on pusher registration 2024-06-17 11:30:22 +02:00
Jorge Martin Espinosa
cef8302dd0 Notify of ringing call when there's an active call (#3003)
* Add `CallNotificationEventResolver` to be able to force the new ringing notification to be non-ringing given an existing ringing one.
2024-06-10 15:03:06 +00:00
Jorge Martin Espinosa
6f8de0b2c6 Element Call ringing notifications (#2978)
- Add `ActiveCallManager` to handle incoming and ongoing calls.
- Add ringing call notifications with full screen intents and missed call ones as part of the 'conversation' notifications.

---------

Co-authored-by: ElementBot <benoitm+elementbot@element.io>
2024-06-10 11:51:19 +02:00
Benoit Marty
c973e70b6b Fix formatting issues. 2024-06-05 15:13:04 +02:00
Benoit Marty
625c8aa27e Add test on NotificationBroadcastReceiverHandler 2024-06-05 14:59:51 +02:00
Benoit Marty
6f12820e0b Let NotificationBroadcastReceiver inject NotificationDrawerManager instead of implementation 2024-06-05 14:59:47 +02:00
Jorge Martin Espinosa
801f0b955d Notifications: simplify the flow by removing persistence (#2924)
* Notifications: simplify the flow by removing persistence. 
* Bump of minSdk to `24` (Android 7).
* Add migration to remove `notification.bin` file
2024-05-29 08:03:23 +00:00
Benoit Marty
25c20f1734 Set the value of currentDistributorName by reading again the value from the service. 2024-05-28 14:08:20 +02:00
Benoit Marty
4fc3c6f889 Introduce lambdaError instead of using TODO, to handle error when a lambda is invoked and it should not. 2024-05-23 09:12:40 +02:00
Benoit Marty
c0fccae12e Add test on VectorFirebaseMessagingService 2024-05-22 17:57:35 +02:00
Benoit Marty
233052a3d5 Remove unused code notificationStyleChanged()
We may properly add it again later if necessary.
2024-05-22 11:31:56 +02:00
Benoit Marty
a6dd7b4c18 Add test for FirebasePushProvider 2024-05-22 11:27:20 +02:00
Benoit Marty
3ace9aa160 Add test for push distributor change. 2024-05-21 14:45:20 +02:00
Benoit Marty
6de5e7b3f5 Add missing methods. 2024-05-21 14:45:18 +02:00
Benoit Marty
4bd01b6f4f Improve API, to avoid ignoring errors 2024-05-21 14:45:16 +02:00
Benoit Marty
8588ce7a72 Troubleshoot notifications screen 2024-04-02 16:15:00 +02:00
Benoit Marty
5ff74caed8 Create FakePushService. 2024-04-02 16:14:59 +02:00
Benoit Marty
096c935874 Do not render notification if the user has dismiss the notification.
It should not change anything, just avoid doing useless notification rendering.
2023-09-15 15:42:55 +02:00
Jorge Martin Espinosa
9170c5eb71 Display room invitation notification (#735)
* Notifications: Add some extra mappings so we keep the original contents and can pass it later to an UI layer

* Fix notifications not appearing for a room if the app was on that room when it went to background.

* Modernize how we create spannable strings for notifications, remove unneeded dependency

* Remove actions from invite notifications temporarily

* Add `NotificationDrawerManager` interface to be able to clear membership notifications when accepting or rejecting a room invite

* Fix tests

* Add comment to clarify some weird behaviours

* Address review comments

* Set circle shape for `largeBitmap` in message notifications

* Fix no avatar in DM rooms

* Fix rebase issues

* Add invite list pending intent:

- Refactor pending intents.
- Make `DeepLinkData` a sealed interface.
- Fix and add tests.

* Rename `navigate__` functions to `attach__`

* Add an extra test case for the `InviteList` deep link

* Address most review comments.

* Fix rebase issue

* Add fallback notification type, allow dismissing invite notifications.

Fallback notifications have a different underlying type and can be dismissed at will.

* Fix tests
2023-07-10 14:34:58 +02:00