Add additional debug info for the backups alpha.

This commit is contained in:
Greyson Parrelli
2025-07-03 10:09:03 -04:00
committed by Alex Hart
parent 869b5aa3d5
commit dc8e93a9d3
13 changed files with 252 additions and 38 deletions

View File

@@ -171,7 +171,7 @@ private fun BackupsSettingsContent(
is BackupState.ActiveFree, is BackupState.ActivePaid, is BackupState.Canceled -> {
ActiveBackupsRow(
backupState = backupsSettingsState.backupState,
backupState = backupsSettingsState.backupState as BackupState.WithTypeAndRenewalTime,
onBackupsRowClick = onBackupsRowClick,
lastBackupAt = backupsSettingsState.lastBackupAt
)
@@ -524,7 +524,8 @@ private fun BackupsSettingsContentPreview() {
),
renewalTime = 0.seconds,
price = FiatMoney(BigDecimal.valueOf(4), Currency.getInstance("CAD"))
)
),
lastBackupAt = 0.seconds
)
)
}
@@ -536,7 +537,8 @@ private fun BackupsSettingsContentNotAvailablePreview() {
Previews.Preview {
BackupsSettingsContent(
backupsSettingsState = BackupsSettingsState(
backupState = BackupState.NotAvailable
backupState = BackupState.NotAvailable,
lastBackupAt = 0.seconds
)
)
}
@@ -550,7 +552,8 @@ private fun BackupsSettingsContentBackupTierInternalOverridePreview() {
backupsSettingsState = BackupsSettingsState(
backupState = BackupState.None,
showBackupTierInternalOverride = true,
backupTierInternalOverride = null
backupTierInternalOverride = null,
lastBackupAt = 0.seconds
)
)
}

View File

