Skip to content

Commit d93ed99

Browse files
committed
Remove unused service repository dependency and update worker to suspend
1 parent 1dadfda commit d93ed99

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ data class Collection(
138138
val supportsWebPush: Boolean = false,
139139

140140
/** WebDAV-Push: VAPID public key */
141-
// TODO: add non-unique index
142141
val pushVapidKey: String? = null,
143142

144143
/** WebDAV-Push subscription URL */

app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import at.bitfire.davdroid.repository.DavServiceRepository
3232
import dagger.Lazy
3333
import dagger.hilt.android.qualifiers.ApplicationContext
3434
import kotlinx.coroutines.Dispatchers
35-
import kotlinx.coroutines.runBlocking
3635
import kotlinx.coroutines.runInterruptible
3736
import kotlinx.coroutines.withContext
3837
import okhttp3.HttpUrl
@@ -92,7 +91,7 @@ class PushRegistrationManager @Inject constructor(
9291
else
9392
UnifiedPush.unregister(context, serviceId.toString())
9493

95-
// UnifiedPush has now been called. It will do its work and then call back to UnifiedPushService, which
94+
// UnifiedPush has now been called. It will do its work and then asynchronously call back to UnifiedPushService, which
9695
// will then call processSubscription or removeSubscription.
9796
}
9897

@@ -158,13 +157,13 @@ class PushRegistrationManager @Inject constructor(
158157
/**
159158
* Called when no subscription is available (anymore) for the given service.
160159
*
161-
* Unsubscribes from all collections.
160+
* Unsubscribes from all subscribed collections.
162161
*/
163-
internal suspend fun removeSubscription(serviceId: Long) {
164-
val service = serviceRepository.get(serviceId) ?: return
162+
internal suspend fun removeSubscription(serviceId: Long) = withContext(dispatcher) {
163+
val service = serviceRepository.get(serviceId) ?: return@withContext
165164
val unsubscribeFrom = collectionRepository.getPushRegistered(service.id)
166165
if (unsubscribeFrom.isEmpty())
167-
return
166+
return@withContext
168167

169168
val account = accountRepository.get().fromName(service.accountName)
170169
httpClientBuilder.get()
@@ -268,10 +267,8 @@ class PushRegistrationManager @Inject constructor(
268267
*
269268
* Otherwise, a potentially existing worker is cancelled.
270269
*/
271-
fun updatePeriodicWorker() {
272-
val workerNeeded = runBlocking {
273-
collectionRepository.anyPushCapable()
274-
}
270+
suspend fun updatePeriodicWorker() = withContext(dispatcher) {
271+
val workerNeeded = collectionRepository.anyPushCapable()
275272

276273
val workManager = WorkManager.getInstance(context)
277274
if (workerNeeded) {
@@ -301,6 +298,9 @@ class PushRegistrationManager @Inject constructor(
301298
private const val WORKER_UNIQUE_NAME = "push-registration"
302299
const val WORKER_INTERVAL_DAYS = 1L
303300

301+
/**
302+
* Single-thread dispatcher to synchronize tasks.
303+
*/
304304
val dispatcher = Dispatchers.IO.limitedParallelism(1)
305305

306306
}

app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationWorker.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.content.Context
88
import androidx.hilt.work.HiltWorker
99
import androidx.work.CoroutineWorker
1010
import androidx.work.WorkerParameters
11-
import at.bitfire.davdroid.repository.DavServiceRepository
1211
import dagger.assisted.Assisted
1312
import dagger.assisted.AssistedInject
1413
import java.util.logging.Logger
@@ -24,8 +23,7 @@ class PushRegistrationWorker @AssistedInject constructor(
2423
@Assisted context: Context,
2524
@Assisted workerParameters: WorkerParameters,
2625
private val logger: Logger,
27-
private val pushRegistrationManager: PushRegistrationManager,
28-
private val serviceRepository: DavServiceRepository
26+
private val pushRegistrationManager: PushRegistrationManager
2927
) : CoroutineWorker(context, workerParameters) {
3028

3129
override suspend fun doWork(): Result {

app/src/main/kotlin/at/bitfire/davdroid/repository/PreferenceRepository.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class PreferenceRepository @Inject constructor(
2525

2626
companion object {
2727
const val LOG_TO_FILE = "log_to_file"
28-
const val UNIFIED_PUSH_ENDPOINT_URL = "unified_push_endpoint_url"
29-
const val UNIFIED_PUSH_ENDPOINT_KEY = "unified_push_endpoint_key"
30-
const val UNIFIED_PUSH_ENDPOINT_AUTH = "unified_push_endpoint_auth"
3128
}
3229

3330
private val preferences = PreferenceManager.getDefaultSharedPreferences(context)

0 commit comments

Comments
 (0)