mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Fix SQL crash in backup restore by preventing job from running until restore complete.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.impl
|
||||
|
||||
import android.app.job.JobInfo
|
||||
import org.thoughtcrime.securesms.jobmanager.Constraint
|
||||
|
||||
/**
|
||||
* Constraint that, when added, means that a job cannot be performed while a backup restore or device transfer
|
||||
* is occurring.
|
||||
*/
|
||||
object DataRestoreConstraint : Constraint {
|
||||
|
||||
const val KEY = "DataRestoreConstraint"
|
||||
|
||||
@JvmStatic
|
||||
var isRestoringData: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
DataRestoreConstraintObserver.onChange()
|
||||
}
|
||||
|
||||
override fun isMet(): Boolean {
|
||||
return !isRestoringData
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun applyToJobInfo(jobInfoBuilder: JobInfo.Builder) = Unit
|
||||
|
||||
class Factory : Constraint.Factory<DataRestoreConstraint> {
|
||||
override fun create(): DataRestoreConstraint {
|
||||
return DataRestoreConstraint
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.impl
|
||||
|
||||
import org.thoughtcrime.securesms.jobmanager.ConstraintObserver
|
||||
|
||||
/**
|
||||
* An observer for the [DataRestoreConstraint]. This class expects to be told when a change happens,
|
||||
* since the points at which it happens are triggered by application code.
|
||||
*/
|
||||
object DataRestoreConstraintObserver : ConstraintObserver {
|
||||
|
||||
private const val REASON = "DataRestoreConstraint"
|
||||
|
||||
private var notifier: ConstraintObserver.Notifier? = null
|
||||
|
||||
override fun register(notifier: ConstraintObserver.Notifier) {
|
||||
this.notifier = notifier
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the observer know that the change number state has changed.
|
||||
*/
|
||||
fun onChange() {
|
||||
if (DataRestoreConstraint.isMet) {
|
||||
notifier?.onConstraintMet(REASON)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user