@@ -279,6 +279,10 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
requireActivity().finish()
requireActivity().startActivity(AppSettingsActivity.manageStorage(requireActivity()))
}
override fun onIncludeDebuglogClick(newState: Boolean) {
viewModel.setIncludeDebuglog(newState)
}
}
private fun displayBackupKey() {
@@ -368,6 +372,7 @@ private interface ContentCallbacks {
fun onDisplayProgressDialog() = Unit
fun onDisplayDownloadingBackupDialog() = Unit
fun onManageStorageClick() = Unit
fun onIncludeDebuglogClick(newState: Boolean) = Unit
object Empty : ContentCallbacks
}
@@ -512,6 +517,7 @@ private fun RemoteBackupsSettingsContent(
canBackUpUsingCellular = state.canBackUpUsingCellular,
canRestoreUsingCellular = state.canRestoreUsingCellular,
canBackUpNow = !state.isOutOfStorageSpace,
includeDebuglog = state.includeDebuglog,
contentCallbacks = contentCallbacks
)
} else {
@@ -815,6 +821,7 @@ private fun LazyListScope.appendBackupDetailsItems(
canBackUpUsingCellular: Boolean,
canRestoreUsingCellular: Boolean,
canBackUpNow: Boolean,
includeDebuglog: Boolean?,
contentCallbacks: ContentCallbacks
) {
item {
@@ -843,6 +850,12 @@ private fun LazyListScope.appendBackupDetailsItems(
}
}
if (includeDebuglog != null) {
item {
IncludeDebuglogRow(includeDebuglog) { contentCallbacks.onIncludeDebuglogClick(it) }
}
}
if (backupProgress == null || backupProgress.state == ArchiveUploadProgressState.State.None || backupProgress.state == ArchiveUploadProgressState.State.UserCanceled) {
item {
LastBackupRow(
@@ -1421,6 +1434,19 @@ private fun getBackupUploadPhaseProgressString(state: ArchiveUploadProgressState
return stringResource(R.string.RemoteBackupsSettingsFragment__uploading_s_of_s_d, formattedUploadedBytes, formattedTotalBytes, percent)
}
@Composable
private fun IncludeDebuglogRow(
enabled: Boolean,
onToggle: (Boolean) -> Unit
) {
Rows.ToggleRow(
checked = enabled,
text = "[INTERNAL ONLY] Include debuglog?",
label = "If enabled, we will capture a debuglog and include it in the backup file.",
onCheckChanged = onToggle
)
}
@Composable
private fun LastBackupRow(
lastBackupTimestamp: Long,
@@ -1748,6 +1774,36 @@ private fun RemoteBackupsSettingsContentPreview() {
}
}
@SignalPreview
@Composable
private fun RemoteBackupsSettingsInternalUserContentPreview() {
Previews.Preview {
RemoteBackupsSettingsContent(
state = RemoteBackupsSettingsState(
backupsEnabled = true,
lastBackupTimestamp = -1,
canBackUpUsingCellular = false,
canRestoreUsingCellular = false,
backupsFrequency = BackupFrequency.MANUAL,
dialog = RemoteBackupsSettingsState.Dialog.NONE,
snackbar = RemoteBackupsSettingsState.Snackbar.NONE,
backupMediaSize = 2300000,
backupState = BackupState.ActiveFree(
messageBackupsType = MessageBackupsType.Free(mediaRetentionDays = 30)
),
hasRedemptionError = false,
isOutOfStorageSpace = false,
includeDebuglog = true
),
statusBarColorNestedScrollConnection = null,
backupDeleteState = DeletionState.NONE,
backupRestoreState = BackupRestoreState.FromBackupStatusData(BackupStatusData.CouldNotCompleteBackup),
contentCallbacks = ContentCallbacks.Empty,
backupProgress = null
)
}
}
@SignalPreview
@Composable
private fun RedemptionErrorAlertPreview() {

View File

@@ -9,6 +9,9 @@ import org.thoughtcrime.securesms.backup.v2.BackupFrequency
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.components.settings.app.backups.BackupState
/**
* @param includeDebuglog The state for whether or not we should include a debuglog in the backup. If `null`, hide the setting.
*/
data class RemoteBackupsSettingsState(
val tier: MessageBackupTier? = null,
val backupsEnabled: Boolean,
@@ -23,7 +26,8 @@ data class RemoteBackupsSettingsState(
val backupsFrequency: BackupFrequency = BackupFrequency.DAILY,
val lastBackupTimestamp: Long = 0,
val dialog: Dialog = Dialog.NONE,
val snackbar: Snackbar = Snackbar.NONE
val snackbar: Snackbar = Snackbar.NONE,
val includeDebuglog: Boolean? = null
) {
enum class Dialog {

View File

@@ -45,6 +45,7 @@ import org.thoughtcrime.securesms.jobs.BackupMessagesJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.keyvalue.protos.ArchiveUploadProgressState
import org.thoughtcrime.securesms.service.MessageBackupListener
import org.thoughtcrime.securesms.util.RemoteConfig
import org.thoughtcrime.securesms.util.TextSecurePreferences
import kotlin.time.Duration.Companion.seconds
@@ -66,7 +67,8 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
lastBackupTimestamp = SignalStore.backup.lastBackupTime,
backupsFrequency = SignalStore.backup.backupFrequency,
canBackUpUsingCellular = SignalStore.backup.backupWithCellular,
canRestoreUsingCellular = SignalStore.backup.restoreWithCellular
canRestoreUsingCellular = SignalStore.backup.restoreWithCellular,
includeDebuglog = SignalStore.internal.includeDebuglogInBackup.takeIf { RemoteConfig.internalUser }
)
)
@@ -214,6 +216,11 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
ArchiveUploadProgress.cancel()
}
fun setIncludeDebuglog(includeDebuglog: Boolean) {
SignalStore.internal.includeDebuglogInBackup = includeDebuglog
_state.update { it.copy(includeDebuglog = includeDebuglog) }
}
private suspend fun refreshState(lastPurchase: InAppPaymentTable.InAppPayment?) {
try {
Log.i(TAG, "Performing a state refresh.")