Skip to content
Snippets Groups Projects
Commit 25e4fa92 authored by Benoit Marty's avatar Benoit Marty
Browse files

Merge branch 'release/1.1.13' into main

parents c61bdecf e29ebdb7
No related branches found
No related tags found
No related merge requests found
Showing
with 557 additions and 90 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
......@@ -2,7 +2,7 @@
buildscript {
// Ref: https://kotlinlang.org/releases.html
ext.kotlin_version = '1.5.10'
ext.kotlin_version = '1.5.21'
ext.kotlin_coroutines_version = "1.5.0"
repositories {
google()
......@@ -12,7 +12,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
......@@ -38,7 +38,8 @@ allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
// Warnings are potential errors, so stop ignoring them
kotlinOptions.allWarningsAsErrors = true
// Ignore on the SDK for the moment
kotlinOptions.allWarningsAsErrors = false
}
}
......
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=13bf8d3cf8eeeb5770d19741a59bde9bd966dd78d17f1bbad787a05ef19d1c2d
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionSha256Sum=9bb8bc05f562f2d42bdf1ba8db62f6b6fa1c3bf6c392228802cc7cb0578fe7e0
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -10,7 +10,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:10.5.0"
classpath "io.realm:realm-gradle-plugin:10.6.1"
}
}
......@@ -22,7 +22,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.1.9"
versionName "1.2.0"
// Multidex is useful for tests
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
......@@ -73,12 +73,12 @@ android {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}
sourceSets {
......@@ -113,7 +113,7 @@ dependencies {
def lifecycle_version = '2.2.0'
def arch_version = '2.1.0'
def markwon_version = '3.1.0'
def daggerVersion = '2.36'
def daggerVersion = '2.38'
def work_version = '2.5.0'
def retrofit_version = '2.9.0'
......@@ -121,8 +121,8 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "androidx.core:core-ktx:1.5.0"
implementation "androidx.appcompat:appcompat:1.3.1"
implementation "androidx.core:core-ktx:1.6.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
......@@ -163,39 +163,39 @@ dependencies {
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
// Logging
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
// Video compression
implementation 'com.otaliastudios:transcoder:0.10.3'
// Phone number https://github.com/google/libphonenumber
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.24'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.28'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.5.1'
//testImplementation 'org.robolectric:shadows-support-v4:3.0'
// Note: version sticks to 1.9.2 due to https://github.com/mockk/mockk/issues/281
testImplementation 'io.mockk:mockk:1.11.0'
testImplementation 'org.amshove.kluent:kluent-android:1.65'
testImplementation 'io.mockk:mockk:1.12.0'
testImplementation 'org.amshove.kluent:kluent-android:1.68'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
// Plant Timber tree for test
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'org.amshove.kluent:kluent-android:1.65'
androidTestImplementation 'io.mockk:mockk-android:1.11.0'
androidTestImplementation 'androidx.test:core:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'org.amshove.kluent:kluent-android:1.68'
androidTestImplementation 'io.mockk:mockk-android:1.12.0'
androidTestImplementation "androidx.arch.core:core-testing:$arch_version"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
// Plant Timber tree for test
androidTestImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
androidTestUtil 'androidx.test:orchestrator:1.3.0'
androidTestUtil 'androidx.test:orchestrator:1.4.0'
}
project.afterEvaluate {
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.matrix.android.sdk">
<application>
<!--
This is mandatory to run integration tests
-->
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
</application>
</manifest>
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk
import org.amshove.kluent.internal.assertEquals
import org.junit.Assert
import org.junit.Test
import org.matrix.android.sdk.api.session.space.SpaceOrderUtils
class SpaceOrderTest {
@Test
fun testOrderBetweenNodesWithOrder() {
val orderedSpaces = listOf(
"roomId1" to "a",
"roomId2" to "m",
"roomId3" to "z"
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId1", 1)
Assert.assertTrue("Only one order should be changed", orderCommand.size == 1)
Assert.assertTrue("Moved space order should change", orderCommand.first().spaceId == "roomId1")
Assert.assertTrue("m" < orderCommand[0].order)
Assert.assertTrue(orderCommand[0].order < "z")
}
@Test
fun testMoveLastBetweenNodesWithOrder() {
val orderedSpaces = listOf(
"roomId1" to "a",
"roomId2" to "m",
"roomId3" to "z"
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId1", 2)
Assert.assertTrue("Only one order should be changed", orderCommand.size == 1)
Assert.assertTrue("Moved space order should change", orderCommand.first().spaceId == "roomId1")
Assert.assertTrue("z" < orderCommand[0].order)
}
@Test
fun testMoveUpNoOrder() {
val orderedSpaces = listOf(
"roomId1" to null,
"roomId2" to null,
"roomId3" to null
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId1", 1)
Assert.assertTrue("2 orders change should be needed", orderCommand.size == 2)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId2", reOrdered[0].first)
Assert.assertEquals("roomId1", reOrdered[1].first)
Assert.assertEquals("roomId3", reOrdered[2].first)
}
@Test
fun testMoveUpNotEnoughSpace() {
val orderedSpaces = listOf(
"roomId1" to "a",
"roomId2" to "j",
"roomId3" to "k"
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId1", 1)
Assert.assertTrue("more orders change should be needed", orderCommand.size > 1)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId2", reOrdered[0].first)
Assert.assertEquals("roomId1", reOrdered[1].first)
Assert.assertEquals("roomId3", reOrdered[2].first)
}
@Test
fun testMoveEndNoOrder() {
val orderedSpaces = listOf(
"roomId1" to null,
"roomId2" to null,
"roomId3" to null
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId1", 2)
// Actually 2 could be enough... as it's last it can stays with null
Assert.assertEquals("3 orders change should be needed", 3, orderCommand.size)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId2", reOrdered[0].first)
Assert.assertEquals("roomId3", reOrdered[1].first)
Assert.assertEquals("roomId1", reOrdered[2].first)
}
@Test
fun testMoveUpBiggerOrder() {
val orderedSpaces = listOf(
"roomId1" to "aaaa",
"roomId2" to "ffff",
"roomId3" to "pppp",
"roomId4" to null,
"roomId5" to null,
"roomId6" to null
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId2", 3)
// Actually 2 could be enough... as it's last it can stays with null
Assert.assertEquals("3 orders change should be needed", 3, orderCommand.size)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId1", reOrdered[0].first)
Assert.assertEquals("roomId3", reOrdered[1].first)
Assert.assertEquals("roomId4", reOrdered[2].first)
Assert.assertEquals("roomId5", reOrdered[3].first)
Assert.assertEquals("roomId2", reOrdered[4].first)
Assert.assertEquals("roomId6", reOrdered[5].first)
}
@Test
fun testMoveDownBetweenNodesWithOrder() {
val orderedSpaces = listOf(
"roomId1" to "a",
"roomId2" to "m",
"roomId3" to "z"
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId3", -1)
Assert.assertTrue("Only one order should be changed", orderCommand.size == 1)
Assert.assertTrue("Moved space order should change", orderCommand.first().spaceId == "roomId3")
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId1", reOrdered[0].first)
Assert.assertEquals("roomId3", reOrdered[1].first)
Assert.assertEquals("roomId2", reOrdered[2].first)
}
@Test
fun testMoveDownNoOrder() {
val orderedSpaces = listOf(
"roomId1" to null,
"roomId2" to null,
"roomId3" to null
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId3", -1)
Assert.assertTrue("2 orders change should be needed", orderCommand.size == 2)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId1", reOrdered[0].first)
Assert.assertEquals("roomId3", reOrdered[1].first)
Assert.assertEquals("roomId2", reOrdered[2].first)
}
@Test
fun testMoveDownBiggerOrder() {
val orderedSpaces = listOf(
"roomId1" to "aaaa",
"roomId2" to "ffff",
"roomId3" to "pppp",
"roomId4" to null,
"roomId5" to null,
"roomId6" to null
).assertSpaceOrdered()
val orderCommand = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId5", -4)
Assert.assertEquals("1 order change should be needed", 1, orderCommand.size)
val reOrdered = reOrderWithCommands(orderedSpaces, orderCommand)
Assert.assertEquals("roomId5", reOrdered[0].first)
Assert.assertEquals("roomId1", reOrdered[1].first)
Assert.assertEquals("roomId2", reOrdered[2].first)
Assert.assertEquals("roomId3", reOrdered[3].first)
Assert.assertEquals("roomId4", reOrdered[4].first)
Assert.assertEquals("roomId6", reOrdered[5].first)
}
@Test
fun testMultipleMoveOrder() {
val orderedSpaces = listOf(
"roomId1" to null,
"roomId2" to null,
"roomId3" to null,
"roomId4" to null,
"roomId5" to null,
"roomId6" to null
).assertSpaceOrdered()
// move 5 to Top
val fiveToTop = SpaceOrderUtils.orderCommandsForMove(orderedSpaces, "roomId5", -4)
val fiveTopReOrder = reOrderWithCommands(orderedSpaces, fiveToTop)
// now move 4 to second
val orderCommand = SpaceOrderUtils.orderCommandsForMove(fiveTopReOrder, "roomId4", -3)
val reOrdered = reOrderWithCommands(fiveTopReOrder, orderCommand)
// second order should cost 1 re-order
Assert.assertEquals(1, orderCommand.size)
Assert.assertEquals("roomId5", reOrdered[0].first)
Assert.assertEquals("roomId4", reOrdered[1].first)
Assert.assertEquals("roomId1", reOrdered[2].first)
Assert.assertEquals("roomId2", reOrdered[3].first)
Assert.assertEquals("roomId3", reOrdered[4].first)
Assert.assertEquals("roomId6", reOrdered[5].first)
}
@Test
fun testComparator() {
listOf(
"roomId2" to "a",
"roomId1" to "b",
"roomId3" to null,
"roomId4" to null
).assertSpaceOrdered()
}
private fun reOrderWithCommands(orderedSpaces: List<Pair<String, String?>>, orderCommand: List<SpaceOrderUtils.SpaceReOrderCommand>) =
orderedSpaces.map { orderInfo ->
orderInfo.first to (orderCommand.find { it.spaceId == orderInfo.first }?.order ?: orderInfo.second)
}
.sortedWith(testSpaceComparator)
private fun List<Pair<String, String?>>.assertSpaceOrdered(): List<Pair<String, String?>> {
assertEquals(this, this.sortedWith(testSpaceComparator))
return this
}
private val testSpaceComparator = compareBy<Pair<String, String?>, String?>(nullsLast()) { it.second }.thenBy { it.first }
}
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk
import org.amshove.kluent.internal.assertEquals
import org.junit.Assert
import org.junit.Test
import org.matrix.android.sdk.api.MatrixPatterns
import org.matrix.android.sdk.api.util.StringOrderUtils
class StringOrderTest {
@Test
fun testbasing() {
assertEquals("a", StringOrderUtils.baseToString(StringOrderUtils.stringToBase("a", StringOrderUtils.DEFAULT_ALPHABET), StringOrderUtils.DEFAULT_ALPHABET))
assertEquals("element", StringOrderUtils.baseToString(StringOrderUtils.stringToBase("element", StringOrderUtils.DEFAULT_ALPHABET), StringOrderUtils.DEFAULT_ALPHABET))
assertEquals("matrix", StringOrderUtils.baseToString(StringOrderUtils.stringToBase("matrix", StringOrderUtils.DEFAULT_ALPHABET), StringOrderUtils.DEFAULT_ALPHABET))
}
@Test
fun testValid() {
println(StringOrderUtils.DEFAULT_ALPHABET.joinToString(","))
assert(MatrixPatterns.isValidOrderString("a"))
assert(MatrixPatterns.isValidOrderString(" "))
assert(MatrixPatterns.isValidOrderString("abc"))
assert(!MatrixPatterns.isValidOrderString("abcê"))
assert(!MatrixPatterns.isValidOrderString(""))
assert(MatrixPatterns.isValidOrderString("!"))
assert(MatrixPatterns.isValidOrderString("!\"#\$%&'()*+,012"))
assert(!MatrixPatterns.isValidOrderString(Char(' '.code - 1).toString()))
assert(!MatrixPatterns.isValidOrderString(
buildString {
for (i in 0..49) {
append(StringOrderUtils.DEFAULT_ALPHABET.random())
}
}
))
assert(MatrixPatterns.isValidOrderString(
buildString {
for (i in 0..48) {
append(StringOrderUtils.DEFAULT_ALPHABET.random())
}
}
))
}
@Test
fun testAverage() {
assertAverage("${StringOrderUtils.DEFAULT_ALPHABET.first()}", "m")
assertAverage("aa", "aab")
assertAverage("matrix", "element")
assertAverage("mmm", "mmmmm")
assertAverage("aab", "aa")
assertAverage("", "aa")
assertAverage("a", "z")
assertAverage("ground", "sky")
}
@Test
fun testMidPoints() {
val orders = StringOrderUtils.midPoints("element", "matrix", 4)
assertEquals(4, orders!!.size)
assert("element" < orders[0])
assert(orders[0] < orders[1])
assert(orders[1] < orders[2])
assert(orders[2] < orders[3])
assert(orders[3] < "matrix")
println("element < ${orders.joinToString(" < ") { "[$it]" }} < matrix")
val orders2 = StringOrderUtils.midPoints("a", "d", 4)
assertEquals(null, orders2)
}
@Test
fun testRenumberNeeded() {
assertEquals(null, StringOrderUtils.average("a", "a"))
assertEquals(null, StringOrderUtils.average("", ""))
assertEquals(null, StringOrderUtils.average("a", "b"))
assertEquals(null, StringOrderUtils.average("b", "a"))
assertEquals(null, StringOrderUtils.average("mmmm", "mmmm"))
assertEquals(null, StringOrderUtils.average("a${Char(0)}", "a"))
}
private fun assertAverage(first: String, second: String) {
val left = first.takeIf { first < second } ?: second
val right = first.takeIf { first > second } ?: second
val av1 = StringOrderUtils.average(left, right)!!
println("[$left] < [$av1] < [$right]")
Assert.assertTrue(left < av1)
Assert.assertTrue(av1 < right)
}
}
......@@ -78,7 +78,7 @@ class CommonTestHelper(context: Context) {
}
/**
* Create a Home server configuration, with Http connection allowed for test
* Create a homeserver configuration, with Http connection allowed for test
*/
fun createHomeServerConfig(): HomeServerConnectionConfig {
return HomeServerConnectionConfig.Builder()
......
......@@ -816,7 +816,7 @@ class KeysBackupTest : InstrumentedTest {
// - Do an e2e backup to the homeserver
mKeysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)
// Get key backup version from the home server
// Get key backup version from the homeserver
val keysVersionResult = mTestHelper.doSync<KeysVersionResult?> {
keysBackup.getCurrentVersion(it)
}
......
......@@ -33,7 +33,7 @@ import org.matrix.android.sdk.common.TestConstants
import org.matrix.android.sdk.internal.crypto.SSSS_ALGORITHM_AES_HMAC_SHA2
import org.matrix.android.sdk.internal.crypto.crosssigning.toBase64NoPadding
import org.matrix.android.sdk.internal.crypto.secrets.DefaultSharedSecretStorageService
import org.matrix.android.sdk.api.session.accountdata.AccountDataEvent
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
......@@ -73,12 +73,12 @@ class QuadSTests : InstrumentedTest {
// Assert Account data is updated
val accountDataLock = CountDownLatch(1)
var accountData: AccountDataEvent? = null
var accountData: UserAccountDataEvent? = null
val liveAccountData = runBlocking(Dispatchers.Main) {
aliceSession.userAccountDataService().getLiveAccountDataEvent("${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID")
aliceSession.accountDataService().getLiveUserAccountDataEvent("${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID")
}
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
val accountDataObserver = Observer<Optional<UserAccountDataEvent>?> { t ->
if (t?.getOrNull()?.type == "${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID") {
accountData = t.getOrNull()
accountDataLock.countDown()
......@@ -100,13 +100,13 @@ class QuadSTests : InstrumentedTest {
quadS.setDefaultKey(TEST_KEY_ID)
}
var defaultKeyAccountData: AccountDataEvent? = null
var defaultKeyAccountData: UserAccountDataEvent? = null
val defaultDataLock = CountDownLatch(1)
val liveDefAccountData = runBlocking(Dispatchers.Main) {
aliceSession.userAccountDataService().getLiveAccountDataEvent(DefaultSharedSecretStorageService.DEFAULT_KEY_ID)
aliceSession.accountDataService().getLiveUserAccountDataEvent(DefaultSharedSecretStorageService.DEFAULT_KEY_ID)
}
val accountDefDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
val accountDefDataObserver = Observer<Optional<UserAccountDataEvent>?> { t ->
if (t?.getOrNull()?.type == DefaultSharedSecretStorageService.DEFAULT_KEY_ID) {
defaultKeyAccountData = t.getOrNull()!!
defaultDataLock.countDown()
......@@ -206,7 +206,7 @@ class QuadSTests : InstrumentedTest {
)
}
val accountDataEvent = aliceSession.userAccountDataService().getAccountDataEvent("my.secret")
val accountDataEvent = aliceSession.accountDataService().getUserAccountDataEvent("my.secret")
val encryptedContent = accountDataEvent?.content?.get("encrypted") as? Map<*, *>
assertEquals("Content should contains two encryptions", 2, encryptedContent?.keys?.size ?: 0)
......@@ -275,14 +275,14 @@ class QuadSTests : InstrumentedTest {
mTestHelper.signOutAndClose(aliceSession)
}
private fun assertAccountData(session: Session, type: String): AccountDataEvent {
private fun assertAccountData(session: Session, type: String): UserAccountDataEvent {
val accountDataLock = CountDownLatch(1)
var accountData: AccountDataEvent? = null
var accountData: UserAccountDataEvent? = null
val liveAccountData = runBlocking(Dispatchers.Main) {
session.userAccountDataService().getLiveAccountDataEvent(type)
session.accountDataService().getLiveUserAccountDataEvent(type)
}
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
val accountDataObserver = Observer<Optional<UserAccountDataEvent>?> { t ->
if (t?.getOrNull()?.type == type) {
accountData = t.getOrNull()
accountDataLock.countDown()
......
......@@ -10,15 +10,6 @@
<application android:networkSecurityConfig="@xml/network_security_config">
<!--
This is mandatory to run integration tests
-->
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
<!--
The SDK offers a secured File provider to access downloaded files.
Access to these file will be given via the FileService, with a temporary
......
......@@ -16,8 +16,12 @@
package org.matrix.android.sdk.api
import org.matrix.android.sdk.BuildConfig
import timber.log.Timber
/**
* This class contains pattern to match the different Matrix ids
* Ref: https://matrix.org/docs/spec/appendices#identifier-grammar
*/
object MatrixPatterns {
......@@ -25,7 +29,7 @@ object MatrixPatterns {
private const val DOMAIN_REGEX = ":[A-Z0-9.-]+(:[0-9]{2,5})?"
// regex pattern to find matrix user ids in a string.
// See https://matrix.org/speculator/spec/HEAD/appendices.html#historical-user-ids
// See https://matrix.org/docs/spec/appendices#historical-user-ids
private const val MATRIX_USER_IDENTIFIER_REGEX = "@[A-Z0-9\\x21-\\x39\\x3B-\\x7F]+$DOMAIN_REGEX"
val PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER = MATRIX_USER_IDENTIFIER_REGEX.toRegex(RegexOption.IGNORE_CASE)
......@@ -71,6 +75,9 @@ object MatrixPatterns {
private const val LINK_TO_APP_ROOM_ALIAS_REGEXP = APP_BASE_REGEX + MATRIX_ROOM_ALIAS_REGEX + SEP_REGEX + MATRIX_EVENT_IDENTIFIER_REGEX
private val PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ALIAS = LINK_TO_APP_ROOM_ALIAS_REGEXP.toRegex(RegexOption.IGNORE_CASE)
// ascii characters in the range \x20 (space) to \x7E (~)
val ORDER_STRING_REGEX = "[ -~]+".toRegex()
// list of patterns to find some matrix item.
val MATRIX_PATTERNS = listOf(
PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID,
......@@ -146,4 +153,32 @@ object MatrixPatterns {
fun extractServerNameFromId(matrixId: String?): String? {
return matrixId?.substringAfter(":", missingDelimiterValue = "")?.takeIf { it.isNotEmpty() }
}
/**
* Orders which are not strings, or do not consist solely of ascii characters in the range \x20 (space) to \x7E (~),
* or consist of more than 50 characters, are forbidden and the field should be ignored if received.
*/
fun isValidOrderString(order: String?): Boolean {
return order != null && order.length < 50 && order matches ORDER_STRING_REGEX
}
fun candidateAliasFromRoomName(name: String): String {
return Regex("\\s").replace(name.lowercase(), "_").let {
"[^a-z0-9._%#@=+-]".toRegex().replace(it, "")
}
}
/**
* Return the domain form a userId
* Examples:
* - "@alice:domain.org".getDomain() will return "domain.org"
* - "@bob:domain.org:3455".getDomain() will return "domain.org:3455"
*/
fun String.getDomain(): String {
if (BuildConfig.DEBUG && !isUserId(this)) {
// They are some invalid userId localpart in the wild, but the domain part should be there anyway
Timber.w("Not a valid user ID: $this")
}
return substringAfter(":")
}
}
......@@ -18,11 +18,11 @@ package org.matrix.android.sdk.api.auth.data
import android.net.Uri
import com.squareup.moshi.JsonClass
import okhttp3.CipherSuite
import okhttp3.TlsVersion
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig.Builder
import org.matrix.android.sdk.internal.network.ssl.Fingerprint
import org.matrix.android.sdk.internal.util.ensureTrailingSlash
import okhttp3.CipherSuite
import okhttp3.TlsVersion
/**
* This data class holds how to connect to a specific Homeserver.
......@@ -31,7 +31,12 @@ import okhttp3.TlsVersion
*/
@JsonClass(generateAdapter = true)
data class HomeServerConnectionConfig(
// This is the homeserver URL entered by the user
val homeServerUri: Uri,
// This is the homeserver base URL for the client-server API. Default to homeServerUri,
// but can be updated with data from .Well-Known before login, and/or with the data
// included in the login response
val homeServerUriBase: Uri = homeServerUri,
val identityServerUri: Uri? = null,
val antiVirusServerUri: Uri? = null,
val allowedFingerprints: List<Fingerprint> = emptyList(),
......@@ -47,7 +52,6 @@ data class HomeServerConnectionConfig(
* This builder should be use to create a [HomeServerConnectionConfig] instance.
*/
class Builder {
private lateinit var homeServerUri: Uri
private var identityServerUri: Uri? = null
private var antiVirusServerUri: Uri? = null
......@@ -69,14 +73,14 @@ data class HomeServerConnectionConfig(
*/
fun withHomeServerUri(hsUri: Uri): Builder {
if (hsUri.scheme != "http" && hsUri.scheme != "https") {
throw RuntimeException("Invalid home server URI: $hsUri")
throw RuntimeException("Invalid homeserver URI: $hsUri")
}
// ensure trailing /
val hsString = hsUri.toString().ensureTrailingSlash()
homeServerUri = try {
Uri.parse(hsString)
} catch (e: Exception) {
throw RuntimeException("Invalid home server URI: $hsUri")
throw RuntimeException("Invalid homeserver URI: $hsUri")
}
return this
}
......@@ -134,7 +138,7 @@ data class HomeServerConnectionConfig(
}
/**
* Add an accepted TLS version for TLS connections with the home server.
* Add an accepted TLS version for TLS connections with the homeserver.
*
* @param tlsVersion the tls version to add to the set of TLS versions accepted.
* @return this builder
......@@ -156,7 +160,7 @@ data class HomeServerConnectionConfig(
}
/**
* Add a TLS cipher suite to the list of accepted TLS connections with the home server.
* Add a TLS cipher suite to the list of accepted TLS connections with the homeserver.
*
* @param tlsCipherSuite the tls cipher suite to add.
* @return this builder
......@@ -234,16 +238,16 @@ data class HomeServerConnectionConfig(
*/
fun build(): HomeServerConnectionConfig {
return HomeServerConnectionConfig(
homeServerUri,
identityServerUri,
antiVirusServerUri,
allowedFingerprints,
shouldPin,
tlsVersions,
tlsCipherSuites,
shouldAcceptTlsExtensions,
allowHttpExtension,
forceUsageTlsVersions
homeServerUri = homeServerUri,
identityServerUri = identityServerUri,
antiVirusServerUri = antiVirusServerUri,
allowedFingerprints = allowedFingerprints,
shouldPin = shouldPin,
tlsVersions = tlsVersions,
tlsCipherSuites = tlsCipherSuites,
shouldAcceptTlsExtensions = shouldAcceptTlsExtensions,
allowHttpExtension = allowHttpExtension,
forceUsageTlsVersions = forceUsageTlsVersions
)
}
}
......
......@@ -51,13 +51,18 @@ data class SessionParams(
val deviceId = credentials.deviceId
/**
* The current homeserver Url. It can be different that the homeserver url entered
* during login phase, because a redirection may have occurred
* The homeserver Url entered by the user during the login phase.
*/
val homeServerUrl = homeServerConnectionConfig.homeServerUri.toString()
/**
* The current homeserver host
* The current homeserver Url for client-server API. It can be different that the homeserver url entered
* during login phase, because a redirection may have occurred
*/
val homeServerUrlBase = homeServerConnectionConfig.homeServerUriBase.toString()
/**
* The current homeserver host, using what has been entered by the user during login phase
*/
val homeServerHost = homeServerConnectionConfig.homeServerUri.host
......
......@@ -38,7 +38,7 @@ data class RegistrationFlowResponse(
val completedStages: List<String>? = null,
/**
* The session identifier that the client must pass back to the home server, if one is provided,
* The session identifier that the client must pass back to the homeserver, if one is provided,
* in subsequent attempts to authenticate in the same API call.
*/
@Json(name = "session")
......
......@@ -22,11 +22,6 @@ import org.matrix.android.sdk.api.auth.data.WellKnown
* Ref: https://matrix.org/docs/spec/client_server/latest#well-known-uri
*/
sealed class WellknownResult {
/**
* The provided matrixId is no valid. Unable to extract a domain name.
*/
object InvalidMatrixId : WellknownResult()
/**
* Retrieve the specific piece of information from the user in a way which fits within the existing client user experience,
* if the client is inclined to do so. Failure can take place instead if no good user experience for this is possible at this point.
......
/*
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.failure
sealed class MatrixIdFailure : Failure.FeatureFailure() {
object InvalidMatrixId : MatrixIdFailure()
}
/*
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.logger
/**
* Parent class for custom logger tags. Can be used with Timber :
*
* val loggerTag = LoggerTag("MyTag", LoggerTag.VOIP)
* Timber.tag(loggerTag.value).v("My log message")
*/
open class LoggerTag(_value: String, parentTag: LoggerTag? = null) {
object VOIP : LoggerTag("VOIP")
val value: String = if (parentTag == null) {
_value
} else {
"${parentTag.value}/$_value"
}
}
......@@ -31,7 +31,13 @@ interface PushRuleService {
suspend fun addPushRule(kind: RuleKind, pushRule: PushRule)
suspend fun updatePushRuleActions(kind: RuleKind, oldPushRule: PushRule, newPushRule: PushRule)
/**
* Enables/Disables a push rule and updates the actions if necessary
* @param enable Enables/Disables the rule
* @param actions Actions to update if not null
*/
suspend fun updatePushRuleActions(kind: RuleKind, ruleId: String, enable: Boolean, actions: List<Action>?)
suspend fun removePushRule(kind: RuleKind, pushRule: PushRule)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment