Replace matrix callbacks by coroutines

This commit is contained in:
yostyle 2021-11-10 16:32:35 +01:00
parent 98ae9d0e8a
commit 7a78bc6866
22 changed files with 324 additions and 149 deletions

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.session.contentscanner package org.matrix.android.sdk.api.session.contentscanner

View File

@ -1,13 +1,22 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.session.contentscanner package org.matrix.android.sdk.api.session.contentscanner
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
@ -20,16 +29,14 @@ interface ContentScannerService {
* Get the current public curve25519 key that the AV server is advertising. * Get the current public curve25519 key that the AV server is advertising.
* @param callback on success callback containing the server public key * @param callback on success callback containing the server public key
*/ */
fun getServerPublicKey(forceDownload: Boolean = false, callback: MatrixCallback<String?>) suspend fun getServerPublicKey(forceDownload: Boolean = false): String?
fun getScanResultForAttachment(mxcUrl: String, callback: MatrixCallback<ScanStatusInfo>) suspend fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt? = null): ScanStatusInfo
fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt, callback: MatrixCallback<ScanStatusInfo>)
fun setScannerUrl(url: String?) fun setScannerUrl(url: String?)
fun enableScanner(enabled: Boolean) fun enableScanner(enabled: Boolean)
fun isScannerEnabled(): Boolean fun isScannerEnabled(): Boolean
fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean = true): LiveData<Optional<ScanStatusInfo>> fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean = true, fileInfo: ElementToDecrypt? = null): LiveData<Optional<ScanStatusInfo>>
fun getLiveStatusForEncryptedFile(mxcUrl: String, fileInfo: ElementToDecrypt, fetchIfNeeded: Boolean = true): LiveData<Optional<ScanStatusInfo>>
fun getCachedScanResultForFile(mxcUrl: String): ScanStatusInfo? fun getCachedScanResultForFile(mxcUrl: String): ScanStatusInfo?
} }

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.session.contentscanner package org.matrix.android.sdk.api.session.contentscanner

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner package org.matrix.android.sdk.internal.session.contentscanner

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner package org.matrix.android.sdk.internal.session.contentscanner

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner package org.matrix.android.sdk.internal.session.contentscanner
@ -55,7 +65,7 @@ internal abstract class ContentScannerModule {
} }
@Binds @Binds
abstract fun bindContentScannerService(service: DefaultContentScannerService): ContentScannerService abstract fun bindContentScannerService(service: DisabledContentScannerService): ContentScannerService
@Binds @Binds
abstract fun bindContentScannerStore(store: RealmContentScannerStore): ContentScannerStore abstract fun bindContentScannerStore(store: RealmContentScannerStore): ContentScannerStore

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner package org.matrix.android.sdk.internal.session.contentscanner
@ -10,9 +20,6 @@ import androidx.lifecycle.LiveData
import dagger.Lazy import dagger.Lazy
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.NoOpMatrixCallback
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
import org.matrix.android.sdk.api.session.contentscanner.ScanState import org.matrix.android.sdk.api.session.contentscanner.ScanState
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
@ -26,8 +33,6 @@ import org.matrix.android.sdk.internal.session.contentscanner.tasks.GetServerPub
import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanEncryptedTask import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanEncryptedTask
import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanMediaTask import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanMediaTask
import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.launchToCallback
import org.matrix.android.sdk.internal.util.awaitCallback
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -38,12 +43,10 @@ internal class DefaultContentScannerService @Inject constructor(
private val okHttpClient: Lazy<OkHttpClient>, private val okHttpClient: Lazy<OkHttpClient>,
private val contentScannerApiProvider: ContentScannerApiProvider, private val contentScannerApiProvider: ContentScannerApiProvider,
private val contentScannerStore: ContentScannerStore, private val contentScannerStore: ContentScannerStore,
// private val sessionParams: SessionParams,
private val getServerPublicKeyTask: GetServerPublicKeyTask, private val getServerPublicKeyTask: GetServerPublicKeyTask,
private val scanEncryptedTask: ScanEncryptedTask, private val scanEncryptedTask: ScanEncryptedTask,
private val scanMediaTask: ScanMediaTask, private val scanMediaTask: ScanMediaTask,
private val taskExecutor: TaskExecutor, private val taskExecutor: TaskExecutor
private val coroutineDispatchers: MatrixCoroutineDispatchers
) : ContentScannerService { ) : ContentScannerService {
// Cache public key in memory // Cache public key in memory
@ -54,53 +57,35 @@ internal class DefaultContentScannerService @Inject constructor(
return contentScannerStore.getScannerUrl() return contentScannerStore.getScannerUrl()
} }
override fun getServerPublicKey(forceDownload: Boolean, callback: MatrixCallback<String?>) { override suspend fun getServerPublicKey(forceDownload: Boolean): String? {
val api = contentScannerApiProvider.contentScannerApi ?: return Unit.also { val api = contentScannerApiProvider.contentScannerApi ?: throw IllegalArgumentException("No content scanner define")
callback.onFailure(IllegalArgumentException("No content scanner defined"))
}
if (!forceDownload && serverPublicKey != null) { if (!forceDownload && serverPublicKey != null) {
callback.onSuccess(serverPublicKey) return serverPublicKey
return
} }
taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, callback) {
getServerPublicKeyTask.execute(GetServerPublicKeyTask.Params(api)).also { return getServerPublicKeyTask.execute(GetServerPublicKeyTask.Params(api)).also {
serverPublicKey = it serverPublicKey = it
} }
} }
}
override fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt, callback: MatrixCallback<ScanStatusInfo>) { override suspend fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt?): ScanStatusInfo {
taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, callback) { val result = if (fileInfo != null) {
val serverPublicKey = serverPublicKey ?: awaitCallback<String?> { scanEncryptedTask.execute(ScanEncryptedTask.Params(
getServerPublicKey(false, it)
}
val result = scanEncryptedTask.execute(ScanEncryptedTask.Params(
mxcUrl = mxcUrl, mxcUrl = mxcUrl,
publicServerKey = serverPublicKey, publicServerKey = getServerPublicKey(false),
encryptedInfo = fileInfo encryptedInfo = fileInfo
)) ))
} else {
scanMediaTask.execute(ScanMediaTask.Params(mxcUrl))
}
ScanStatusInfo( return ScanStatusInfo(
state = if (result.clean) ScanState.TRUSTED else ScanState.INFECTED, state = if (result.clean) ScanState.TRUSTED else ScanState.INFECTED,
humanReadableMessage = result.info, humanReadableMessage = result.info,
scanDateTimestamp = System.currentTimeMillis() scanDateTimestamp = System.currentTimeMillis()
) )
} }
}
override fun getScanResultForAttachment(mxcUrl: String, callback: MatrixCallback<ScanStatusInfo>) {
taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, callback) {
val result = scanMediaTask.execute(ScanMediaTask.Params(mxcUrl))
ScanStatusInfo(
state = if (result.clean) ScanState.TRUSTED else ScanState.INFECTED,
humanReadableMessage = result.info,
scanDateTimestamp = System.currentTimeMillis()
)
}
}
override fun setScannerUrl(url: String?) = contentScannerStore.setScannerUrl(url).also { override fun setScannerUrl(url: String?) = contentScannerStore.setScannerUrl(url).also {
if (url == null) { if (url == null) {
@ -112,11 +97,9 @@ internal class DefaultContentScannerService @Inject constructor(
.create(ContentScannerApi::class.java) .create(ContentScannerApi::class.java)
contentScannerApiProvider.contentScannerApi = api contentScannerApiProvider.contentScannerApi = api
taskExecutor.executorScope.launch(coroutineDispatchers.io) { taskExecutor.executorScope.launch {
try { try {
awaitCallback<String?> { getServerPublicKey(true)
getServerPublicKey(true, it)
}
} catch (failure: Throwable) { } catch (failure: Throwable) {
Timber.e("Failed to get public server api") Timber.e("Failed to get public server api")
} }
@ -124,7 +107,7 @@ internal class DefaultContentScannerService @Inject constructor(
} }
} }
override fun enableScanner(enabled: Boolean) = contentScannerStore.enableScanning(enabled) override fun enableScanner(enabled: Boolean) = contentScannerStore.enableScanner(enabled)
override fun isScannerEnabled(): Boolean = contentScannerStore.isScanEnabled() override fun isScannerEnabled(): Boolean = contentScannerStore.isScanEnabled()
@ -132,18 +115,16 @@ internal class DefaultContentScannerService @Inject constructor(
return contentScannerStore.getScanResult(mxcUrl) return contentScannerStore.getScanResult(mxcUrl)
} }
override fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> { override fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean, fileInfo: ElementToDecrypt?): LiveData<Optional<ScanStatusInfo>> {
val data = contentScannerStore.getLiveScanResult(mxcUrl) val data = contentScannerStore.getLiveScanResult(mxcUrl)
if (fetchIfNeeded && !contentScannerStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) { if (fetchIfNeeded && !contentScannerStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
getScanResultForAttachment(mxcUrl, NoOpMatrixCallback()) taskExecutor.executorScope.launch {
try {
getScanResultForAttachment(mxcUrl, fileInfo)
} catch (failure: Throwable) {
Timber.e("Failed to get file status : ${failure.localizedMessage}")
} }
return data
} }
override fun getLiveStatusForEncryptedFile(mxcUrl: String, fileInfo: ElementToDecrypt, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> {
val data = contentScannerStore.getLiveScanResult(mxcUrl)
if (fetchIfNeeded && !contentScannerStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
getScanResultForAttachment(mxcUrl, fileInfo, NoOpMatrixCallback())
} }
return data return data
} }

View File

@ -18,16 +18,18 @@ package org.matrix.android.sdk.internal.session.contentscanner
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
import org.matrix.android.sdk.internal.session.SessionScope
import javax.inject.Inject
/** /**
* Created to by-pass ProfileTask execution in LoginWizard. * Created to by-pass ProfileTask execution in LoginWizard.
*/ */
class DisabledContentScannerService : ContentScannerService { @SessionScope
internal class DisabledContentScannerService @Inject constructor() : ContentScannerService {
override val serverPublicKey: String? override val serverPublicKey: String?
get() = null get() = null
@ -36,13 +38,12 @@ class DisabledContentScannerService : ContentScannerService {
return null return null
} }
override fun getServerPublicKey(forceDownload: Boolean, callback: MatrixCallback<String?>) { override suspend fun getServerPublicKey(forceDownload: Boolean): String? {
return null
} }
override fun getScanResultForAttachment(mxcUrl: String, callback: MatrixCallback<ScanStatusInfo>) { override suspend fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt?): ScanStatusInfo {
} TODO("Not yet implemented")
override fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt, callback: MatrixCallback<ScanStatusInfo>) {
} }
override fun setScannerUrl(url: String?) { override fun setScannerUrl(url: String?) {
@ -55,11 +56,7 @@ class DisabledContentScannerService : ContentScannerService {
return false return false
} }
override fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> { override fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean, fileInfo: ElementToDecrypt?): LiveData<Optional<ScanStatusInfo>> {
return MutableLiveData()
}
override fun getLiveStatusForEncryptedFile(mxcUrl: String, fileInfo: ElementToDecrypt, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> {
return MutableLiveData() return MutableLiveData()
} }

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner package org.matrix.android.sdk.internal.session.contentscanner
@ -14,7 +24,7 @@ import org.matrix.android.sdk.internal.session.contentscanner.model.DownloadBody
import org.matrix.android.sdk.internal.session.contentscanner.model.EncryptedBody import org.matrix.android.sdk.internal.session.contentscanner.model.EncryptedBody
import org.matrix.android.sdk.internal.session.contentscanner.model.toCanonicalJson import org.matrix.android.sdk.internal.session.contentscanner.model.toCanonicalJson
object ScanEncryptorUtils { internal object ScanEncryptorUtils {
fun getDownloadBodyAndEncryptIfNeeded(publicServerKey: String?, mxcUrl: String, elementToDecrypt: ElementToDecrypt): DownloadBody { fun getDownloadBodyAndEncryptIfNeeded(publicServerKey: String?, mxcUrl: String, elementToDecrypt: ElementToDecrypt): DownloadBody {
// TODO, upstream refactoring changed the object model here... // TODO, upstream refactoring changed the object model here...

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.data package org.matrix.android.sdk.internal.session.contentscanner.data
@ -17,7 +27,7 @@ internal interface ContentScannerStore {
fun setScannerUrl(url: String?) fun setScannerUrl(url: String?)
fun enableScanning(enabled: Boolean) fun enableScanner(enabled: Boolean)
fun isScanEnabled(): Boolean fun isScanEnabled(): Boolean

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.db package org.matrix.android.sdk.internal.session.contentscanner.db

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.db package org.matrix.android.sdk.internal.session.contentscanner.db

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.db package org.matrix.android.sdk.internal.session.contentscanner.db

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.db package org.matrix.android.sdk.internal.session.contentscanner.db

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.db package org.matrix.android.sdk.internal.session.contentscanner.db
@ -52,7 +62,7 @@ internal class RealmContentScannerStore @Inject constructor(
} }
} }
override fun enableScanning(enabled: Boolean) { override fun enableScanner(enabled: Boolean) {
monarchy.runTransactionSync { realm -> monarchy.runTransactionSync { realm ->
val info = realm.where<ContentScannerInfoEntity>().findFirst() val info = realm.where<ContentScannerInfoEntity>().findFirst()
?: realm.createObject() ?: realm.createObject()

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.model package org.matrix.android.sdk.internal.session.contentscanner.model
@ -13,18 +23,18 @@ import org.matrix.android.sdk.internal.di.MoshiProvider
import org.matrix.android.sdk.internal.util.JsonCanonicalizer import org.matrix.android.sdk.internal.util.JsonCanonicalizer
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class DownloadBody( internal data class DownloadBody(
@Json(name = "file") val file: EncryptedFileInfo? = null, @Json(name = "file") val file: EncryptedFileInfo? = null,
@Json(name = "encrypted_body") val encryptedBody: EncryptedBody? = null @Json(name = "encrypted_body") val encryptedBody: EncryptedBody? = null
) )
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class EncryptedBody( internal data class EncryptedBody(
@Json(name = "ciphertext") val cipherText: String, @Json(name = "ciphertext") val cipherText: String,
@Json(name = "mac") val mac: String, @Json(name = "mac") val mac: String,
@Json(name = "ephemeral") val ephemeral: String @Json(name = "ephemeral") val ephemeral: String
) )
fun DownloadBody.toJson(): String = MoshiProvider.providesMoshi().adapter(DownloadBody::class.java).toJson(this) internal fun DownloadBody.toJson(): String = MoshiProvider.providesMoshi().adapter(DownloadBody::class.java).toJson(this)
fun DownloadBody.toCanonicalJson() = JsonCanonicalizer.getCanonicalJson(DownloadBody::class.java, this) internal fun DownloadBody.toCanonicalJson() = JsonCanonicalizer.getCanonicalJson(DownloadBody::class.java, this)

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.model package org.matrix.android.sdk.internal.session.contentscanner.model
@ -16,7 +26,7 @@ import com.squareup.moshi.JsonClass
* } * }
*/ */
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class ScanResponse( internal data class ScanResponse(
@Json(name = "clean") val clean: Boolean, @Json(name = "clean") val clean: Boolean,
/** Human-readable information about the result. */ /** Human-readable information about the result. */
@Json(name = "info") val info: String? @Json(name = "info") val info: String?

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.model package org.matrix.android.sdk.internal.session.contentscanner.model
@ -10,7 +20,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class ServerPublicKeyResponse( internal data class ServerPublicKeyResponse(
@Json(name = "public_key") @Json(name = "public_key")
val publicKey : String? val publicKey : String?
) )

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.tasks package org.matrix.android.sdk.internal.session.contentscanner.tasks

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.tasks package org.matrix.android.sdk.internal.session.contentscanner.tasks

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.tasks package org.matrix.android.sdk.internal.session.contentscanner.tasks

View File

@ -1,7 +1,17 @@
/* /*
* Copyright 2020 New Vector Ltd - All Rights Reserved * Copyright 2021 The Matrix.org Foundation C.I.C.
* Unauthorized copying of this file, via any medium is strictly prohibited *
* Proprietary and confidential * 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.internal.session.contentscanner.tasks package org.matrix.android.sdk.internal.session.contentscanner.tasks