Cleanup FetchPushForegroundService (#6577)
* 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>
This commit is contained in:
parent
8853f160e2
commit
f80a140cf9
17 changed files with 329 additions and 215 deletions
|
|
@ -15,7 +15,7 @@ import dev.zacsweers.metro.Inject
|
|||
import io.element.android.libraries.architecture.bindings
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.di.annotations.AppCoroutineScope
|
||||
import io.element.android.libraries.push.api.push.PushHandlingWakeLock
|
||||
import io.element.android.libraries.push.api.push.FetchPushForegroundServiceManager
|
||||
import io.element.android.libraries.pushproviders.api.PushHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -27,7 +27,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
@Inject lateinit var firebaseNewTokenHandler: FirebaseNewTokenHandler
|
||||
@Inject lateinit var pushParser: FirebasePushParser
|
||||
@Inject lateinit var pushHandler: PushHandler
|
||||
@Inject lateinit var pushHandlingWakeLock: PushHandlingWakeLock
|
||||
@Inject lateinit var fetchPushForegroundServiceManager: FetchPushForegroundServiceManager
|
||||
@AppCoroutineScope
|
||||
@Inject lateinit var coroutineScope: CoroutineScope
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
val isHighPriority = message.priority == PRIORITY_HIGH
|
||||
if (isHighPriority) {
|
||||
// Acquire wakelock to ensure the device stays awake while we handle the push and schedule and run the work
|
||||
pushHandlingWakeLock.lock()
|
||||
fetchPushForegroundServiceManager.start()
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
|
|
@ -63,7 +63,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
},
|
||||
)
|
||||
if (isHighPriority) {
|
||||
pushHandlingWakeLock.unlock()
|
||||
fetchPushForegroundServiceManager.stop()
|
||||
}
|
||||
} else {
|
||||
val handled = pushHandler.handle(
|
||||
|
|
@ -73,7 +73,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
|
||||
// If we failed to handle the push, we should release the wakelock early to avoid keeping the device awake for too long.
|
||||
if (!handled && isHighPriority) {
|
||||
pushHandlingWakeLock.unlock()
|
||||
fetchPushForegroundServiceManager.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue