From 7ad3ccfc6024f6be90627686c61ef2056778ca5b Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 5 Jul 2024 17:58:25 +0200 Subject: [PATCH 1/7] Authenticated media : add versions check to HomeServerCapabilities --- .../homeserver/HomeServerCapabilities.kt | 4 +++ .../auth/version/HomeServerVersion.kt | 1 + .../sdk/internal/auth/version/Versions.kt | 10 +++++++ .../database/RealmSessionStoreMigration.kt | 4 ++- .../mapper/HomeServerCapabilitiesMapper.kt | 1 + .../database/migration/MigrateSessionTo055.kt | 30 +++++++++++++++++++ .../model/HomeServerCapabilitiesEntity.kt | 1 + .../GetHomeServerCapabilitiesTask.kt | 3 ++ 8 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt index ecd03288fc..101947f9d9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt @@ -95,6 +95,10 @@ data class HomeServerCapabilities( * If set to true, the SDK will not use the network constraint when configuring Worker for the WorkManager, provided in Wellknown. */ val disableNetworkConstraint: Boolean? = null, + /** + * True if the home server supports authenticated media. + */ + val canUseAuthenticatedMedia: Boolean = false, ) { enum class RoomCapabilitySupport { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/HomeServerVersion.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/HomeServerVersion.kt index d443d6e3c8..f683ae773b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/HomeServerVersion.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/HomeServerVersion.kt @@ -61,5 +61,6 @@ internal data class HomeServerVersion( val r0_6_1 = HomeServerVersion(major = 0, minor = 6, patch = 1) val v1_3_0 = HomeServerVersion(major = 1, minor = 3, patch = 0) val v1_4_0 = HomeServerVersion(major = 1, minor = 4, patch = 0) + val v1_11_0 = HomeServerVersion(major = 1, minor = 11, patch = 0) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/Versions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/Versions.kt index 83186344bb..d819bef584 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/Versions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/version/Versions.kt @@ -54,6 +54,7 @@ private const val FEATURE_ID_ACCESS_TOKEN = "m.id_access_token" private const val FEATURE_SEPARATE_ADD_AND_BIND = "m.separate_add_and_bind" private const val FEATURE_THREADS_MSC3440 = "org.matrix.msc3440" private const val FEATURE_THREADS_MSC3440_STABLE = "org.matrix.msc3440.stable" + @Deprecated("The availability of stable get_login_token is now exposed as a capability and part of login flow") private const val FEATURE_QR_CODE_LOGIN = "org.matrix.msc3882" private const val FEATURE_THREADS_MSC3771 = "org.matrix.msc3771" @@ -142,6 +143,15 @@ internal fun Versions.doesServerSupportLogoutDevices(): Boolean { return getMaxVersion() >= HomeServerVersion.r0_6_1 } +/** + * Indicate if the server supports MSC3916 : https://github.com/matrix-org/matrix-spec-proposals/pull/3916 + * + * @return true if authenticated media is supported + */ +internal fun Versions.doesServerSupportAuthenticatedMedia(): Boolean { + return getMaxVersion() >= HomeServerVersion.v1_11_0 +} + private fun Versions.getMaxVersion(): HomeServerVersion { return supportedVersions ?.mapNotNull { HomeServerVersion.parse(it) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 4a7064ebf5..e02ffc36c5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -71,6 +71,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo051 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo052 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo053 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo054 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo055 import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import javax.inject.Inject @@ -79,7 +80,7 @@ internal class RealmSessionStoreMigration @Inject constructor( private val normalizer: Normalizer ) : MatrixRealmMigration( dbName = "Session", - schemaVersion = 54L, + schemaVersion = 55L, ) { /** * Forces all RealmSessionStoreMigration instances to be equal. @@ -143,5 +144,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 52) MigrateSessionTo052(realm).perform() if (oldVersion < 53) MigrateSessionTo053(realm).perform() if (oldVersion < 54) MigrateSessionTo054(realm).perform() + if (oldVersion < 55) MigrateSessionTo055(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/HomeServerCapabilitiesMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/HomeServerCapabilitiesMapper.kt index 25af5be66d..8cdabaf150 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/HomeServerCapabilitiesMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/HomeServerCapabilitiesMapper.kt @@ -51,6 +51,7 @@ internal object HomeServerCapabilitiesMapper { externalAccountManagementUrl = entity.externalAccountManagementUrl, authenticationIssuer = entity.authenticationIssuer, disableNetworkConstraint = entity.disableNetworkConstraint, + canUseAuthenticatedMedia = entity.canUseAuthenticatedMedia, ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt new file mode 100644 index 0000000000..77e8d7c868 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 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.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields +import org.matrix.android.sdk.internal.extensions.forceRefreshOfHomeServerCapabilities +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo055(realm: DynamicRealm) : RealmMigrator(realm, 54) { + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("HomeServerCapabilitiesEntity") + ?.addField(HomeServerCapabilitiesEntityFields.CAN_USE_AUTHENTICATED_MEDIA, Boolean::class.java) + ?.forceRefreshOfHomeServerCapabilities() + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/HomeServerCapabilitiesEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/HomeServerCapabilitiesEntity.kt index 3891948418..0096071d54 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/HomeServerCapabilitiesEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/HomeServerCapabilitiesEntity.kt @@ -38,6 +38,7 @@ internal open class HomeServerCapabilitiesEntity( var externalAccountManagementUrl: String? = null, var authenticationIssuer: String? = null, var disableNetworkConstraint: Boolean? = null, + var canUseAuthenticatedMedia: Boolean = false, ) : RealmObject() { companion object diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index f007f22366..7a7d140736 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -23,6 +23,7 @@ import org.matrix.android.sdk.api.auth.wellknown.WellknownResult import org.matrix.android.sdk.api.extensions.orTrue import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.internal.auth.version.Versions +import org.matrix.android.sdk.internal.auth.version.doesServerSupportAuthenticatedMedia import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices import org.matrix.android.sdk.internal.auth.version.doesServerSupportQrCodeLogin import org.matrix.android.sdk.internal.auth.version.doesServerSupportRedactionOfRelatedEvents @@ -155,6 +156,8 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( getVersionResult.doesServerSupportRemoteToggleOfPushNotifications() homeServerCapabilitiesEntity.canRedactEventWithRelations = getVersionResult.doesServerSupportRedactionOfRelatedEvents() + homeServerCapabilitiesEntity.canUseAuthenticatedMedia = + getVersionResult.doesServerSupportAuthenticatedMedia() } if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) { From da8c892f7a571a7f18e4108395c6b55f229a6607 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 9 Jul 2024 11:57:55 +0200 Subject: [PATCH 2/7] Authenticated media : makes usage of API when server supports it --- .../matrix/android/sdk/api/session/Session.kt | 5 ++ .../api/session/content/ContentUrlResolver.kt | 2 + .../internal/auth/login/DefaultLoginWizard.kt | 11 ++- .../network/AccessTokenInterceptor.kt | 3 +- .../network/httpclient/OkHttpClientUtil.kt | 9 +++ .../internal/session/DefaultFileService.kt | 23 +++++-- .../sdk/internal/session/DefaultSession.kt | 7 ++ .../content/DefaultContentUrlResolver.kt | 13 +++- .../GetHomeServerCapabilitiesTask.kt | 8 +-- .../session/media/AuthenticatedMediaAPI.kt | 45 ++++++++++++ .../DefaultIsAuthenticatedMediaSupported.kt | 45 ++++++++++++ .../session/media/GetPreviewUrlTask.kt | 4 +- .../session/media/GetRawPreviewUrlTask.kt | 2 +- .../media/IsAuthenticatedMediaSupported.kt | 21 ++++++ .../sdk/internal/session/media/MediaAPI.kt | 27 ++------ .../session/media/MediaAPIProvider.kt | 34 ++++++++++ .../sdk/internal/session/media/MediaModule.kt | 14 +++- .../session/media/UnauthenticatedMediaAPI.kt | 42 ++++++++++++ .../vector/app/core/di/ActiveSessionHolder.kt | 1 - .../im/vector/app/core/di/ImageManager.kt | 11 ++- .../core/glide/AuthenticatedGlideUrlLoader.kt | 68 +++++++++++++++++++ .../im/vector/app/core/glide/FactoryUrl.kt | 38 ----------- ...r.kt => ImageContentRendererDataLoader.kt} | 12 ++-- .../vector/app/core/glide/MyAppGlideModule.kt | 2 +- 24 files changed, 351 insertions(+), 96 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/IsAuthenticatedMediaSupported.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPIProvider.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UnauthenticatedMediaAPI.kt create mode 100644 vector/src/main/java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt delete mode 100644 vector/src/main/java/im/vector/app/core/glide/FactoryUrl.kt rename vector/src/main/java/im/vector/app/core/glide/{VectorGlideModelLoader.kt => ImageContentRendererDataLoader.kt} (91%) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt index cf0f4bdce0..9c94847b22 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt @@ -296,6 +296,11 @@ interface Session { */ fun getOkHttpClient(): OkHttpClient + /** + * Same as [getOkHttpClient] but will add the access token to the request. + */ + fun getAuthenticatedOkHttpClient(): OkHttpClient + /** * A global session listener to get notified for some events. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentUrlResolver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentUrlResolver.kt index 20f977e86e..3dd3712489 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentUrlResolver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentUrlResolver.kt @@ -61,6 +61,8 @@ interface ContentUrlResolver { */ fun resolveThumbnail(contentUrl: String?, width: Int, height: Int, method: ThumbnailMethod): String? + fun requiresAuthentication(resolvedUrl: String): Boolean + sealed class ResolvedMethod { data class GET(val url: String) : ResolvedMethod() data class POST(val url: String, val jsonBody: String) : ResolvedMethod() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt index 86341729ca..45e0fd072c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt @@ -35,6 +35,7 @@ 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.contentscanner.DisabledContentScannerService +import org.matrix.android.sdk.internal.session.media.IsAuthenticatedMediaSupported internal class DefaultLoginWizard( private val authAPI: AuthAPI, @@ -45,8 +46,14 @@ internal class DefaultLoginWizard( private var pendingSessionData: PendingSessionData = pendingSessionStore.getPendingSessionData() ?: error("Pending session data should exist here") private val getProfileTask: GetProfileTask = DefaultGetProfileTask( - authAPI, - DefaultContentUrlResolver(pendingSessionData.homeServerConnectionConfig, DisabledContentScannerService()) + authAPI = authAPI, + contentUrlResolver = DefaultContentUrlResolver( + homeServerConnectionConfig = pendingSessionData.homeServerConnectionConfig, + scannerService = DisabledContentScannerService(), + isAuthenticatedMediaSupported = object : IsAuthenticatedMediaSupported { + override fun invoke() = false + } + ) ) override suspend fun getProfileInfo(matrixId: String): LoginProfileInfo { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/AccessTokenInterceptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/AccessTokenInterceptor.kt index a34606a6bb..fe27cea5ca 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/AccessTokenInterceptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/AccessTokenInterceptor.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.network import okhttp3.Interceptor import okhttp3.Response +import org.matrix.android.sdk.internal.network.httpclient.addAuthenticationHeader import org.matrix.android.sdk.internal.network.token.AccessTokenProvider internal class AccessTokenInterceptor(private val accessTokenProvider: AccessTokenProvider) : Interceptor { @@ -28,7 +29,7 @@ internal class AccessTokenInterceptor(private val accessTokenProvider: AccessTok // Add the access token to all requests if it is set accessTokenProvider.getToken()?.let { token -> val newRequestBuilder = request.newBuilder() - newRequestBuilder.header(HttpHeaders.Authorization, "Bearer $token") + newRequestBuilder.addAuthenticationHeader(token) request = newRequestBuilder.build() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/httpclient/OkHttpClientUtil.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/httpclient/OkHttpClientUtil.kt index 1c395c2d61..aef2e63b2c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/httpclient/OkHttpClientUtil.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/httpclient/OkHttpClientUtil.kt @@ -17,9 +17,11 @@ package org.matrix.android.sdk.internal.network.httpclient import okhttp3.OkHttpClient +import okhttp3.Request import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.internal.network.AccessTokenInterceptor +import org.matrix.android.sdk.internal.network.HttpHeaders import org.matrix.android.sdk.internal.network.interceptors.CurlLoggingInterceptor import org.matrix.android.sdk.internal.network.ssl.CertUtil import org.matrix.android.sdk.internal.network.token.AccessTokenProvider @@ -66,3 +68,10 @@ internal fun OkHttpClient.Builder.applyMatrixConfiguration(matrixConfiguration: return this } + +fun Request.Builder.addAuthenticationHeader(accessToken: String?): Request.Builder { + if (accessToken != null) { + header(HttpHeaders.Authorization, "Bearer $accessToken") + } + return this +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt index bbf260a3f1..217ef43821 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt @@ -34,8 +34,11 @@ import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.api.session.file.FileService import org.matrix.android.sdk.api.util.md5 import org.matrix.android.sdk.internal.crypto.attachments.MXEncryptedAttachments +import org.matrix.android.sdk.internal.di.Authenticated import org.matrix.android.sdk.internal.di.SessionDownloadsDirectory import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificateWithProgress +import org.matrix.android.sdk.internal.network.httpclient.addAuthenticationHeader +import org.matrix.android.sdk.internal.network.token.AccessTokenProvider import org.matrix.android.sdk.internal.session.download.DownloadProgressInterceptor.Companion.DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER import org.matrix.android.sdk.internal.util.file.AtomicFileCreator import org.matrix.android.sdk.internal.util.time.Clock @@ -54,6 +57,7 @@ internal class DefaultFileService @Inject constructor( private val okHttpClient: OkHttpClient, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val clock: Clock, + @Authenticated private val accessTokenProvider: AccessTokenProvider, ) : FileService { // Legacy folder, will be deleted @@ -124,21 +128,26 @@ internal class DefaultFileService @Inject constructor( val cachedFiles = getFiles(url, fileName, mimeType, elementToDecrypt != null) if (!cachedFiles.file.exists()) { - val resolvedUrl = contentUrlResolver.resolveForDownload(url, elementToDecrypt) ?: throw IllegalArgumentException("url is null") + val resolvedMethod = contentUrlResolver.resolveForDownload(url, elementToDecrypt) ?: throw IllegalArgumentException("url is null") - val request = when (resolvedUrl) { + val request = when (resolvedMethod) { is ContentUrlResolver.ResolvedMethod.GET -> { - Request.Builder() - .url(resolvedUrl.url) + val requestBuilder = Request.Builder() + .url(resolvedMethod.url) .header(DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER, url) - .build() + + if (contentUrlResolver.requiresAuthentication(resolvedMethod.url)) { + val accessToken = accessTokenProvider.getToken() + requestBuilder.addAuthenticationHeader(accessToken) + } + requestBuilder.build() } is ContentUrlResolver.ResolvedMethod.POST -> { Request.Builder() - .url(resolvedUrl.url) + .url(resolvedMethod.url) .header(DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER, url) - .post(resolvedUrl.jsonBody.toRequestBody("application/json".toMediaType())) + .post(resolvedMethod.jsonBody.toRequestBody("application/json".toMediaType())) .build() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt index 992ea650cf..b2d5be2946 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt @@ -67,6 +67,7 @@ import org.matrix.android.sdk.api.util.appendParamToUrl import org.matrix.android.sdk.internal.auth.SSO_UIA_FALLBACK_PATH import org.matrix.android.sdk.internal.auth.SessionParamsStore import org.matrix.android.sdk.internal.database.tools.RealmDebugTools +import org.matrix.android.sdk.internal.di.Authenticated import org.matrix.android.sdk.internal.di.ContentScannerDatabase import org.matrix.android.sdk.internal.di.CryptoDatabase import org.matrix.android.sdk.internal.di.IdentityDatabase @@ -131,6 +132,8 @@ internal class DefaultSession @Inject constructor( private val eventStreamService: Lazy, @UnauthenticatedWithCertificate private val unauthenticatedWithCertificateOkHttpClient: Lazy, + @Authenticated + private val authenticatedOkHttpClient: Lazy, private val sessionState: SessionState, ) : Session, GlobalErrorHandler.Listener { @@ -234,6 +237,10 @@ internal class DefaultSession @Inject constructor( return unauthenticatedWithCertificateOkHttpClient.get() } + override fun getAuthenticatedOkHttpClient(): OkHttpClient { + return authenticatedOkHttpClient.get() + } + override fun addListener(listener: Session.Listener) { sessionListeners.addListener(listener) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/DefaultContentUrlResolver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/DefaultContentUrlResolver.kt index ad2b9d0905..dd277f6956 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/DefaultContentUrlResolver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/DefaultContentUrlResolver.kt @@ -25,16 +25,18 @@ import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.internal.network.NetworkConstants 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.session.media.IsAuthenticatedMediaSupported import org.matrix.android.sdk.internal.util.ensureTrailingSlash import javax.inject.Inject internal class DefaultContentUrlResolver @Inject constructor( homeServerConnectionConfig: HomeServerConnectionConfig, - private val scannerService: ContentScannerService + private val scannerService: ContentScannerService, + private val isAuthenticatedMediaSupported: IsAuthenticatedMediaSupported, ) : ContentUrlResolver { private val baseUrl = homeServerConnectionConfig.homeServerUriBase.toString().ensureTrailingSlash() - + private val authenticatedMediaApiPath = baseUrl + NetworkConstants.URI_API_PREFIX_PATH_V1 + "media/" override val uploadUrl = baseUrl + NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "upload" override fun resolveForDownload(contentUrl: String?, elementToDecrypt: ElementToDecrypt?): ContentUrlResolver.ResolvedMethod? { @@ -80,15 +82,20 @@ internal class DefaultContentUrlResolver @Inject constructor( } } + override fun requiresAuthentication(resolvedUrl: String): Boolean { + return resolvedUrl.startsWith(authenticatedMediaApiPath) + } + private fun resolve( contentUrl: String, toThumbnail: Boolean, params: String = "" ): String { var serverAndMediaId = contentUrl.removeMxcPrefix() - val apiPath = if (scannerService.isScannerEnabled()) { NetworkConstants.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE + } else if (isAuthenticatedMediaSupported()) { + NetworkConstants.URI_API_PREFIX_PATH_V1 + "media/" } else { NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index 7a7d140736..5e58443516 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -40,7 +40,8 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult -import org.matrix.android.sdk.internal.session.media.MediaAPI +import org.matrix.android.sdk.internal.session.media.MediaAPIProvider +import org.matrix.android.sdk.internal.session.media.UnauthenticatedMediaAPI import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.wellknown.GetWellknownTask @@ -56,7 +57,7 @@ internal interface GetHomeServerCapabilitiesTask : Task val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm) - doRequest = homeServerCapabilitiesEntity.lastUpdatedTimestamp + MIN_DELAY_BETWEEN_TWO_REQUEST_MILLIS < Date().time } } @@ -88,7 +88,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( val mediaConfig = runCatching { executeRequest(globalErrorReceiver) { - mediaAPI.getMediaConfig() + mediaAPIProvider.getMediaAPI().getMediaConfig() } }.getOrNull() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt new file mode 100644 index 0000000000..baeb309cff --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * 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.media + +import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.internal.network.NetworkConstants +import retrofit2.http.GET +import retrofit2.http.Query + +/** + * Implementation of the media repository API using the new Authenticated media API. + */ +internal interface AuthenticatedMediaAPI : MediaAPI { + /** + * Retrieve the configuration of the content repository + * Ref: https://spec.matrix.org/v1.11/client-server-api/#get_matrixclientv1mediaconfig + */ + @GET(NetworkConstants.URI_API_PREFIX_PATH_V1 + "media/config") + override suspend fun getMediaConfig(): GetMediaConfigResult + + /** + * Get information about a URL for the client. Typically this is called when a client + * sees a URL in a message and wants to render a preview for the user. + * Ref: https://spec.matrix.org/v1.11/client-server-api/#get_matrixclientv1mediapreview_url + * @param url Required. The URL to get a preview of. + * @param ts The preferred point in time to return a preview for. The server may return a newer version + * if it does not have the requested version available. + */ + @GET(NetworkConstants.URI_API_PREFIX_PATH_V1 + "media/preview_url") + override suspend fun getPreviewUrlData(@Query("url") url: String, @Query("ts") ts: Long?): JsonDict +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt new file mode 100644 index 0000000000..f2884c5cf7 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * 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.media + +import com.zhuinden.monarchy.Monarchy +import io.realm.Realm +import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity +import org.matrix.android.sdk.internal.database.query.get +import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.session.SessionScope +import javax.inject.Inject + +@SessionScope +class DefaultIsAuthenticatedMediaSupported @Inject constructor( + @SessionDatabase private val monarchy: Monarchy, +) : IsAuthenticatedMediaSupported { + + private val canUseAuthenticatedMedia: Boolean by lazy { + canUseAuthenticatedMedia() + } + + override fun invoke(): Boolean { + return canUseAuthenticatedMedia + } + + private fun canUseAuthenticatedMedia(): Boolean { + return Realm.getInstance(monarchy.realmConfiguration).use { realm -> + HomeServerCapabilitiesEntity.get(realm)?.canUseAuthenticatedMedia ?: false + } + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt index a31f0d6065..fafd6f2753 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt @@ -41,7 +41,7 @@ internal interface GetPreviewUrlTask : Task { + + private val defaultClient = OkHttpClient() + + override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { + return AuthenticatedGlideUrlLoader(context, defaultClient) + } + + override fun teardown() = Unit +} + +class AuthenticatedGlideUrlLoader( + context: Context, + private val defaultClient: OkHttpClient +) : + ModelLoader { + + private val activeSessionHolder = context.singletonEntryPoint().activeSessionHolder() + private val client: OkHttpClient + get() = activeSessionHolder.getSafeActiveSession() + ?.getAuthenticatedOkHttpClient() + ?: defaultClient + + private val callFactory = Call.Factory { request -> client.newCall(request) } + + override fun handles(model: GlideUrl): Boolean { + if (!activeSessionHolder.hasActiveSession()) return false + val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() + val stringUrl = model.toStringUrl() + return contentUrlResolver.requiresAuthentication(stringUrl) + } + + override fun buildLoadData(model: GlideUrl, width: Int, height: Int, options: Options): ModelLoader.LoadData { + val fetcher = OkHttpStreamFetcher(callFactory, model) + return ModelLoader.LoadData(model, fetcher) + } +} + diff --git a/vector/src/main/java/im/vector/app/core/glide/FactoryUrl.kt b/vector/src/main/java/im/vector/app/core/glide/FactoryUrl.kt deleted file mode 100644 index d52d5814ad..0000000000 --- a/vector/src/main/java/im/vector/app/core/glide/FactoryUrl.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 New Vector Ltd - * - * 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 im.vector.app.core.glide - -import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader -import com.bumptech.glide.load.model.GlideUrl -import com.bumptech.glide.load.model.ModelLoader -import com.bumptech.glide.load.model.ModelLoaderFactory -import com.bumptech.glide.load.model.MultiModelLoaderFactory -import im.vector.app.ActiveSessionDataSource -import okhttp3.OkHttpClient -import java.io.InputStream - -class FactoryUrl(private val activeSessionDataSource: ActiveSessionDataSource) : ModelLoaderFactory { - - override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { - val client = activeSessionDataSource.currentValue?.orNull()?.getOkHttpClient() ?: OkHttpClient() - return OkHttpUrlLoader(client) - } - - override fun teardown() { - // Do nothing, this instance doesn't own the client. - } -} diff --git a/vector/src/main/java/im/vector/app/core/glide/VectorGlideModelLoader.kt b/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt similarity index 91% rename from vector/src/main/java/im/vector/app/core/glide/VectorGlideModelLoader.kt rename to vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt index 92c95d3062..6936a46d57 100644 --- a/vector/src/main/java/im/vector/app/core/glide/VectorGlideModelLoader.kt +++ b/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt @@ -37,10 +37,10 @@ import timber.log.Timber import java.io.IOException import java.io.InputStream -class VectorGlideModelLoaderFactory(private val context: Context) : ModelLoaderFactory { +class ImageContentRendererDataLoaderFactory(private val context: Context) : ModelLoaderFactory { override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { - return VectorGlideModelLoader(context) + return ImageContentRendererDataLoader(context) } override fun teardown() { @@ -48,7 +48,7 @@ class VectorGlideModelLoaderFactory(private val context: Context) : ModelLoaderF } } -class VectorGlideModelLoader(private val context: Context) : +class ImageContentRendererDataLoader(private val context: Context) : ModelLoader { override fun handles(model: ImageContentRenderer.Data): Boolean { // Always handle @@ -56,11 +56,11 @@ class VectorGlideModelLoader(private val context: Context) : } override fun buildLoadData(model: ImageContentRenderer.Data, width: Int, height: Int, options: Options): ModelLoader.LoadData? { - return ModelLoader.LoadData(ObjectKey(model), VectorGlideDataFetcher(context, model, width, height)) + return ModelLoader.LoadData(ObjectKey(model), ImageContentRendererDataFetcher(context, model, width, height)) } } -class VectorGlideDataFetcher( +class ImageContentRendererDataFetcher( context: Context, private val data: ImageContentRenderer.Data, private val width: Int, @@ -71,8 +71,6 @@ class VectorGlideDataFetcher( private val localFilesHelper = LocalFilesHelper(context) private val activeSessionHolder = context.singletonEntryPoint().activeSessionHolder() - private val client = activeSessionHolder.getSafeActiveSession()?.getOkHttpClient() ?: OkHttpClient() - override fun getDataClass(): Class { return InputStream::class.java } diff --git a/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt b/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt index 59bffd95fd..67a79ca8b3 100644 --- a/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt +++ b/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt @@ -38,7 +38,7 @@ class MyAppGlideModule : AppGlideModule() { registry.append( ImageContentRenderer.Data::class.java, InputStream::class.java, - VectorGlideModelLoaderFactory(context) + ImageContentRendererDataLoaderFactory(context) ) registry.append( AvatarPlaceholder::class.java, From fa0860ac0f44a45c137e6d1039267c0c2170a5b6 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 18 Jul 2024 17:52:53 +0200 Subject: [PATCH 3/7] Authenticated media : listen db. --- .../sdk/internal/session/SessionModule.kt | 5 +++ .../DefaultIsAuthenticatedMediaSupported.kt | 34 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt index 54834f4263..d6e1d36b54 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt @@ -83,6 +83,7 @@ import org.matrix.android.sdk.internal.session.events.DefaultEventService import org.matrix.android.sdk.internal.session.homeserver.DefaultHomeServerCapabilitiesService import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManager +import org.matrix.android.sdk.internal.session.media.DefaultIsAuthenticatedMediaSupported import org.matrix.android.sdk.internal.session.openid.DefaultOpenIdService import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor @@ -365,6 +366,10 @@ internal abstract class SessionModule { @IntoSet abstract fun bindEventInsertObserver(observer: EventInsertLiveObserver): SessionLifecycleObserver + @Binds + @IntoSet + abstract fun bindIsMediaAuthenticated(observer: DefaultIsAuthenticatedMediaSupported): SessionLifecycleObserver + @Binds @IntoSet abstract fun bindIntegrationManager(manager: IntegrationManager): SessionLifecycleObserver diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt index f2884c5cf7..e6f09c9353 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt @@ -18,28 +18,44 @@ package org.matrix.android.sdk.internal.session.media import com.zhuinden.monarchy.Monarchy import io.realm.Realm +import io.realm.RealmResults +import org.matrix.android.sdk.internal.database.RealmLiveEntityObserver import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity -import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.session.SessionScope +import timber.log.Timber import javax.inject.Inject @SessionScope -class DefaultIsAuthenticatedMediaSupported @Inject constructor( +internal class DefaultIsAuthenticatedMediaSupported @Inject constructor( @SessionDatabase private val monarchy: Monarchy, -) : IsAuthenticatedMediaSupported { - - private val canUseAuthenticatedMedia: Boolean by lazy { - canUseAuthenticatedMedia() - } +) : + IsAuthenticatedMediaSupported, + RealmLiveEntityObserver(monarchy.realmConfiguration) { override fun invoke(): Boolean { return canUseAuthenticatedMedia } - private fun canUseAuthenticatedMedia(): Boolean { + override val query = Monarchy.Query { + it.where(HomeServerCapabilitiesEntity::class.java) + } + + override fun onChange(results: RealmResults) { + Timber.d("HomeServerCapabilitiesEntity updated.") + canUseAuthenticatedMedia = results.canUseAuthenticatedMedia() + Timber.d("canUseAuthenticatedMedia: $canUseAuthenticatedMedia") + } + + private var canUseAuthenticatedMedia = getInitialValue() + + private fun getInitialValue(): Boolean { return Realm.getInstance(monarchy.realmConfiguration).use { realm -> - HomeServerCapabilitiesEntity.get(realm)?.canUseAuthenticatedMedia ?: false + query.createQuery(realm).findAll().canUseAuthenticatedMedia() } } + + private fun RealmResults.canUseAuthenticatedMedia(): Boolean { + return firstOrNull()?.canUseAuthenticatedMedia ?: false + } } From d10e83bb486eaf030ab89431a8e968f7ac858639 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 19 Jul 2024 10:25:45 +0200 Subject: [PATCH 4/7] Authenticated media : fix formatting. --- .../internal/session/homeserver/GetHomeServerCapabilitiesTask.kt | 1 - .../src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt | 1 - .../java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt | 1 - .../im/vector/app/core/glide/ImageContentRendererDataLoader.kt | 1 - 4 files changed, 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index 5e58443516..2a74cdf198 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -41,7 +41,6 @@ import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult import org.matrix.android.sdk.internal.session.media.MediaAPIProvider -import org.matrix.android.sdk.internal.session.media.UnauthenticatedMediaAPI import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.wellknown.GetWellknownTask diff --git a/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt b/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt index 77135eed23..ca839dff42 100644 --- a/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt +++ b/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt @@ -16,7 +16,6 @@ package im.vector.app.core.di -import android.content.Context import im.vector.app.ActiveSessionDataSource import im.vector.app.core.dispatchers.CoroutineDispatchers import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase diff --git a/vector/src/main/java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt b/vector/src/main/java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt index f56d6e0b60..4b1300b062 100644 --- a/vector/src/main/java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt +++ b/vector/src/main/java/im/vector/app/core/glide/AuthenticatedGlideUrlLoader.kt @@ -65,4 +65,3 @@ class AuthenticatedGlideUrlLoader( return ModelLoader.LoadData(model, fetcher) } } - diff --git a/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt b/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt index 6936a46d57..521eb08385 100644 --- a/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt +++ b/vector/src/main/java/im/vector/app/core/glide/ImageContentRendererDataLoader.kt @@ -32,7 +32,6 @@ import im.vector.app.features.session.coroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import okhttp3.OkHttpClient import timber.log.Timber import java.io.IOException import java.io.InputStream From 669a80e8e4d0a3e470bbb21ef36ab7339f563146 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 19 Jul 2024 12:35:47 +0200 Subject: [PATCH 5/7] Update Realm gradle plugin and Flipper dependencies. --- dependencies.gradle | 2 +- matrix-sdk-android/build.gradle | 2 +- vector-app/build.gradle | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 14077987b2..0f18443f22 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -19,7 +19,7 @@ def markwon = "4.6.2" def moshi = "1.15.1" def lifecycle = "2.8.3" def flowBinding = "1.2.0" -def flipper = "0.190.0" +def flipper = "0.259.0" def epoxy = "5.0.0" def mavericks = "3.0.9" def glide = "4.16.0" diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 5d1a9f1497..78f4a6d179 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -17,7 +17,7 @@ buildscript { } } dependencies { - classpath "io.realm:realm-gradle-plugin:10.16.0" + classpath "io.realm:realm-gradle-plugin:10.18.0" } } diff --git a/vector-app/build.gradle b/vector-app/build.gradle index b22dae7710..157e8eb0ff 100644 --- a/vector-app/build.gradle +++ b/vector-app/build.gradle @@ -399,7 +399,7 @@ dependencies { exclude group: 'com.facebook.fbjni', module: 'fbjni' } debugImplementation 'com.facebook.soloader:soloader:0.10.5' - debugImplementation "com.kgurgul.flipper:flipper-realm-android:2.2.0" + debugImplementation "com.kgurgul.flipper:flipper-realm-android:2.3.0" gplayImplementation "com.google.android.gms:play-services-location:21.3.0" // UnifiedPush gplay flavor only From 497f422b2b6c0ebc62d87115a6691c5956491890 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 19 Jul 2024 12:56:58 +0200 Subject: [PATCH 6/7] Authenticated media : fix pr remarks --- .../GetHomeServerCapabilitiesTask.kt | 23 ++++++++++++------- .../DefaultIsAuthenticatedMediaSupported.kt | 1 - .../session/media/GetRawPreviewUrlTask.kt | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index 2a74cdf198..5314237c3c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy import org.matrix.android.sdk.api.MatrixPatterns.getServerName import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.wellknown.WellknownResult +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orTrue import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.internal.auth.version.Versions @@ -39,8 +40,9 @@ import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor +import org.matrix.android.sdk.internal.session.media.AuthenticatedMediaAPI import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult -import org.matrix.android.sdk.internal.session.media.MediaAPIProvider +import org.matrix.android.sdk.internal.session.media.UnauthenticatedMediaAPI import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.wellknown.GetWellknownTask @@ -56,7 +58,8 @@ internal interface GetHomeServerCapabilitiesTask : Task) { - Timber.d("HomeServerCapabilitiesEntity updated.") canUseAuthenticatedMedia = results.canUseAuthenticatedMedia() Timber.d("canUseAuthenticatedMedia: $canUseAuthenticatedMedia") } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt index 631d2fe6aa..bf0953522b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt @@ -30,13 +30,13 @@ internal interface GetRawPreviewUrlTask : Task Date: Fri, 19 Jul 2024 14:08:23 +0200 Subject: [PATCH 7/7] Fix copyrights. --- .../sdk/internal/database/migration/MigrateSessionTo056.kt | 2 +- .../android/sdk/internal/session/media/AuthenticatedMediaAPI.kt | 2 +- .../session/media/DefaultIsAuthenticatedMediaSupported.kt | 2 +- .../sdk/internal/session/media/IsAuthenticatedMediaSupported.kt | 2 +- .../org/matrix/android/sdk/internal/session/media/MediaAPI.kt | 2 +- .../android/sdk/internal/session/media/MediaAPIProvider.kt | 2 +- .../sdk/internal/session/media/UnauthenticatedMediaAPI.kt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo056.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo056.kt index 258649bf85..dd345b7183 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo056.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo056.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (c) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt index baeb309cff..417d97abba 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/AuthenticatedMediaAPI.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (C) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt index c4ea7fabaf..90b9d1ff88 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/DefaultIsAuthenticatedMediaSupported.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (C) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/IsAuthenticatedMediaSupported.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/IsAuthenticatedMediaSupported.kt index 825f6577fb..f1dad68fe5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/IsAuthenticatedMediaSupported.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/IsAuthenticatedMediaSupported.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (C) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt index abc251797d..7b2e71aee3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (C) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPIProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPIProvider.kt index 45b20165f7..8f8a5e6a5e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPIProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPIProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 New Vector Ltd + * Copyright (C) 2024 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. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UnauthenticatedMediaAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UnauthenticatedMediaAPI.kt index 73dfdcb9c9..66bf784551 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UnauthenticatedMediaAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UnauthenticatedMediaAPI.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Matrix.org Foundation C.I.C. + * Copyright (C) 2024 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.