Skip to content

Commit

Permalink
Merge tag 'v7.32.2' into molly-7.32
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Feb 3, 2025
2 parents dc5f599 + 553d783 commit 772cce4
Show file tree
Hide file tree
Showing 100 changed files with 2,269 additions and 340 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ plugins {
id("molly")
}

val canonicalVersionCode = 1508
val canonicalVersionName = "7.32.1"
val canonicalVersionCode = 1509
val canonicalVersionName = "7.32.2"
val currentHotfixVersion = 0
val maxHotfixVersions = 100
val mollyRevision = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected void onPreCreate() {
protected void onCreate(Bundle bundle, boolean ready) {
AlertDialog dialog = new MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.DeviceProvisioningActivity_link_a_signal_device))
.setMessage(getString(R.string.DeviceProvisioningActivity_it_looks_like_youre_trying_to_link_a_signal_device_using_a_3rd_party_scanner))
.setMessage(getString(R.string.DeviceProvisioningActivity_to_link_a_desktop_or_ipad_to_this_signal_account))
.setPositiveButton(R.string.DeviceProvisioningActivity_continue, (dialog1, which) -> {
startActivity(AppSettingsActivity.linkedDevices(this));
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ object ArchiveValidator {
/**
* Validates the provided [backupFile] that is encrypted with the provided [backupKey].
*/
fun validate(backupFile: File, backupKey: MessageBackupKey): ValidationResult {
fun validate(backupFile: File, backupKey: MessageBackupKey, forTransfer: Boolean): ValidationResult {
return try {
val backupId = backupKey.deriveBackupId(SignalStore.account.requireAci())
val libSignalBackupKey = LibSignalBackupKey(backupKey.value)
val backupKey = LibSignalMessageBackupKey(libSignalBackupKey, backupId.value)

MessageBackup.validate(backupKey, MessageBackup.Purpose.REMOTE_BACKUP, { backupFile.inputStream() }, backupFile.length())
MessageBackup.validate(
backupKey,
if (forTransfer) MessageBackup.Purpose.DEVICE_TRANSFER else MessageBackup.Purpose.REMOTE_BACKUP,
{ backupFile.inputStream() },
backupFile.length()
)

ValidationResult.Success
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ object BackupRepository {
plaintext: Boolean = false,
currentTime: Long = System.currentTimeMillis(),
mediaBackupEnabled: Boolean = SignalStore.backup.backsUpMedia,
forTransfer: Boolean = false,
progressEmitter: ExportProgressListener? = null,
cancellationSignal: () -> Boolean = { false },
exportExtras: ((SignalDatabase) -> Unit)? = null
Expand All @@ -481,6 +482,7 @@ object BackupRepository {
writer = writer,
progressEmitter = progressEmitter,
mediaBackupEnabled = mediaBackupEnabled,
forTransfer = forTransfer,
cancellationSignal = cancellationSignal,
exportExtras = exportExtras
)
Expand All @@ -500,6 +502,7 @@ object BackupRepository {
isLocal: Boolean,
writer: BackupExportWriter,
mediaBackupEnabled: Boolean = SignalStore.backup.backsUpMedia,
forTransfer: Boolean = false,
progressEmitter: ExportProgressListener? = null,
cancellationSignal: () -> Boolean = { false },
exportExtras: ((SignalDatabase) -> Unit)? = null
Expand All @@ -515,7 +518,7 @@ object BackupRepository {
val signalStoreSnapshot: SignalStore = createSignalStoreSnapshot(keyValueDbName)
eventTimer.emit("store-db-snapshot")

val exportState = ExportState(backupTime = currentTime, mediaBackupEnabled = mediaBackupEnabled)
val exportState = ExportState(backupTime = currentTime, mediaBackupEnabled = mediaBackupEnabled, forTransfer = forTransfer)
val selfAci = signalStoreSnapshot.accountValues.aci!!
val selfRecipientId = dbSnapshot.recipientTable.getByAci(selfAci).get().toLong().let { RecipientId.from(it) }

Expand Down Expand Up @@ -1521,7 +1524,11 @@ data class ResumableMessagesBackupUploadSpec(

data class ArchivedMediaObject(val mediaId: String, val cdn: Int)

class ExportState(val backupTime: Long, val mediaBackupEnabled: Boolean) {
class ExportState(
val backupTime: Long,
val mediaBackupEnabled: Boolean,
val forTransfer: Boolean
) {
val recipientIds: MutableSet<Long> = hashSetOf()
val threadIds: MutableSet<Long> = hashSetOf()
val contactRecipientIds: MutableSet<Long> = hashSetOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,14 @@ private fun BackupMessageRecord.toBasicChatItemBuilder(selfRecipientId: Recipien
}
}

if (!MessageTypes.isExpirationTimerUpdate(record.type) && builder.expiresInMs != null && builder.expireStartDate != null && builder.expireStartDate!! + builder.expiresInMs!! < backupStartTime + 1.days.inWholeMilliseconds) {
Log.w(TAG, ExportSkips.messageExpiresTooSoon(record.dateSent))
return null
if (!MessageTypes.isExpirationTimerUpdate(record.type) && builder.expiresInMs != null && builder.expireStartDate != null) {
val expiresAt = builder.expireStartDate!! + builder.expiresInMs!!
val threshold = if (exportState.forTransfer) backupStartTime else backupStartTime + 1.days.inWholeMilliseconds

if (expiresAt < threshold) {
Log.w(TAG, ExportSkips.messageExpiresTooSoon(record.dateSent))
return null
}
}

if (builder.expireStartDate != null && builder.expiresInMs == null) {
Expand Down Expand Up @@ -1428,10 +1433,6 @@ private fun Cursor.toBackupMessageRecord(pastIds: Set<Long>, backupStartTime: Lo
val expiresIn = this.requireLong(MessageTable.EXPIRES_IN)
val expireStarted = this.requireLong(MessageTable.EXPIRE_STARTED)

if (expireStarted != 0L && expireStarted + expiresIn < backupStartTime + 1.days.inWholeMilliseconds) {
return null
}

return BackupMessageRecord(
id = id,
dateSent = this.requireLong(MessageTable.DATE_SENT).clampToValidBackupRange(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class InternalBackupPlaygroundViewModel : ViewModel() {
append = { bytes -> tempFile.appendBytes(bytes) }
)
_state.value = _state.value.copy(statusMessage = "Export complete! Validating...")
ArchiveValidator.validate(tempFile, SignalStore.backup.messageBackupKey)
ArchiveValidator.validate(tempFile, SignalStore.backup.messageBackupKey, forTransfer = false)
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class BackupMessagesJob private constructor(

stopwatch.split("export")

when (val result = ArchiveValidator.validate(tempBackupFile, backupKey)) {
when (val result = ArchiveValidator.validate(tempBackupFile, backupKey, forTransfer = false)) {
ArchiveValidator.ValidationResult.Success -> {
Log.d(TAG, "Successfully passed validation.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ object LinkDeviceRepository {
append = { tempBackupFile.appendBytes(it) },
messageBackupKey = ephemeralMessageBackupKey,
mediaBackupEnabled = false,
forTransfer = true,
cancellationSignal = cancellationSignal
)
} catch (e: Exception) {
Expand All @@ -268,7 +269,7 @@ object LinkDeviceRepository {
return LinkUploadArchiveResult.BackupCreationCancelled
}

when (val result = ArchiveValidator.validate(tempBackupFile, ephemeralMessageBackupKey)) {
when (val result = ArchiveValidator.validate(tempBackupFile, ephemeralMessageBackupKey, forTransfer = true)) {
ArchiveValidator.ValidationResult.Success -> {
Log.d(TAG, "[createAndUploadArchive] Successfully passed validation.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MediaCaptureFragment : Fragment(R.layout.fragment_container), CameraFragme
is MediaCaptureEvent.DeviceLinkScannedFromQrCode -> {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.MediaCaptureFragment_device_link_dialog_title)
.setMessage(R.string.MediaCaptureFragment_device_link_dialog_body)
.setMessage(R.string.MediaCaptureFragment_it_looks_like_youre_trying)
.setPositiveButton(R.string.MediaCaptureFragment_device_link_dialog_continue) { d, _ ->
startActivity(AppSettingsActivity.linkedDevices(requireContext()))
requireActivity().finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.registration.data.network.Challenge
import org.thoughtcrime.securesms.registration.data.network.RegisterAccountResult
import org.thoughtcrime.securesms.registration.data.network.RegistrationSessionResult
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult
import org.thoughtcrime.securesms.registration.ui.countrycode.Country
import org.whispersystems.signalservice.api.svr.Svr3Credentials
import org.whispersystems.signalservice.internal.push.AuthCredentials
import kotlin.time.Duration
Expand Down Expand Up @@ -54,7 +55,8 @@ data class RegistrationState(
val networkError: Throwable? = null,
val sessionCreationError: RegistrationSessionResult? = null,
val sessionStateError: VerificationCodeRequestResult? = null,
val registerAccountError: RegisterAccountResult? = null
val registerAccountError: RegisterAccountResult? = null,
val country: Country? = null
) {
val challengesRemaining: List<Challenge> = challengesRequested.filterNot { it in challengesPresented }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequ
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult.Success
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult.TokenNotAccepted
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult.UnknownError
import org.thoughtcrime.securesms.registration.ui.countrycode.Country
import org.thoughtcrime.securesms.registration.util.RegistrationUtil
import org.thoughtcrime.securesms.registration.viewmodel.SvrAuthCredentialSet
import org.thoughtcrime.securesms.util.RemoteConfig
Expand Down Expand Up @@ -199,6 +200,18 @@ class RegistrationViewModel : ViewModel() {
}
}

fun setCurrentCountryPicked(country: Country) {
store.update {
it.copy(country = country)
}
}

fun clearCountry() {
store.update {
it.copy(country = null)
}
}

fun fetchFcmToken(context: Context) {
viewModelScope.launch(context = coroutineExceptionHandler) {
val fcmToken = RegistrationRepository.getFcmToken(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.registration.ui.countrycode

/**
* Data class string describing useful characteristics of countries when selecting one. Used in the [CountryCodeState]
*/
data class Country(val emoji: String, val name: String, val countryCode: String)
Loading

0 comments on commit 772cce4

Please sign in to comment.