Add cellular backup toggle for message backup.
This commit is contained in:
parent
83c34dd4cc
commit
ba4cdea75d
5 changed files with 42 additions and 2 deletions
|
@ -31,7 +31,7 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
|||
val state: State<RemoteBackupsSettingsState> = internalState
|
||||
|
||||
fun setCanBackUpUsingCellular(canBackUpUsingCellular: Boolean) {
|
||||
// TODO [message-backups] -- Update via repository?
|
||||
SignalStore.backup().backupWithCellular = canBackUpUsingCellular
|
||||
internalState.value = state.value.copy(canBackUpUsingCellular = canBackUpUsingCellular)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 org.thoughtcrime.securesms.jobmanager.Constraint
|
||||
import org.thoughtcrime.securesms.util.NetworkUtil
|
||||
|
||||
/**
|
||||
* Constraint that, when added, means that a job cannot be performed unless the user has Wifi
|
||||
*/
|
||||
class WifiConstraint(private val application: Application) : Constraint {
|
||||
|
||||
companion object {
|
||||
const val KEY = "WifiConstraint"
|
||||
}
|
||||
|
||||
override fun isMet(): Boolean {
|
||||
return NetworkUtil.isConnectedWifi(application)
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun applyToJobInfo(jobInfoBuilder: JobInfo.Builder) = Unit
|
||||
|
||||
class Factory(val application: Application) : Constraint.Factory<WifiConstraint> {
|
||||
override fun create(): WifiConstraint {
|
||||
return WifiConstraint(application)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.database.SignalDatabase
|
|||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.WifiConstraint
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
|
@ -43,7 +44,7 @@ class BackupMessagesJob private constructor(parameters: Parameters) : BaseJob(pa
|
|||
|
||||
constructor() : this(
|
||||
Parameters.Builder()
|
||||
.addConstraint(NetworkConstraint.KEY)
|
||||
.addConstraint(if (SignalStore.backup().backupWithCellular) NetworkConstraint.KEY else WifiConstraint.KEY)
|
||||
.setMaxAttempts(3)
|
||||
.setMaxInstancesForFactory(1)
|
||||
.setQueue(QUEUE)
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NotInCallConstraint;
|
|||
import org.thoughtcrime.securesms.jobmanager.impl.NotInCallConstraintObserver;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraint;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.WifiConstraint;
|
||||
import org.thoughtcrime.securesms.jobmanager.migrations.DonationReceiptRedemptionJobMigration;
|
||||
import org.thoughtcrime.securesms.jobmanager.migrations.PushDecryptMessageJobEnvelopeMigration;
|
||||
import org.thoughtcrime.securesms.jobmanager.migrations.PushProcessMessageJobMigration;
|
||||
|
@ -340,6 +341,7 @@ public final class JobManagerFactories {
|
|||
put(NetworkOrCellServiceConstraint.LEGACY_KEY, new NetworkOrCellServiceConstraint.Factory(application));
|
||||
put(NotInCallConstraint.KEY, new NotInCallConstraint.Factory());
|
||||
put(SqlCipherMigrationConstraint.KEY, new SqlCipherMigrationConstraint.Factory(application));
|
||||
put(WifiConstraint.KEY, new WifiConstraint.Factory(application));
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ internal class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
|||
private const val KEY_CDN_BACKUP_DIRECTORY = "backup.cdn.directory"
|
||||
private const val KEY_CDN_BACKUP_MEDIA_DIRECTORY = "backup.cdn.mediaDirectory"
|
||||
|
||||
private const val KEY_BACKUP_OVER_CELLULAR = "backup.useCellular"
|
||||
private const val KEY_OPTIMIZE_STORAGE = "backup.optimizeStorage"
|
||||
private const val KEY_BACKUPS_INITIALIZED = "backup.initialized"
|
||||
|
||||
|
@ -55,6 +56,7 @@ internal class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
|||
var canReadWriteToArchiveCdn: Boolean by booleanValue(KEY_CDN_CAN_READ_WRITE, false)
|
||||
var restoreState: RestoreState by enumValue(KEY_RESTORE_STATE, RestoreState.NONE, RestoreState.serializer)
|
||||
var optimizeStorage: Boolean by booleanValue(KEY_OPTIMIZE_STORAGE, false)
|
||||
var backupWithCellular: Boolean by booleanValue(KEY_BACKUP_OVER_CELLULAR, false)
|
||||
|
||||
var nextBackupTime: Long by longValue(KEY_NEXT_BACKUP_TIME, -1)
|
||||
var lastBackupTime: Long by longValue(KEY_LAST_BACKUP_TIME, -1)
|
||||
|
|
Loading…
Add table
Reference in a new issue