* Create `PushHandlingWakeLock` to start a foreground service:
When receiving a push and scheduling the notification fetching, several problems can happen:
1. Some async operation is waiting for a timeout and it takes way longer than that to finish (i.e. timeout of 10s but it took 30s to advance).
2. The same, but when starting new coroutines. I've seen the time between scheduling a coroutine and it running sometimes take up to 1 minute.
3. Notification fetching can be scheduled immediately, but it can take a while to actually run because the OS understands the app is now in Doze.
Having a wakelock that runs as soon as the push handling starts fixes these: it continues the previous wakelock held by either Firebase or the UnifiedPush distributor.
* Acquire the wakelock as soon as we received the pushes in both receivers
* Also release the wakelock ahead of time if possible
* 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.
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.
* 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>
* Add `getForegroundInfo` implementation to try to fix issues with WorkManager on Android 12 and below
This may be a MIUI-only issue as I couldn't reproduce it with several emulators on Android 11, 12 and 13.
* Use `setExpedited` only on Android 13 or higher, it's not needed on older versions
* Use an actual string resource, fix tests
* Fix review comments
* Fix broken test with Element Pro:
Instead of using Robolectric with API < 33 (since Pro uses minSdk 33) use a `BuildVersionSdkIntProvider`
* Remove `getForegroundInfo` and the associated permission, as we expect it to be dead code
* Fix lint issues
* Cleanup NotificationIdProvider
---------
Co-authored-by: Benoit Marty <benoit@matrix.org>
* 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`
* 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>
* 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>
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."
- 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>
* 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
* Update AGP to 8.0.0.
* Set JAVA_HOME to JDK17
* Update lint version.
* Use right JDK for dependency analysis, replace deprecated env var.
* Upgrade to Gradle 8.1.
* Remove `@Supress(DSL_SCOPE_VIOLATION)` as it's no longer needed.
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>