Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge tag 'v7.9.6' into molly-7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Jul 9, 2024
2 parents 2c60682 + 26bd59c commit 738a683
Show file tree
Hide file tree
Showing 873 changed files with 31,175 additions and 13,551 deletions.
15 changes: 13 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ root = true
indent_size = 2
ktlint_standard_trailing-comma-on-call-site = disable
ktlint_standard_trailing-comma-on-declaration-site = disable
ktlink_standard_spacing-between-declarations-with-annotations = disable
ktlint_standard_spacing-between-declarations-with-annotations = disable
ktlint_code_style = intellij_idea
ktlint_standard_class-naming = disabled
ktlint_standard_class-naming = disabled

# below rules disabled during ktlint version migration because they were preexisting but should be corrected and re-enabled ASAP
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_standard_property-naming = disabled
ktlint_standard_enum-wrapping = disabled
ktlint_standard_multiline-if-else = disabled
ktlint_standard_backing-property-naming = disabled
ktlint_standard_statement-wrapping = disabled
internal:ktlint-suppression = disabled
ktlint_standard_unnecessary-parentheses-before-trailing-lambda = disabled
ktlint_standard_value-parameter-comment = disabled
10 changes: 6 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ apply {
from("fix-profm.gradle")
}

val canonicalVersionCode = 1421
val canonicalVersionName = "7.8.1"
val canonicalVersionCode = 1428
val canonicalVersionName = "7.9.6"
val mollyRevision = 1

val postFixSize = 100
Expand Down Expand Up @@ -141,7 +141,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.4"
kotlinCompilerExtensionVersion = "1.5.4"
}

