From 597c9b473a03d1da80ef7c2c29621ca65213f5ab Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Fri, 17 Oct 2025 11:51:27 +0200 Subject: [PATCH] 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` --- app/src/main/AndroidManifest.xml | 10 +- .../element/android/x/ElementXApplication.kt | 9 +- .../io/element/android/x/di/AppGraph.kt | 8 + features/logout/impl/build.gradle.kts | 2 + .../features/logout/impl/LogoutPresenter.kt | 5 + .../logout/impl/LogoutPresenterTest.kt | 11 +- .../impl/reporter/DefaultBugReporterTest.kt | 2 +- gradle/libs.versions.toml | 2 + .../libraries/featureflag/api/FeatureFlags.kt | 8 + .../push/api/push/NotificationEventRequest.kt | 19 ++ .../push/api/push/SyncOnNotifiableEvent.kt | 12 + libraries/push/impl/build.gradle.kts | 4 + .../DefaultNotifiableEventResolver.kt | 6 +- .../NotificationResolverQueue.kt | 58 +++-- .../push/impl/push/DefaultPushHandler.kt | 11 +- ...ent.kt => DefaultSyncOnNotifiableEvent.kt} | 18 +- .../impl/push/OnNotifiableEventReceived.kt | 2 - .../workmanager/FetchNotificationsWorker.kt | 123 +++++++++++ .../SyncNotificationWorkManagerRequest.kt | 87 ++++++++ .../DefaultNotifiableEventResolverTest.kt | 1 + .../FakeNotifiableEventResolver.kt | 1 + .../NotificationEventRequestFixture.kt | 28 +++ .../push/impl/push/DefaultPushHandlerTest.kt | 63 +++++- .../impl/push/SyncOnNotifiableEventTest.kt | 62 +----- .../FetchNotificationWorkerTest.kt | 206 ++++++++++++++++++ .../SyncNotificationWorkManagerRequestTest.kt | 50 +++++ .../FakeNotificationResolverQueue.kt | 23 ++ libraries/workmanager/api/build.gradle.kts | 23 ++ .../workmanager/api/WorkManagerRequest.kt | 14 ++ .../workmanager/api/WorkManagerScheduler.kt | 26 +++ .../workmanager/api/di/MetroWorkerFactory.kt | 35 +++ .../libraries/workmanager/api/di/WorkerKey.kt | 18 ++ libraries/workmanager/impl/build.gradle.kts | 24 ++ .../impl/DefaultWorkManagerScheduler.kt | 47 ++++ libraries/workmanager/test/build.gradle.kts | 19 ++ .../test/FakeWorkManagerScheduler.kt | 26 +++ .../kotlin/extension/DependencyHandleScope.kt | 1 + .../tests/konsist/KonsistClassNameTest.kt | 2 + 38 files changed, 968 insertions(+), 98 deletions(-) create mode 100644 libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/push/NotificationEventRequest.kt create mode 100644 libraries/push/api/src/main/kotlin/io/element/android/libraries/push/api/push/SyncOnNotifiableEvent.kt rename libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/{SyncOnNotifiableEvent.kt => DefaultSyncOnNotifiableEvent.kt} (74%) create mode 100644 libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/workmanager/FetchNotificationsWorker.kt create mode 100644 libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/workmanager/SyncNotificationWorkManagerRequest.kt create mode 100644 libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotificationEventRequestFixture.kt create mode 100644 libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/workmanager/FetchNotificationWorkerTest.kt create mode 100644 libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/workmanager/SyncNotificationWorkManagerRequestTest.kt create mode 100644 libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/notifications/FakeNotificationResolverQueue.kt create mode 100644 libraries/workmanager/api/build.gradle.kts create mode 100644 libraries/workmanager/api/src/main/kotlin/io/element/android/libraries/workmanager/api/WorkManagerRequest.kt create mode 100644 libraries/workmanager/api/src/main/kotlin/io/element/android/libraries/workmanager/api/WorkManagerScheduler.kt create mode 100644 libraries/workmanager/api/src/main/kotlin/io/element/android/libraries/workmanager/api/di/MetroWorkerFactory.kt create mode 100644 libraries/workmanager/api/src/main/kotlin/io/element/android/libraries/workmanager/api/di/WorkerKey.kt create mode 100644 libraries/workmanager/impl/build.gradle.kts create mode 100644 libraries/workmanager/impl/src/main/kotlin/io/element/android/libraries/workmanager/impl/DefaultWorkManagerScheduler.kt create mode 100644 libraries/workmanager/test/build.gradle.kts create mode 100644 libraries/workmanager/test/src/main/kotlin/io/element/android/libraries/workmanager/test/FakeWorkManagerScheduler.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 26e8c7dc23..bcfcd71b94 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,10 +34,17 @@ + android:exported="false" + tools:node="merge"> + + +