This happens when building a `ShortcutInfoCompat` in `DefaultNotificationConversationService.onSendMessage` when the provided room name is not null but it's empty.
`AnalyticsLongRunningTransaction.PushToWorkManager` was incorrectly used instead of `AnalyticsLongRunningTransaction.PushToNotification`, resulting in wrongly formatter analytic traces
* Improve `FetchPushForegroundService`'s reliability
- Don't use DI, we can just create the notification channel. This should speed up the creation of the service and reduce the number of `ForegroundServiceDidNotStartInTimeException` received. Also use `MainScope` instead of the app's coroutine scope.
- Move the wakelock releasing mechanism to `onDestroy` so it's always used. Previously, this would only happen when `stopService` was called, which would only happen when `stopSelf()` is called, but not when the OS or the service manager stops the service.
* Add fallback value for the notification channel title
* Replace the wrong string for the notification/channel title
---------
Co-authored-by: Benoit Marty <benoitm@element.io>
* Set `DmRoomDefinition.TwoPeople` in `ClientBuilder`. This applies the 'direct and with at most 2 non-service members' rule to what the SDK should consider a DM.
* Map `RoomInfo.isDm` from the SDK
* Map `NotificationData.isDm` from `NotificationInfo.roomInfo.isDm`
* Remove `RoomIsDmCheck` file as its extension functions are now redundant. Move `Room.isDm` helper function to `BaseRoom`.
* Map `isDm` in `SpaceRoom` from the SDK too
* Replace `isDirect` with `isDm` where possible
* Map `RoomMember.isServiceMember` from the SDK and use it to tell apart normal members of a room from service members (i.e. `RoomMembersState.getDirectRoomMember`)
In Sentry there are some reports of methods called when notifications are fetched that end up having ANRs. This looked weird because everything is asynchronous... but it's still running with a `Main` dispatcher.
Using the `Default/computation` one instead should be the right call.
* Sync Strings from Localazy
* Use the previous plurals as plain strings
* Add extra case for 1 vs multiple users
* Update screenshots
---------
Co-authored-by: Jorge Martín <jorgem@element.io>
* Rename `PushHandlingWakeLock` to `FetchPushForegroundServiceManager`. Move the start/stop logic from `FetchPushForegroundService.Companion` to it.
* Add more tests using Robolectric.
* Remove `FeatureFlags.SyncNotificationsWithWorkManager` and associated code: this should have been removed in one of the previous refactors, since we don't have the 2 ways to sync notifications anymore, everything uses the `WorkManager`
---------
Co-authored-by: Benoit Marty <benoit@matrix.org>
* Fix `isInAirGappedEnvironment` check for older APIs: use `networkCapabilities.hasCapability` instead of `networkCapabilities.capabilities.contains`, which only works on Android 12 and newer versions
* Check for air-gapped env in the FOSS app too: this unifies the notification behaviour on EXA and Element Pro
* Add support for slash commands
* Update screenshots
* Rename module `slash` to `slashcommands`
* Rename `SlashCommand` to `SlashCommandService`
* Introduce MsgType in order to send text message with a different msgtype value.
* Format file and add parameter names, add default values and cleanup
* Add isSupported parameter to filter out unsupported yet commands.
* Slash commands: disable suggestions if the feature is disabled.
* Fix sending shrug command.
* Add missing test on SuggestionsProcessor
* Add tests on MessageComposerPresenter about slash command.
* Fix import ordering
* Add missing tests on CommandExecutor
* Add missing tests in MarkdownTextEditorStateTest
* Slash commands: Improve code when sending message with prefix.
* Slash commands: Add support for /unflip
---------
Co-authored-by: ElementBot <android@element.io>
* Tentative fix for `ForegroundServiceStartNotAllowedException`
When failing to start the service in foreground, don't crash. This is a helper to speed up the scheduling by keeping the CPU awake, not a critical part that should succeed
* Simplify `DefaultPushHandlingWakeLock`
It seems like restarting the service from background won't work in some cases, so don't try it.
* Try handling `ForegroundServiceStartNotAllowedException` better
The docs mention starting a foreground service when the app is on background is allowed when FCM receives a high priority notification, so we don't do it if the priority is not high.
Also, we handle the case where starting the foreground service fails so it doesn't crash the app.
* Start the `FetchPushForegroundService ` in foreground ASAP. This is a first step to mitigate `ForegroundServiceDidNotStartInTimeException` being thrown.
* Don't stop the service immediately if it's running but not in foreground. Try waiting up to 5s for it to be in foreground.
If notifications for a device are disabled when there is no connection with the HS, the push registration will still exist, so the device can still receive push notifications.
In that cases, we were running into an issue where the wakelock for push notifications was started immediately after receiving a push but was never stopped and it ran for 3 minutes until its timeout, keeping the device awake for no reason.
This patch changes `DefaultPushHandler` so if we don't need the wakelock it returns `false` and we can stop the wakelock early.
* 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
* 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.
* 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.
* Update metro to v0.11.2
* Bind push tests to the right scope .Add a comment so we don't forget to do it for future ones.
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jorge Martín <jorgem@element.io>
- Added `MediaSource.safeUrl` property replacing `withCleanUrl` method.
- Made `url` private so it can't be used externally.
- Reverted code in `CoilMediaFetcher`
- Also add tests
* Update metro to v0.11.0
* Fix `@AssistedInject` usages
Now the injected variables in the factories must match the names in the constructors
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jorge Martín <jorgem@element.io>
* Add `NetworkMonitor.isNetworkBlocked()`, use it to check if Doze prevented us from loading notifications
* Only check if network is blocked after checking if we have a network available, otherwise it's always `true`
* Extract `NetworkBlockedChecker` to handle deprecations more carefully