mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Fix backup message job cancel and start bugs.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user