Fix backup message job cancel and start bugs.

This commit is contained in:
Cody Henthorne
2025-07-16 14:21:59 -04:00
committed by GitHub
parent 141faf3fb6
commit 8ee80b0d27
11 changed files with 135 additions and 17 deletions

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.jobmanager.impl
import android.app.Application
import android.app.job.JobInfo
import android.content.Context
import org.thoughtcrime.securesms.jobmanager.Constraint
import org.thoughtcrime.securesms.keyvalue.SignalStore
/**
* Constraint that, when added, means that a job cannot be performed unless the user either has Wifi or, if they enabled it, cellular
*/
class BackupMessagesConstraint(private val application: Application) : Constraint {
companion object {
const val KEY = "BackupMessagesConstraint"
fun isMet(context: Context): Boolean {
if (SignalStore.backup.backupWithCellular) {
return NetworkConstraint.isMet(context)
}
return WifiConstraint.isMet(context)
}
}
override fun isMet(): Boolean {
return isMet(application)
}
override fun getFactoryKey(): String = KEY
override fun applyToJobInfo(jobInfoBuilder: JobInfo.Builder) = Unit
class Factory(val application: Application) : Constraint.Factory<BackupMessagesConstraint> {
override fun create(): BackupMessagesConstraint {
return BackupMessagesConstraint(application)
}
}
}

View File

@@ -0,0 +1,27 @@
package org.thoughtcrime.securesms.jobmanager.impl
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.jobmanager.ConstraintObserver
/**
* An observer for the [BackupMessagesConstraint]. This is called when users change whether or not backup is allowed via cellular
*/
object BackupMessagesConstraintObserver : ConstraintObserver {
private const val REASON = "BackupMessagesConstraint"
private var notifier: ConstraintObserver.Notifier? = null
override fun register(notifier: ConstraintObserver.Notifier) {
this.notifier = notifier
}
/**
* Let the observer know that the backup using cellular flag has changed.
*/
fun onChange() {
if (BackupMessagesConstraint.isMet(AppDependencies.application)) {
notifier?.onConstraintMet(REASON)
}
}
}