mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Update local backup v2 support.
This commit is contained in:
committed by
jeffrey-signal
parent
71b15d269e
commit
d9ecab5240
@@ -99,6 +99,10 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
||||
private const val KEY_MESSAGE_CUTOFF_DURATION = "backup.message_cutoff_duration"
|
||||
private const val KEY_LAST_USED_MESSAGE_CUTOFF_TIME = "backup.last_used_message_cutoff_time"
|
||||
|
||||
private const val KEY_NEW_LOCAL_BACKUPS_ENABLED = "backup.new_local_backups_enabled"
|
||||
private const val KEY_NEW_LOCAL_BACKUPS_DIRECTORY = "backup.new_local_backups_directory"
|
||||
private const val KEY_NEW_LOCAL_BACKUPS_LAST_BACKUP_TIME = "backup.new_local_backups_last_backup_time"
|
||||
|
||||
private val cachedCdnCredentialsExpiresIn: Duration = 12.hours
|
||||
|
||||
private val lock = ReentrantLock()
|
||||
@@ -441,6 +445,27 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
||||
*/
|
||||
var lastUsedMessageCutoffTime: Long by longValue(KEY_LAST_USED_MESSAGE_CUTOFF_TIME, 0)
|
||||
|
||||
/**
|
||||
* True if the new local backup system is enabled, otherwise false.
|
||||
*/
|
||||
private val newLocalBackupsEnabledValue = booleanValue(KEY_NEW_LOCAL_BACKUPS_ENABLED, false)
|
||||
var newLocalBackupsEnabled: Boolean by newLocalBackupsEnabledValue
|
||||
val newLocalBackupsEnabledFlow: Flow<Boolean> by lazy { newLocalBackupsEnabledValue.toFlow() }
|
||||
|
||||
/**
|
||||
* The directory URI path selected for new local backups.
|
||||
*/
|
||||
private val newLocalBackupsDirectoryValue = stringValue(KEY_NEW_LOCAL_BACKUPS_DIRECTORY, null as String?)
|
||||
var newLocalBackupsDirectory: String? by newLocalBackupsDirectoryValue
|
||||
val newLocalBackupsDirectoryFlow: Flow<String?> by lazy { newLocalBackupsDirectoryValue.toFlow() }
|
||||
|
||||
/**
|
||||
* The timestamp of the last successful new local backup.
|
||||
*/
|
||||
private val newLocalBackupsLastBackupTimeValue = longValue(KEY_NEW_LOCAL_BACKUPS_LAST_BACKUP_TIME, -1)
|
||||
var newLocalBackupsLastBackupTime: Long by newLocalBackupsLastBackupTimeValue
|
||||
val newLocalBackupsLastBackupTimeFlow: Flow<Long> by lazy { newLocalBackupsLastBackupTimeValue.toFlow() }
|
||||
|
||||
/**
|
||||
* When we are told by the server that we are out of storage space, we should show
|
||||
* UX treatment to make the user aware of this.
|
||||
|
||||
@@ -32,6 +32,15 @@ val RestoreDecisionState.isWantingManualRemoteRestore: Boolean
|
||||
else -> false
|
||||
}
|
||||
|
||||
/** Has the user indicated they want a manual local v2 restore but not via quick restore. */
|
||||
val RestoreDecisionState.isWantingNewLocalBackupRestore: Boolean
|
||||
get() = when (this.decisionState) {
|
||||
RestoreDecisionState.State.INTEND_TO_RESTORE -> {
|
||||
this.intendToRestoreData?.fromLocalV2 == true && !this.intendToRestoreData.hasOldDevice
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
val RestoreDecisionState.includeDeviceToDeviceTransfer: Boolean
|
||||
get() = when (this.decisionState) {
|
||||
RestoreDecisionState.State.INTEND_TO_RESTORE -> {
|
||||
@@ -49,10 +58,10 @@ val RestoreDecisionState.Companion.Start: RestoreDecisionState
|
||||
get() = RestoreDecisionState(RestoreDecisionState.State.START)
|
||||
|
||||
/** Helper to create a [RestoreDecisionState.State.INTEND_TO_RESTORE] with appropriate data. */
|
||||
fun RestoreDecisionState.Companion.intendToRestore(hasOldDevice: Boolean, fromRemote: Boolean?): RestoreDecisionState {
|
||||
fun RestoreDecisionState.Companion.intendToRestore(hasOldDevice: Boolean, fromRemote: Boolean?, fromLocalV2: Boolean? = null): RestoreDecisionState {
|
||||
return RestoreDecisionState(
|
||||
decisionState = RestoreDecisionState.State.INTEND_TO_RESTORE,
|
||||
intendToRestoreData = RestoreDecisionState.IntendToRestoreData(hasOldDevice = hasOldDevice, fromRemote = fromRemote)
|
||||
intendToRestoreData = RestoreDecisionState.IntendToRestoreData(hasOldDevice = hasOldDevice, fromRemote = fromRemote, fromLocalV2 = fromLocalV2)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user