diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupMessagesJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupMessagesJob.kt index 552e05e206..d3d8ecb899 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupMessagesJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupMessagesJob.kt @@ -71,22 +71,22 @@ class BackupMessagesJob private constructor( private fun isBackupAllowed(): Boolean { return when { !RemoteConfig.messageBackups -> { - Log.i(TAG, "Remote config for backups is disabled.") + Log.i(TAG, "Remote config for backups is disabled.", true) false } SignalStore.registration.restoreDecisionState.isDecisionPending -> { - Log.i(TAG, "Backup not allowed: a restore decision is pending.") + Log.i(TAG, "Backup not allowed: a restore decision is pending.", true) false } ArchiveRestoreProgress.state.activelyRestoring() -> { - Log.i(TAG, "Backup not allowed: a restore is in progress.") + Log.i(TAG, "Backup not allowed: a restore is in progress.", true) false } SignalStore.account.isLinkedDevice -> { - Log.i(TAG, "Backup not allowed: linked device.") + Log.i(TAG, "Backup not allowed: linked device.", true) false } @@ -96,7 +96,7 @@ class BackupMessagesJob private constructor( fun enqueue() { if (!isBackupAllowed()) { - Log.d(TAG, "Skip enqueueing BackupMessagesJob.") + Log.d(TAG, "Skip enqueueing BackupMessagesJob.", true) return } @@ -142,14 +142,14 @@ class BackupMessagesJob private constructor( override fun onFailure() { if (!isCanceled) { - Log.w(TAG, "Failed to backup user messages. Marking failure state.") + Log.w(TAG, "Failed to backup user messages. Marking failure state.", true) BackupRepository.markBackupFailure() } } override fun run(): Result { if (!isBackupAllowed()) { - Log.d(TAG, "Skip running BackupMessagesJob.") + Log.d(TAG, "Skip running BackupMessagesJob.", true) return Result.success() } @@ -157,13 +157,13 @@ class BackupMessagesJob private constructor( val auth = when (val result = BackupRepository.getSvrBAuth()) { is NetworkResult.Success -> result.result - is NetworkResult.NetworkError -> return Result.retry(defaultBackoff()).logW(TAG, "Network error when getting SVRB auth.", result.getCause()) - is NetworkResult.StatusCodeError -> return Result.retry(defaultBackoff()).logW(TAG, "Status code error when getting SVRB auth.", result.getCause()) + is NetworkResult.NetworkError -> return Result.retry(defaultBackoff()).logW(TAG, "Network error when getting SVRB auth.", result.getCause(), true) + is NetworkResult.StatusCodeError -> return Result.retry(defaultBackoff()).logW(TAG, "Status code error when getting SVRB auth.", result.getCause(), true) is NetworkResult.ApplicationError -> throw result.throwable } val backupSecretData = SignalStore.backup.nextBackupSecretData ?: run { - Log.i(TAG, "First SVRB backup! Creating new backup chain.") + Log.i(TAG, "First SVRB backup! Creating new backup chain.", true) val secretData = SignalNetwork.svrB.createNewBackupChain(auth, SignalStore.backup.messageBackupKey) SignalStore.backup.nextBackupSecretData = secretData secretData @@ -171,29 +171,29 @@ class BackupMessagesJob private constructor( val svrBMetadata: SvrBStoreResponse = when (val result = SignalNetwork.svrB.store(auth, SignalStore.backup.messageBackupKey, backupSecretData)) { is SvrBApi.StoreResult.Success -> result.data - is SvrBApi.StoreResult.NetworkError -> return Result.retry(result.retryAfter?.inWholeMilliseconds ?: defaultBackoff()).logW(TAG, "SVRB transient network error.", result.exception) - is SvrBApi.StoreResult.SvrError -> return Result.retry(defaultBackoff()).logW(TAG, "SVRB error.", result.throwable) + is SvrBApi.StoreResult.NetworkError -> return Result.retry(result.retryAfter?.inWholeMilliseconds ?: defaultBackoff()).logW(TAG, "SVRB transient network error.", result.exception, true) + is SvrBApi.StoreResult.SvrError -> return Result.retry(defaultBackoff()).logW(TAG, "SVRB error.", result.throwable, true) SvrBApi.StoreResult.InvalidDataError -> { - Log.w(TAG, "Invalid SVRB data on the server! Clearing backup secret data and retrying.") + Log.w(TAG, "Invalid SVRB data on the server! Clearing backup secret data and retrying.", true) SignalStore.backup.nextBackupSecretData = null return Result.retry(defaultBackoff()) } is SvrBApi.StoreResult.UnknownError -> return Result.fatalFailure(RuntimeException(result.throwable)) } - Log.i(TAG, "Successfully stored data on SVRB.") + Log.i(TAG, "Successfully stored data on SVRB.", true) stopwatch.split("svrb") val createKeyResult = SignalDatabase.attachments.createRemoteKeyForAttachmentsThatNeedArchiveUpload() if (createKeyResult.totalCount > 0) { - Log.w(TAG, "Needed to create remote keys. $createKeyResult") + Log.w(TAG, "Needed to create remote keys. $createKeyResult", true) if (createKeyResult.unexpectedKeyCreation) { maybePostRemoteKeyMissingNotification() } } stopwatch.split("keygen") - SignalDatabase.attachments.clearIncrementalMacsForAttachmentsThatNeedArchiveUpload().takeIf { it > 0 }?.let { count -> Log.w(TAG, "Needed to clear $count incrementalMacs.") } + SignalDatabase.attachments.clearIncrementalMacsForAttachmentsThatNeedArchiveUpload().takeIf { it > 0 }?.let { count -> Log.w(TAG, "Needed to clear $count incrementalMacs.", true) } stopwatch.split("clear-incmac") if (isCanceled) { @@ -214,7 +214,7 @@ class BackupMessagesJob private constructor( val backupSpec: ResumableMessagesBackupUploadSpec = resumableMessagesBackupUploadSpec ?: when (val result = BackupRepository.getResumableMessagesBackupUploadSpec(tempBackupFile.length())) { is NetworkResult.Success -> { - Log.i(TAG, "Successfully generated a new upload spec.") + Log.i(TAG, "Successfully generated a new upload spec.", true) val spec = result.result resumableMessagesBackupUploadSpec = spec @@ -222,18 +222,18 @@ class BackupMessagesJob private constructor( } is NetworkResult.NetworkError -> { - Log.i(TAG, "Network failure", result.getCause()) + Log.i(TAG, "Network failure", result.getCause(), true) return Result.retry(defaultBackoff()) } is NetworkResult.StatusCodeError -> { when (result.code) { 413 -> { - Log.i(TAG, "Backup file is too large! Size: ${tempBackupFile.length()} bytes", result.getCause()) + Log.i(TAG, "Backup file is too large! Size: ${tempBackupFile.length()} bytes", result.getCause(), true) // TODO [backup] Need to show the user an error } else -> { - Log.i(TAG, "Status code failure", result.getCause()) + Log.i(TAG, "Status code failure", result.getCause(), true) } } return Result.retry(defaultBackoff()) @@ -261,9 +261,9 @@ class BackupMessagesJob private constructor( when (uploadResult) { is NetworkResult.Success -> { - Log.i(TAG, "Successfully uploaded backup file.") + Log.i(TAG, "Successfully uploaded backup file.", true) if (!SignalStore.backup.hasBackupBeenUploaded) { - Log.i(TAG, "First time making a backup - scheduling a storage sync.") + Log.i(TAG, "First time making a backup - scheduling a storage sync.", true) SignalDatabase.recipients.markNeedsSync(Recipient.self().id) StorageSyncHelper.scheduleSyncForDataChange() } @@ -271,7 +271,7 @@ class BackupMessagesJob private constructor( } is NetworkResult.NetworkError -> { - Log.i(TAG, "Network failure", uploadResult.getCause()) + Log.i(TAG, "Network failure", uploadResult.getCause(), true) return if (isCanceled) { Result.failure() } else { @@ -280,10 +280,10 @@ class BackupMessagesJob private constructor( } is NetworkResult.StatusCodeError -> { - Log.i(TAG, "Status code failure", uploadResult.getCause()) + Log.i(TAG, "Status code failure", uploadResult.getCause(), true) when (uploadResult.code) { 400 -> { - Log.w(TAG, "400 likely means bad resumable state. Resetting the upload spec before retrying.") + Log.w(TAG, "400 likely means bad resumable state. Resetting the upload spec before retrying.", true) resumableMessagesBackupUploadSpec = null } } @@ -299,7 +299,7 @@ class BackupMessagesJob private constructor( SignalStore.backup.lastBackupProtoSize = tempBackupFile.length() if (!tempBackupFile.delete()) { - Log.e(TAG, "Failed to delete temp backup file") + Log.e(TAG, "Failed to delete temp backup file", true) } SignalStore.backup.lastBackupTime = System.currentTimeMillis() @@ -311,18 +311,18 @@ class BackupMessagesJob private constructor( } if (SignalStore.backup.backsUpMedia && SignalDatabase.attachments.doAnyAttachmentsNeedArchiveUpload()) { - Log.i(TAG, "Enqueuing attachment backfill job.") + Log.i(TAG, "Enqueuing attachment backfill job.", true) AppDependencies.jobManager.add(ArchiveAttachmentBackfillJob()) } else { - Log.i(TAG, "No attachments need to be uploaded, we can finish. Tier: ${SignalStore.backup.backupTier}") + Log.i(TAG, "No attachments need to be uploaded, we can finish. Tier: ${SignalStore.backup.backupTier}", true) ArchiveUploadProgress.onMessageBackupFinishedEarly() } if (SignalStore.backup.backsUpMedia && SignalDatabase.attachments.doAnyThumbnailsNeedArchiveUpload()) { - Log.i(TAG, "Enqueuing thumbnail backfill job.") + Log.i(TAG, "Enqueuing thumbnail backfill job.", true) AppDependencies.jobManager.add(ArchiveThumbnailBackfillJob()) } else { - Log.i(TAG, "No thumbnails need to be uploaded: ${SignalStore.backup.backupTier}") + Log.i(TAG, "No thumbnails need to be uploaded: ${SignalStore.backup.backupTier}", true) } BackupRepository.clearBackupFailure() @@ -346,7 +346,7 @@ class BackupMessagesJob private constructor( val elapsed = (System.currentTimeMillis() - syncTime).milliseconds if (file.exists() && file.canRead() && elapsed < FILE_REUSE_TIMEOUT) { - Log.d(TAG, "File exists and is new enough to utilize.") + Log.d(TAG, "File exists and is new enough to utilize.", true) return BackupFileResult.Success(file, syncTime) } } @@ -380,22 +380,22 @@ class BackupMessagesJob private constructor( when (val result = ArchiveValidator.validateSignalBackup(tempBackupFile, backupKey, forwardSecrecyToken)) { ArchiveValidator.ValidationResult.Success -> { - Log.d(TAG, "Successfully passed validation.") + Log.d(TAG, "Successfully passed validation.", true) } is ArchiveValidator.ValidationResult.ReadError -> { - Log.w(TAG, "Failed to read the file during validation!", result.exception) + Log.w(TAG, "Failed to read the file during validation!", result.exception, true) return BackupFileResult.Retry } is ArchiveValidator.ValidationResult.MessageValidationError -> { - Log.w(TAG, "The backup file fails validation! Message: ${result.exception.message}, Details: ${result.messageDetails}") + Log.w(TAG, "The backup file fails validation! Message: ${result.exception.message}, Details: ${result.messageDetails}", true) ArchiveUploadProgress.onValidationFailure() return BackupFileResult.Failure } is ArchiveValidator.ValidationResult.RecipientDuplicateE164Error -> { - Log.w(TAG, "The backup file fails validation with a duplicate recipient! Message: ${result.exception.message}, Details: ${result.details}") + Log.w(TAG, "The backup file fails validation with a duplicate recipient! Message: ${result.exception.message}, Details: ${result.details}", true) ArchiveUploadProgress.onValidationFailure() return BackupFileResult.Failure } diff --git a/core-util-jvm/src/main/java/org/signal/core/util/logging/LoggingExtensions.kt b/core-util-jvm/src/main/java/org/signal/core/util/logging/LoggingExtensions.kt index 4c1550205f..bc398650d8 100644 --- a/core-util-jvm/src/main/java/org/signal/core/util/logging/LoggingExtensions.kt +++ b/core-util-jvm/src/main/java/org/signal/core/util/logging/LoggingExtensions.kt @@ -32,8 +32,8 @@ fun T.logI(tag: String, message: String, throwable: Throwable? = null): T { /** * Convenience method to replace `.also { Log.w(TAG, "message") }` */ -fun T.logW(tag: String, message: String, throwable: Throwable? = null): T { - Log.w(tag, message, throwable) +fun T.logW(tag: String, message: String, throwable: Throwable? = null, keepLonger: Boolean = false): T { + Log.w(tag, message, throwable, keepLonger) return this }