if (mollyRevision < 0 || mollyRevision >= postFixSize) {
Expand Down Expand Up @@ -495,6 +495,7 @@ dependencies {
implementation(libs.kotlinx.collections.immutable)
implementation(libs.accompanist.permissions)
implementation(libs.kotlin.stdlib.jdk8)
"gmsImplementation"(libs.kotlinx.coroutines.play.services)
implementation(libs.rxjava3.rxandroid)
implementation(libs.rxjava3.rxkotlin)
implementation(libs.rxdogtag)
Expand Down Expand Up @@ -614,7 +615,8 @@ fun Project.languageList(): List<String> {
.map { valuesFolderName -> valuesFolderName.replace("values-", "") }
.filter { valuesFolderName -> valuesFolderName != "values" }
.map { languageCode -> languageCode.replace("-r", "_") }
.distinct() + "en"
.distinct()
.sorted() + "en"
}

fun String.capitalize(): String {
Expand Down
4 changes: 4 additions & 0 deletions app/proguard/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

-keep class androidx.window.** { *; }

-keepclassmembers class * extends androidx.constraintlayout.motion.widget.Key {
public <init>();
}

# AGP generated dont warns
-dontwarn com.android.org.conscrypt.SSLParametersImpl
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.signal.core.util.logging.Log
import org.signal.libsignal.protocol.logging.SignalProtocolLoggerProvider
import org.thoughtcrime.securesms.crypto.MasterSecretUtil
import org.thoughtcrime.securesms.database.LogDatabase
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.dependencies.ApplicationDependencyProvider
import org.thoughtcrime.securesms.dependencies.InstrumentationApplicationDependencyProvider
import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger
Expand All @@ -26,8 +26,8 @@ class SignalInstrumentationApplicationContext : ApplicationContext() {

override fun initializeAppDependencies() {
val default = ApplicationDependencyProvider(this)
ApplicationDependencies.init(this, InstrumentationApplicationDependencyProvider(this, default))
ApplicationDependencies.getDeadlockDetector().start()
AppDependencies.init(this, InstrumentationApplicationDependencyProvider(this, default))
AppDependencies.deadlockDetector.start()
}

override fun initializeLogging(locked: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ import org.signal.core.util.toInt
import org.signal.core.util.withinTransaction
import org.signal.libsignal.zkgroup.profiles.ProfileKey
import org.thoughtcrime.securesms.backup.v2.database.clearAllDataForBackupRestore
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository
import org.thoughtcrime.securesms.database.CallTable
import org.thoughtcrime.securesms.database.EmojiSearchTable
import org.thoughtcrime.securesms.database.MessageTable
import org.thoughtcrime.securesms.database.MessageTypes
import org.thoughtcrime.securesms.database.RecipientTable
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.mms.QuoteModel
import org.thoughtcrime.securesms.profiles.ProfileName
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.subscription.Subscriber
import org.thoughtcrime.securesms.testing.assertIs
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.api.push.ServiceId.ACI
import org.whispersystems.signalservice.api.push.ServiceId.PNI
import org.whispersystems.signalservice.api.subscriptions.SubscriberId
import java.io.ByteArrayInputStream
import java.util.Currency
import java.util.UUID
import kotlin.random.Random

Expand Down Expand Up @@ -233,7 +236,7 @@ class BackupTest {

@Test
fun accountData() {
val context = ApplicationDependencies.getApplication()
val context = AppDependencies.application

backupTest(validateKeyValue = true) {
val self = Recipient.self()
Expand All @@ -251,8 +254,7 @@ class BackupTest {
SignalDatabase.recipients.setProfileName(self.id, ProfileName.fromParts("Peter", "Parker"))
SignalDatabase.recipients.setProfileAvatar(self.id, "https://example.com/")

SignalStore.donationsValues().markUserManuallyCancelled()
SignalStore.donationsValues().setSubscriber(Subscriber(SubscriberId.generate(), "USD"))
InAppPaymentsRepository.setSubscriber(InAppPaymentSubscriberRecord(SubscriberId.generate(), Currency.getInstance("USD"), InAppPaymentSubscriberRecord.Type.DONATION, false, InAppPaymentData.PaymentMethodType.UNKNOWN))
SignalStore.donationsValues().setDisplayBadgesOnProfile(false)

SignalStore.phoneNumberPrivacy().phoneNumberDiscoverabilityMode = PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode.NOT_DISCOVERABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

package org.thoughtcrime.securesms.backup.v2

import android.Manifest
import android.app.UiAutomation
import android.os.Environment
import android.content.Context
import androidx.test.platform.app.InstrumentationRegistry
import io.mockk.InternalPlatformDsl.toArray
import okio.ByteString.Companion.toByteString
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.signal.core.util.Base64
import org.signal.core.util.test.getObjectDiff
import org.signal.libsignal.messagebackup.MessageBackup
import org.signal.libsignal.messagebackup.MessageBackupKey
import org.signal.libsignal.zkgroup.profiles.ProfileKey
Expand Down Expand Up @@ -135,6 +133,9 @@ class ImportExportTest {
private val standardFrames = arrayOf(defaultBackupInfo, standardAccountData, selfRecipient, releaseNotes)
}

private val context: Context
get() = InstrumentationRegistry.getInstrumentation().targetContext

@JvmField
@Rule
var testName = TestName()
Expand Down Expand Up @@ -216,7 +217,7 @@ class ImportExportTest {

@Test
fun largeNumberOfMessagesAndChats() {
val NUM_INDIVIDUAL_RECIPIENTS = 1000
val numIndividualRecipients = 1000
val numIndividualMessages = 500
val numGroupMessagesPerPerson = 200

Expand All @@ -225,7 +226,7 @@ class ImportExportTest {
val recipients = ArrayList<Recipient>(1010)
val chats = ArrayList<Chat>(1010)
var id = 3L
for (i in 0 until NUM_INDIVIDUAL_RECIPIENTS) {
for (i in 0 until numIndividualRecipients) {
val recipientId = id++
recipients.add(
Recipient(
Expand Down Expand Up @@ -369,12 +370,12 @@ class ImportExportTest {
}
}
}
val import = exportFrames(

exportFrames(
*standardFrames,
*recipients.toArray(),
*chatItems.toArray()
)
outputFile(import)
}

@Test
Expand Down Expand Up @@ -565,12 +566,12 @@ class ImportExportTest {
)
)
import(importData)
val exported = export()
val exported = BackupRepository.export()
val expected = exportFrames(
*standardFrames,
alexa
)
outputFile(importData, expected)

compare(expected, exported)
}

Expand Down Expand Up @@ -994,14 +995,13 @@ class ImportExportTest {
expirationNotStarted
)
import(importData)
val exported = export()
val exported = BackupRepository.export()
val expected = exportFrames(
*standardFrames,
alice,
chat,
expirationNotStarted
)
outputFile(importData, expected)
compare(expected, exported)
}

Expand Down Expand Up @@ -1396,27 +1396,10 @@ class ImportExportTest {
return outputStream.toByteArray()
}

/**
* Exports the passed in frames as a backup and then attempts to
* import them.
*/
private fun import(vararg objects: Any) {
val importData = exportFrames(*objects)
import(importData)
}

private fun import(importData: ByteArray) {
BackupRepository.import(length = importData.size.toLong(), inputStreamFactory = { ByteArrayInputStream(importData) }, selfData = BackupRepository.SelfData(SELF_ACI, SELF_PNI, SELF_E164, SELF_PROFILE_KEY))
}

/**
* Export our current database as a backup.
*/
private fun export(): ByteArray {
val exportData = BackupRepository.export()
return exportData
}

private fun validate(importData: ByteArray): MessageBackup.ValidationResult {
val factory = { ByteArrayInputStream(importData) }
val masterKey = SignalStore.svr().getOrCreateMasterKey()
Expand All @@ -1426,10 +1409,12 @@ class ImportExportTest {
}

/**
* Imports the passed in frames and then exports them.
* Given some [Frame]s, this will do the following:
*
* It will do a comparison to assert that the import and export
* are equal.
* 1. Write the frames using an [EncryptedBackupWriter] and keep the result in memory (A).
* 2. Import those frames back into the local database.
* 3. Export the state of the local database and keep the result in memory (B).
* 4. Assert that (A) and (B) are identical. Or, in other words, assert that importing and exporting again results in the original backup data.
*/
private fun importExport(vararg objects: Any) {
val outputStream = ByteArrayOutputStream()
Expand All @@ -1454,12 +1439,13 @@ class ImportExportTest {
}
}
}
val importData = outputStream.toByteArray()
outputFile(importData)
BackupRepository.import(length = importData.size.toLong(), inputStreamFactory = { ByteArrayInputStream(importData) }, selfData = BackupRepository.SelfData(SELF_ACI, SELF_PNI, SELF_E164, SELF_PROFILE_KEY))

val export = export()
compare(importData, export)
val originalBackupData = outputStream.toByteArray()

BackupRepository.import(length = originalBackupData.size.toLong(), inputStreamFactory = { ByteArrayInputStream(originalBackupData) }, selfData = BackupRepository.SelfData(SELF_ACI, SELF_PNI, SELF_E164, SELF_PROFILE_KEY))

val generatedBackupData = BackupRepository.export()
compare(originalBackupData, generatedBackupData)
}

private fun compare(import: ByteArray, export: ByteArray) {
Expand Down Expand Up @@ -1513,11 +1499,11 @@ class ImportExportTest {
prettyAssertEquals(stickersImported, stickersExported) { it.packId }
}

private fun <T> prettyAssertEquals(import: List<T>, export: List<T>) {
private inline fun <reified T : Any> prettyAssertEquals(import: List<T>, export: List<T>) {
Assert.assertEquals(import.size, export.size)
import.zip(export).forEach { (a1, a2) ->
if (a1 != a2) {
Assert.fail("Items do not match: \n $a1 \n $a2")
Assert.fail("Items do not match:\n\n-- Pretty diff\n${getObjectDiff(a1, a2)}\n-- Full objects\n$a1\n$a2")
}
}
}
Expand All @@ -1526,7 +1512,7 @@ class ImportExportTest {
return nextFloat() < prob
}

private fun <T, R : Comparable<R>> prettyAssertEquals(import: List<T>, export: List<T>, selector: (T) -> R?) {
private inline fun <reified T : Any, R : Comparable<R>> prettyAssertEquals(import: List<T>, export: List<T>, crossinline selector: (T) -> R?) {
if (import.size != export.size) {
var msg = StringBuilder()
for (i in import) {
Expand Down Expand Up @@ -1562,9 +1548,8 @@ class ImportExportTest {
return frames
}

private fun outputFile(importBytes: ByteArray, resultBytes: ByteArray? = null) {
grantPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
val dir = File(Environment.getExternalStorageDirectory(), "backup-tests")
private fun writeToOutputFile(importBytes: ByteArray, resultBytes: ByteArray? = null) {
val dir = File(context.filesDir, "backup-tests")
if (dir.mkdirs() || dir.exists()) {
FileOutputStream(File(dir, testName.methodName + ".import")).use {
it.write(importBytes)
Expand All @@ -1579,11 +1564,4 @@ class ImportExportTest {
}
}
}

private fun grantPermissions(vararg permissions: String?) {
val auto: UiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation
for (perm in permissions) {
auto.grantRuntimePermissionAsUser(InstrumentationRegistry.getInstrumentation().targetContext.packageName, perm, android.os.Process.myUserHandle())
}
}
}
Loading

0 comments on commit 738a683

Please sign in to comment.