mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Refactoring
This commit is contained in:
parent
016f3faeea
commit
98ae9d0e8a
28 changed files with 123 additions and 124 deletions
|
@ -18,8 +18,8 @@ package org.matrix.android.sdk.api.failure
|
|||
|
||||
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScanError
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanFailure
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerError
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanFailure
|
||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||
import java.io.IOException
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
@ -110,7 +110,7 @@ fun Throwable.toScanFailure(): ScanFailure? {
|
|||
return if (this is Failure.OtherServerError) {
|
||||
tryOrNull {
|
||||
MoshiProvider.providesMoshi()
|
||||
.adapter(ContentScanError::class.java)
|
||||
.adapter(ContentScannerError::class.java)
|
||||
.fromJson(errorBody)
|
||||
}
|
||||
?.let { ScanFailure(it, httpCode, this) }
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.matrix.android.sdk.api.session.cache.CacheService
|
|||
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
||||
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
||||
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.events.EventService
|
||||
import org.matrix.android.sdk.api.session.file.ContentDownloadStateTracker
|
||||
|
@ -194,9 +194,9 @@ interface Session :
|
|||
fun cryptoService(): CryptoService
|
||||
|
||||
/**
|
||||
* Returns the ContentScanningService associated with the session
|
||||
* Returns the ContentScannerService associated with the session
|
||||
*/
|
||||
fun contentScanningService(): ContentScannerService
|
||||
fun contentScannerService(): ContentScannerService
|
||||
|
||||
/**
|
||||
* Returns the identity service associated with the session
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.contentscanning
|
||||
package org.matrix.android.sdk.api.session.contentscanner
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class ContentScanError(
|
||||
data class ContentScannerError(
|
||||
@Json(name = "info") val info: String? = null,
|
||||
@Json(name = "reason") val reason: String? = null
|
||||
) {
|
||||
|
@ -32,7 +32,7 @@ data class ContentScanError(
|
|||
}
|
||||
}
|
||||
|
||||
class ScanFailure(val error: ContentScanError, val httpCode: Int, cause: Throwable? = null) : Throwable(cause = cause)
|
||||
class ScanFailure(val error: ContentScannerError, val httpCode: Int, cause: Throwable? = null) : Throwable(cause = cause)
|
||||
|
||||
// For Glide, which deals with Exception and not with Throwable
|
||||
fun ScanFailure.toException() = Exception(this)
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.contentscanning
|
||||
package org.matrix.android.sdk.api.session.contentscanner
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.contentscanning
|
||||
package org.matrix.android.sdk.api.session.contentscanner
|
||||
|
||||
enum class ScanState {
|
||||
TRUSTED,
|
|
@ -33,7 +33,7 @@ import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistration
|
|||
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.content.DefaultContentUrlResolver
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.DisabledContentScannerService
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.DisabledContentScannerService
|
||||
|
||||
internal class DefaultLoginWizard(
|
||||
private val authAPI: AuthAPI,
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.matrix.android.sdk.api.session.cache.CacheService
|
|||
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
||||
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
||||
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.events.EventService
|
||||
import org.matrix.android.sdk.api.session.file.ContentDownloadStateTracker
|
||||
|
@ -277,7 +277,7 @@ internal class DefaultSession @Inject constructor(
|
|||
|
||||
override fun cryptoService(): CryptoService = cryptoService.get()
|
||||
|
||||
override fun contentScanningService(): ContentScannerService = contentScannerService.get()
|
||||
override fun contentScannerService(): ContentScannerService = contentScannerService.get()
|
||||
|
||||
override fun identityService() = identityService
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.session
|
|||
|
||||
import dagger.BindsInstance
|
||||
import dagger.Component
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScannerModule
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ContentScannerModule
|
||||
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
|
|
@ -20,11 +20,11 @@ import org.matrix.android.sdk.api.MatrixUrls
|
|||
import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.toJson
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.toJson
|
||||
import org.matrix.android.sdk.internal.util.ensureTrailingSlash
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import okhttp3.ResponseBody
|
||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.DownloadBody
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.ServerPublicKeyResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.DownloadBody
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.ServerPublicKeyResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
|
@ -19,7 +19,7 @@ import retrofit2.http.Path
|
|||
/**
|
||||
* https://github.com/matrix-org/matrix-content-scanner
|
||||
*/
|
||||
internal interface ContentScanApi {
|
||||
internal interface ContentScannerApi {
|
||||
|
||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE + "download_encrypted")
|
||||
suspend fun downloadEncrypted(@Body info: DownloadBody): ResponseBody
|
|
@ -4,13 +4,12 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScanApi
|
||||
import javax.inject.Inject
|
||||
|
||||
@SessionScope
|
||||
internal class ContentScanningApiProvider @Inject constructor() {
|
||||
var contentScannerApi: ContentScanApi? = null
|
||||
internal class ContentScannerApiProvider @Inject constructor() {
|
||||
var contentScannerApi: ContentScannerApi? = null
|
||||
}
|
|
@ -4,30 +4,30 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.realm.RealmConfiguration
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
|
||||
import org.matrix.android.sdk.internal.database.RealmKeysUtils
|
||||
import org.matrix.android.sdk.internal.di.ContentScannerDatabase
|
||||
import org.matrix.android.sdk.internal.di.SessionFilesDirectory
|
||||
import org.matrix.android.sdk.internal.di.UserMd5
|
||||
import org.matrix.android.sdk.internal.session.SessionModule
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.data.ContentScanningStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.db.ContentScannerRealmModule
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.db.RealmContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.DefaultDownloadEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.DefaultGetServerPublicKeyTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.DefaultScanEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.DefaultScanMediaTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.DownloadEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.GetServerPublicKeyTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.ScanEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.ScanMediaTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.data.ContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.db.ContentScannerRealmModule
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.db.RealmContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.DefaultDownloadEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.DefaultGetServerPublicKeyTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.DefaultScanEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.DefaultScanMediaTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.DownloadEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.GetServerPublicKeyTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.ScanMediaTask
|
||||
import java.io.File
|
||||
|
||||
@Module
|
||||
|
@ -58,7 +58,7 @@ internal abstract class ContentScannerModule {
|
|||
abstract fun bindContentScannerService(service: DefaultContentScannerService): ContentScannerService
|
||||
|
||||
@Binds
|
||||
abstract fun bindContentScannerStore(store: RealmContentScannerStore): ContentScanningStore
|
||||
abstract fun bindContentScannerStore(store: RealmContentScannerStore): ContentScannerStore
|
||||
|
||||
@Binds
|
||||
abstract fun bindDownloadEncryptedTask(task: DefaultDownloadEncryptedTask): DownloadEncryptedTask
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import dagger.Lazy
|
||||
|
@ -13,18 +13,18 @@ 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.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanStatusInfo
|
||||
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.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.di.Unauthenticated
|
||||
import org.matrix.android.sdk.internal.network.RetrofitFactory
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.data.ContentScanningStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.GetServerPublicKeyTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.ScanEncryptedTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.tasks.ScanMediaTask
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.data.ContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.tasks.GetServerPublicKeyTask
|
||||
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.task.TaskExecutor
|
||||
import org.matrix.android.sdk.internal.task.launchToCallback
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
|
@ -36,8 +36,8 @@ internal class DefaultContentScannerService @Inject constructor(
|
|||
private val retrofitFactory: RetrofitFactory,
|
||||
@Unauthenticated
|
||||
private val okHttpClient: Lazy<OkHttpClient>,
|
||||
private val contentScanningApiProvider: ContentScanningApiProvider,
|
||||
private val contentScanningStore: ContentScanningStore,
|
||||
private val contentScannerApiProvider: ContentScannerApiProvider,
|
||||
private val contentScannerStore: ContentScannerStore,
|
||||
// private val sessionParams: SessionParams,
|
||||
private val getServerPublicKeyTask: GetServerPublicKeyTask,
|
||||
private val scanEncryptedTask: ScanEncryptedTask,
|
||||
|
@ -51,11 +51,11 @@ internal class DefaultContentScannerService @Inject constructor(
|
|||
private set
|
||||
|
||||
override fun getContentScannerServer(): String? {
|
||||
return contentScanningStore.getScannerUrl()
|
||||
return contentScannerStore.getScannerUrl()
|
||||
}
|
||||
|
||||
override fun getServerPublicKey(forceDownload: Boolean, callback: MatrixCallback<String?>) {
|
||||
val api = contentScanningApiProvider.contentScannerApi ?: return Unit.also {
|
||||
val api = contentScannerApiProvider.contentScannerApi ?: return Unit.also {
|
||||
callback.onFailure(IllegalArgumentException("No content scanner defined"))
|
||||
}
|
||||
|
||||
|
@ -102,15 +102,15 @@ internal class DefaultContentScannerService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun setScannerUrl(url: String?) = contentScanningStore.setScannerUrl(url).also {
|
||||
override fun setScannerUrl(url: String?) = contentScannerStore.setScannerUrl(url).also {
|
||||
if (url == null) {
|
||||
contentScanningApiProvider.contentScannerApi = null
|
||||
contentScannerApiProvider.contentScannerApi = null
|
||||
serverPublicKey = null
|
||||
} else {
|
||||
val api = retrofitFactory
|
||||
.create(okHttpClient, url)
|
||||
.create(ContentScanApi::class.java)
|
||||
contentScanningApiProvider.contentScannerApi = api
|
||||
.create(ContentScannerApi::class.java)
|
||||
contentScannerApiProvider.contentScannerApi = api
|
||||
|
||||
taskExecutor.executorScope.launch(coroutineDispatchers.io) {
|
||||
try {
|
||||
|
@ -124,25 +124,25 @@ internal class DefaultContentScannerService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun enableScanner(enabled: Boolean) = contentScanningStore.enableScanning(enabled)
|
||||
override fun enableScanner(enabled: Boolean) = contentScannerStore.enableScanning(enabled)
|
||||
|
||||
override fun isScannerEnabled(): Boolean = contentScanningStore.isScanEnabled()
|
||||
override fun isScannerEnabled(): Boolean = contentScannerStore.isScanEnabled()
|
||||
|
||||
override fun getCachedScanResultForFile(mxcUrl: String): ScanStatusInfo? {
|
||||
return contentScanningStore.getScanResult(mxcUrl)
|
||||
return contentScannerStore.getScanResult(mxcUrl)
|
||||
}
|
||||
|
||||
override fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> {
|
||||
val data = contentScanningStore.getLiveScanResult(mxcUrl)
|
||||
if (fetchIfNeeded && !contentScanningStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
|
||||
val data = contentScannerStore.getLiveScanResult(mxcUrl)
|
||||
if (fetchIfNeeded && !contentScannerStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
|
||||
getScanResultForAttachment(mxcUrl, NoOpMatrixCallback())
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
override fun getLiveStatusForEncryptedFile(mxcUrl: String, fileInfo: ElementToDecrypt, fetchIfNeeded: Boolean): LiveData<Optional<ScanStatusInfo>> {
|
||||
val data = contentScanningStore.getLiveScanResult(mxcUrl)
|
||||
if (fetchIfNeeded && !contentScanningStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
|
||||
val data = contentScannerStore.getLiveScanResult(mxcUrl)
|
||||
if (fetchIfNeeded && !contentScannerStore.isScanResultKnownOrInProgress(mxcUrl, getContentScannerServer())) {
|
||||
getScanResultForAttachment(mxcUrl, fileInfo, NoOpMatrixCallback())
|
||||
}
|
||||
return data
|
|
@ -14,13 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ContentScannerService
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
|
|
@ -4,15 +4,15 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning
|
||||
package org.matrix.android.sdk.internal.session.contentscanner
|
||||
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileInfo
|
||||
import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileKey
|
||||
import org.matrix.android.sdk.internal.crypto.tools.withOlmEncryption
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.DownloadBody
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.EncryptedBody
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.toCanonicalJson
|
||||
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.toCanonicalJson
|
||||
|
||||
object ScanEncryptorUtils {
|
||||
|
|
@ -4,14 +4,14 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.data
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
||||
internal interface ContentScanningStore {
|
||||
internal interface ContentScannerStore {
|
||||
|
||||
fun getScannerUrl(): String?
|
||||
|
|
@ -4,13 +4,13 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.db
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.db
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.Index
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanStatusInfo
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
|
||||
|
||||
internal open class ContentScanResultEntity(
|
||||
@Index
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.db
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.db
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.db
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.db
|
||||
|
||||
import io.realm.RealmObject
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.db
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.db
|
||||
|
||||
import io.realm.annotations.RealmModule
|
||||
|
|
@ -4,14 +4,14 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.db
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.db
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.data.ContentScanningStore
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanStatusInfo
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.data.ContentScannerStore
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanStatusInfo
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import io.realm.kotlin.createObject
|
||||
|
@ -28,7 +28,7 @@ import javax.inject.Inject
|
|||
internal class RealmContentScannerStore @Inject constructor(
|
||||
@ContentScannerDatabase
|
||||
private val realmConfiguration: RealmConfiguration
|
||||
) : ContentScanningStore {
|
||||
) : ContentScannerStore {
|
||||
|
||||
private val monarchy = Monarchy.Builder()
|
||||
.setRealmConfiguration(realmConfiguration)
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.model
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.model
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
|
@ -4,7 +4,7 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.model
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
|
@ -4,13 +4,13 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.tasks
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.tasks
|
||||
|
||||
import okhttp3.ResponseBody
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScanningApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ContentScannerApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -23,7 +23,7 @@ internal interface DownloadEncryptedTask : Task<DownloadEncryptedTask.Params, Re
|
|||
}
|
||||
|
||||
internal class DefaultDownloadEncryptedTask @Inject constructor(
|
||||
private val contentScanningApiProvider: ContentScanningApiProvider
|
||||
private val contentScannerApiProvider: ContentScannerApiProvider
|
||||
) : DownloadEncryptedTask {
|
||||
|
||||
override suspend fun execute(params: DownloadEncryptedTask.Params): ResponseBody {
|
||||
|
@ -33,7 +33,7 @@ internal class DefaultDownloadEncryptedTask @Inject constructor(
|
|||
params.encryptedInfo
|
||||
)
|
||||
|
||||
val api = contentScanningApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
val api = contentScannerApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
return executeRequest(null) {
|
||||
api.downloadEncrypted(dlBody)
|
||||
}
|
|
@ -4,17 +4,17 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.tasks
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.tasks
|
||||
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScanApi
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.ServerPublicKeyResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ContentScannerApi
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.ServerPublicKeyResponse
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetServerPublicKeyTask : Task<GetServerPublicKeyTask.Params, String?> {
|
||||
data class Params(
|
||||
val contentScanApi: ContentScanApi
|
||||
val contentScannerApi: ContentScannerApi
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ internal class DefaultGetServerPublicKeyTask @Inject constructor() : GetServerPu
|
|||
|
||||
override suspend fun execute(params: GetServerPublicKeyTask.Params): String? {
|
||||
return executeRequest<ServerPublicKeyResponse>(null) {
|
||||
params.contentScanApi.getServerPublicKey()
|
||||
params.contentScannerApi.getServerPublicKey()
|
||||
}.publicKey
|
||||
}
|
||||
}
|
|
@ -4,16 +4,16 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.tasks
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.tasks
|
||||
|
||||
import org.matrix.android.sdk.api.failure.toScanFailure
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanState
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScanningApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.data.ContentScanningStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ContentScannerApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ScanEncryptorUtils
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.data.ContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -26,23 +26,23 @@ internal interface ScanEncryptedTask : Task<ScanEncryptedTask.Params, ScanRespon
|
|||
}
|
||||
|
||||
internal class DefaultScanEncryptedTask @Inject constructor(
|
||||
private val contentScanningApiProvider: ContentScanningApiProvider,
|
||||
private val contentScanningStore: ContentScanningStore
|
||||
private val contentScannerApiProvider: ContentScannerApiProvider,
|
||||
private val contentScannerStore: ContentScannerStore
|
||||
) : ScanEncryptedTask {
|
||||
|
||||
override suspend fun execute(params: ScanEncryptedTask.Params): ScanResponse {
|
||||
val mxcUrl = params.mxcUrl
|
||||
val dlBody = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(params.publicServerKey, params.mxcUrl, params.encryptedInfo)
|
||||
|
||||
val scannerUrl = contentScanningStore.getScannerUrl()
|
||||
contentScanningStore.updateStateForContent(params.mxcUrl, ScanState.IN_PROGRESS, scannerUrl)
|
||||
val scannerUrl = contentScannerStore.getScannerUrl()
|
||||
contentScannerStore.updateStateForContent(params.mxcUrl, ScanState.IN_PROGRESS, scannerUrl)
|
||||
|
||||
try {
|
||||
val api = contentScanningApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
val api = contentScannerApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
val executeRequest = executeRequest<ScanResponse>(null) {
|
||||
api.scanFile(dlBody)
|
||||
}
|
||||
contentScanningStore.updateScanResultForContent(
|
||||
contentScannerStore.updateScanResultForContent(
|
||||
mxcUrl,
|
||||
scannerUrl,
|
||||
ScanState.TRUSTED.takeIf { executeRequest.clean } ?: ScanState.INFECTED,
|
||||
|
@ -50,7 +50,7 @@ internal class DefaultScanEncryptedTask @Inject constructor(
|
|||
)
|
||||
return executeRequest
|
||||
} catch (failure: Throwable) {
|
||||
contentScanningStore.updateStateForContent(params.mxcUrl, ScanState.UNKNOWN, scannerUrl)
|
||||
contentScannerStore.updateStateForContent(params.mxcUrl, ScanState.UNKNOWN, scannerUrl)
|
||||
throw failure.toScanFailure() ?: failure
|
||||
}
|
||||
}
|
|
@ -4,14 +4,14 @@
|
|||
* Proprietary and confidential
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.contentscanning.tasks
|
||||
package org.matrix.android.sdk.internal.session.contentscanner.tasks
|
||||
|
||||
import org.matrix.android.sdk.api.failure.toScanFailure
|
||||
import org.matrix.android.sdk.api.session.contentscanning.ScanState
|
||||
import org.matrix.android.sdk.api.session.contentscanner.ScanState
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.ContentScanningApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.data.ContentScanningStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanning.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.ContentScannerApiProvider
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.data.ContentScannerStore
|
||||
import org.matrix.android.sdk.internal.session.contentscanner.model.ScanResponse
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -22,8 +22,8 @@ internal interface ScanMediaTask : Task<ScanMediaTask.Params, ScanResponse> {
|
|||
}
|
||||
|
||||
internal class DefaultScanMediaTask @Inject constructor(
|
||||
private val contentScanningApiProvider: ContentScanningApiProvider,
|
||||
private val contentScanningStore: ContentScanningStore
|
||||
private val contentScannerApiProvider: ContentScannerApiProvider,
|
||||
private val contentScannerStore: ContentScannerStore
|
||||
) : ScanMediaTask {
|
||||
|
||||
override suspend fun execute(params: ScanMediaTask.Params): ScanResponse {
|
||||
|
@ -31,8 +31,8 @@ internal class DefaultScanMediaTask @Inject constructor(
|
|||
if (!params.mxcUrl.startsWith("mxc://")) {
|
||||
throw IllegalAccessException("Invalid mxc url")
|
||||
}
|
||||
val scannerUrl = contentScanningStore.getScannerUrl()
|
||||
contentScanningStore.updateStateForContent(params.mxcUrl, ScanState.IN_PROGRESS, scannerUrl)
|
||||
val scannerUrl = contentScannerStore.getScannerUrl()
|
||||
contentScannerStore.updateStateForContent(params.mxcUrl, ScanState.IN_PROGRESS, scannerUrl)
|
||||
|
||||
var serverAndMediaId = params.mxcUrl.removePrefix("mxc://")
|
||||
val fragmentOffset = serverAndMediaId.indexOf("#")
|
||||
|
@ -47,10 +47,10 @@ internal class DefaultScanMediaTask @Inject constructor(
|
|||
|
||||
try {
|
||||
val scanResponse = executeRequest<ScanResponse>(null) {
|
||||
val api = contentScanningApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
val api = contentScannerApiProvider.contentScannerApi ?: throw IllegalArgumentException()
|
||||
api.scanMedia(split[0], split[1])
|
||||
}
|
||||
contentScanningStore.updateScanResultForContent(
|
||||
contentScannerStore.updateScanResultForContent(
|
||||
params.mxcUrl,
|
||||
scannerUrl,
|
||||
ScanState.TRUSTED.takeIf { scanResponse.clean } ?: ScanState.INFECTED,
|
||||
|
@ -58,7 +58,7 @@ internal class DefaultScanMediaTask @Inject constructor(
|
|||
)
|
||||
return scanResponse
|
||||
} catch (failure: Throwable) {
|
||||
contentScanningStore.updateStateForContent(params.mxcUrl, ScanState.UNKNOWN, scannerUrl)
|
||||
contentScannerStore.updateStateForContent(params.mxcUrl, ScanState.UNKNOWN, scannerUrl)
|
||||
throw failure.toScanFailure() ?: failure
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue