4
4
5
5
package at.bitfire.davdroid.push
6
6
7
+ import at.bitfire.davdroid.di.ApplicationScope
7
8
import dagger.Lazy
8
9
import dagger.hilt.android.AndroidEntryPoint
9
10
import kotlinx.coroutines.CoroutineScope
10
- import kotlinx.coroutines.SupervisorJob
11
11
import kotlinx.coroutines.launch
12
12
import org.unifiedpush.android.connector.FailedReason
13
13
import org.unifiedpush.android.connector.PushService
@@ -25,6 +25,13 @@ import javax.inject.Inject
25
25
@AndroidEntryPoint
26
26
class UnifiedPushService : PushService () {
27
27
28
+ /* Scope to run the requests asynchronously. UnifiedPush binds the service,
29
+ * sends the message and unbinds one second later. Our operations may take longer,
30
+ * so the scope should not be bound to the service lifecycle. */
31
+ @Inject
32
+ @ApplicationScope
33
+ lateinit var applicationScope: CoroutineScope
34
+
28
35
@Inject
29
36
lateinit var logger: Logger
30
37
@@ -34,18 +41,13 @@ class UnifiedPushService : PushService() {
34
41
@Inject
35
42
lateinit var pushRegistrationManager: Lazy <PushRegistrationManager >
36
43
37
- /* Scope to run the requests asynchronously. UnifiedPush binds the service,
38
- * sends the message and unbinds one second later. Our operations may take longer,
39
- * so the scope should not be bound to the service lifecycle. */
40
- val serviceScope = CoroutineScope (SupervisorJob ())
41
-
42
44
43
45
override fun onNewEndpoint (endpoint : PushEndpoint , instance : String ) {
44
46
val serviceId = instance.toLongOrNull() ? : return
45
47
logger.warning(" Got UnifiedPush endpoint for service $serviceId : ${endpoint.url} " )
46
48
47
49
// register new endpoint at CalDAV/CardDAV servers
48
- serviceScope .launch {
50
+ applicationScope .launch {
49
51
pushRegistrationManager.get().processSubscription(serviceId, endpoint)
50
52
}
51
53
}
@@ -55,7 +57,7 @@ class UnifiedPushService : PushService() {
55
57
logger.warning(" UnifiedPush registration failed for service $serviceId : $reason " )
56
58
57
59
// unregister subscriptions
58
- serviceScope .launch {
60
+ applicationScope .launch {
59
61
pushRegistrationManager.get().removeSubscription(serviceId)
60
62
}
61
63
}
@@ -64,13 +66,13 @@ class UnifiedPushService : PushService() {
64
66
val serviceId = instance.toLongOrNull() ? : return
65
67
logger.warning(" UnifiedPush unregistered for service $serviceId " )
66
68
67
- serviceScope .launch {
69
+ applicationScope .launch {
68
70
pushRegistrationManager.get().removeSubscription(serviceId)
69
71
}
70
72
}
71
73
72
74
override fun onMessage (message : PushMessage , instance : String ) {
73
- serviceScope .launch {
75
+ applicationScope .launch {
74
76
pushMessageHandler.get().processMessage(message, instance)
75
77
}
76
78
}
0 commit comments