From 842aeb70e0ae3837cfe0abd5b400696a46021c09 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 6 Oct 2023 18:03:45 +0200 Subject: [PATCH 01/14] Parse "io.element.disable_network_constraint" from .well-known file. Migrate DB to 54. --- .../android/sdk/api/auth/data/WellKnown.kt | 6 ++++ .../homeserver/HomeServerCapabilities.kt | 5 ++++ .../database/RealmSessionStoreMigration.kt | 4 ++- .../mapper/HomeServerCapabilitiesMapper.kt | 1 + .../database/migration/MigrateSessionTo054.kt | 30 +++++++++++++++++++ .../model/HomeServerCapabilitiesEntity.kt | 1 + .../GetHomeServerCapabilitiesTask.kt | 2 ++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/WellKnown.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/WellKnown.kt index 95488bd682..2f5863d1f4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/WellKnown.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/WellKnown.kt @@ -61,4 +61,10 @@ data class WellKnown( */ @Json(name = "org.matrix.msc2965.authentication") val unstableDelegatedAuthConfig: DelegatedAuthConfig? = null, + + /** + * If set to true, the SDK will not use the network constraint when configuring Worker for the WorkManager. + */ + @Json(name = "io.element.disable_network_constraint") + val disableNetworkConstraint: Boolean? = null, ) 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 6b94452e39..a2ea5c4133 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 @@ -90,6 +90,11 @@ data class HomeServerCapabilities( * Authentication issuer for use with MSC3824 delegated OIDC, provided in Wellknown. */ val authenticationIssuer: String? = null, + + /** + * If set to true, the SDK will not use the network constraint when configuring Worker for the WorkManager, provided in Wellknown. + */ + val disableNetworkConstraint: Boolean = false, ) { enum class RoomCapabilitySupport { 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 4376323df4..4a7064ebf5 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 @@ -70,6 +70,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo050 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.util.Normalizer import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import javax.inject.Inject @@ -78,7 +79,7 @@ internal class RealmSessionStoreMigration @Inject constructor( private val normalizer: Normalizer ) : MatrixRealmMigration( dbName = "Session", - schemaVersion = 53L, + schemaVersion = 54L, ) { /** * Forces all RealmSessionStoreMigration instances to be equal. @@ -141,5 +142,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 51) MigrateSessionTo051(realm).perform() if (oldVersion < 52) MigrateSessionTo052(realm).perform() if (oldVersion < 53) MigrateSessionTo053(realm).perform() + if (oldVersion < 54) MigrateSessionTo054(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 f5cf88e2c1..25af5be66d 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 @@ -50,6 +50,7 @@ internal object HomeServerCapabilitiesMapper { canRedactRelatedEvents = entity.canRedactEventWithRelations, externalAccountManagementUrl = entity.externalAccountManagementUrl, authenticationIssuer = entity.authenticationIssuer, + disableNetworkConstraint = entity.disableNetworkConstraint, ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt new file mode 100644 index 0000000000..0b58c8093d --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 MigrateSessionTo054(realm: DynamicRealm) : RealmMigrator(realm, 54) { + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("HomeServerCapabilitiesEntity") + ?.addField(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, 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 79aaf6d4ce..a00dc29087 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 @@ -37,6 +37,7 @@ internal open class HomeServerCapabilitiesEntity( var canRedactEventWithRelations: Boolean = false, var externalAccountManagementUrl: String? = null, var authenticationIssuer: String? = null, + var disableNetworkConstraint: 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 b973de9fd3..05997aeadd 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 @@ -167,6 +168,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( } homeServerCapabilitiesEntity.authenticationIssuer = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.issuer homeServerCapabilitiesEntity.externalAccountManagementUrl = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.accountManagementUrl + homeServerCapabilitiesEntity.disableNetworkConstraint = getWellknownResult.wellKnown.disableNetworkConstraint.orFalse() } homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult) From 2a5e233e2c30b1132988754ea758a58cf18b6c00 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 9 Oct 2023 11:44:40 +0200 Subject: [PATCH 02/14] Do not apply network constraint if "io.element.disable_network_constraint" is set to true in .well-known file. --- .../sdk/internal/di/WorkManagerProvider.kt | 16 ++++++++++------ .../session/pushers/DefaultPushersService.kt | 6 ++++-- .../session/room/send/DefaultSendService.kt | 6 ++++-- .../room/timeline/TimelineSendEventWorkCommon.kt | 6 ++++-- .../internal/session/sync/DefaultSyncService.kt | 16 ++++++++++++++-- .../sdk/internal/session/sync/job/SyncWorker.kt | 10 ++++++++-- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt index d8cdd162f1..e08f120e38 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt @@ -29,7 +29,9 @@ import androidx.work.WorkRequest import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.matrix.android.sdk.api.MatrixCoroutineDispatchers +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.internal.session.SessionScope +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -102,12 +104,14 @@ internal class WorkManagerProvider @Inject constructor( companion object { private const val MATRIX_SDK_TAG_PREFIX = "MatrixSDK-" - /** - * Default constraints: connected network. - */ - val workConstraints = Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .build() + fun getWorkConstraints( + homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + ): Constraints { + val withNetworkConstraint = homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not() + return Constraints.Builder() + .apply { if (withNetworkConstraint) setRequiredNetworkType(NetworkType.CONNECTED) } + .build() + } // Use min value, smaller value will be ignored const val BACKOFF_DELAY_MILLIS = WorkRequest.MIN_BACKOFF_MILLIS diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt index e89cfa508c..0d73d79662 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt @@ -27,6 +27,7 @@ import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.pushers.gateway.PushGatewayNotifyTask import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.task.configureWith @@ -44,7 +45,8 @@ internal class DefaultPushersService @Inject constructor( private val addPusherTask: AddPusherTask, private val togglePusherTask: TogglePusherTask, private val removePusherTask: RemovePusherTask, - private val taskExecutor: TaskExecutor + private val taskExecutor: TaskExecutor, + private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) : PushersService { override suspend fun testPush( @@ -130,7 +132,7 @@ internal class DefaultPushersService @Inject constructor( private fun enqueueAddPusher(pusher: JsonPusher): UUID { val params = AddPusherWorker.Params(sessionId, pusher) val request = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.workConstraints) + .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) .setInputData(WorkerParamsFactory.toData(params)) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .build() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt index 04749103c1..dd2d79741a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt @@ -53,6 +53,7 @@ import org.matrix.android.sdk.internal.crypto.store.IMXCommonCryptoStore import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.content.UploadContentWorker +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.util.CancelableWork @@ -73,7 +74,8 @@ internal class DefaultSendService @AssistedInject constructor( private val taskExecutor: TaskExecutor, private val localEchoRepository: LocalEchoRepository, private val eventSenderProcessor: EventSenderProcessor, - private val cancelSendTracker: CancelSendTracker + private val cancelSendTracker: CancelSendTracker, + private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) : SendService { @AssistedFactory @@ -373,7 +375,7 @@ internal class DefaultSendService @AssistedInject constructor( val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams) return workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.workConstraints) + .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) .startChain(true) .setInputData(uploadWorkData) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt index 21b508d35a..0295a857fe 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt @@ -22,6 +22,7 @@ import androidx.work.ListenableWorker import androidx.work.OneTimeWorkRequest import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.internal.di.WorkManagerProvider +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.worker.startChain import java.util.concurrent.TimeUnit @@ -34,7 +35,8 @@ import javax.inject.Inject * if not the chain will be doomed in failed state. */ internal class TimelineSendEventWorkCommon @Inject constructor( - private val workManagerProvider: WorkManagerProvider + private val workManagerProvider: WorkManagerProvider, + private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) { fun postWork(roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND_OR_REPLACE): Cancelable { @@ -47,7 +49,7 @@ internal class TimelineSendEventWorkCommon @Inject constructor( inline fun createWork(data: Data, startChain: Boolean): OneTimeWorkRequest { return workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.workConstraints) + .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) .startChain(startChain) .setInputData(data) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt index 76c3c38abf..5c3ca5a6b1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt @@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.session.sync.SyncService import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.SessionState +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.job.SyncThread import org.matrix.android.sdk.internal.session.sync.job.SyncWorker import timber.log.Timber @@ -33,15 +34,26 @@ internal class DefaultSyncService @Inject constructor( private val syncTokenStore: SyncTokenStore, private val syncRequestStateTracker: SyncRequestStateTracker, private val sessionState: SessionState, + private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) : SyncService { private var syncThread: SyncThread? = null override fun requireBackgroundSync() { - SyncWorker.requireBackgroundSync(workManagerProvider, sessionId) + SyncWorker.requireBackgroundSync( + workManagerProvider = workManagerProvider, + sessionId = sessionId, + homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + ) } override fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long) { - SyncWorker.automaticallyBackgroundSync(workManagerProvider, sessionId, timeOutInSeconds, repeatDelayInSeconds) + SyncWorker.automaticallyBackgroundSync( + workManagerProvider = workManagerProvider, + sessionId = sessionId, + homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + serverTimeoutInSeconds = timeOutInSeconds, + delayInSeconds = repeatDelayInSeconds, + ) } override fun stopAnyBackgroundSync() { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt index a04bc74628..15002ed43a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt @@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.failure.isTokenError import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.SessionComponent +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.SyncPresence import org.matrix.android.sdk.internal.session.sync.SyncTask import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker @@ -59,6 +60,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, @Inject lateinit var syncTask: SyncTask @Inject lateinit var workManagerProvider: WorkManagerProvider + @Inject lateinit var homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource override fun injectWith(injector: SessionComponent) { injector.inject(this) @@ -77,6 +79,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, automaticallyBackgroundSync( workManagerProvider = workManagerProvider, sessionId = params.sessionId, + homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, serverTimeoutInSeconds = params.timeout, delayInSeconds = params.delay, forceImmediate = hasToDeviceEvents @@ -86,6 +89,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, requireBackgroundSync( workManagerProvider = workManagerProvider, sessionId = params.sessionId, + homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, serverTimeoutInSeconds = 0 ) } @@ -123,6 +127,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, fun requireBackgroundSync( workManagerProvider: WorkManagerProvider, sessionId: String, + homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, serverTimeoutInSeconds: Long = 0 ) { val data = WorkerParamsFactory.toData( @@ -134,7 +139,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, ) ) val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.workConstraints) + .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setInputData(data) .startChain(true) @@ -146,6 +151,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, fun automaticallyBackgroundSync( workManagerProvider: WorkManagerProvider, sessionId: String, + homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, serverTimeoutInSeconds: Long = 0, delayInSeconds: Long = 30, forceImmediate: Boolean = false @@ -160,7 +166,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, ) ) val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.workConstraints) + .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) .setInputData(data) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setInitialDelay(if (forceImmediate) 0 else delayInSeconds, TimeUnit.SECONDS) From f13a15495b14d84d124687cfc9f0b4ff83fe9804 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 9 Oct 2023 12:04:35 +0200 Subject: [PATCH 03/14] Add a log when network constraint is disabled. --- .../android/sdk/internal/di/WorkManagerProvider.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt index e08f120e38..1852f05ce0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory +import timber.log.Timber import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -109,7 +110,13 @@ internal class WorkManagerProvider @Inject constructor( ): Constraints { val withNetworkConstraint = homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not() return Constraints.Builder() - .apply { if (withNetworkConstraint) setRequiredNetworkType(NetworkType.CONNECTED) } + .apply { + if (withNetworkConstraint) { + setRequiredNetworkType(NetworkType.CONNECTED) + } else { + Timber.w("Network constraint is disabled") + } + } .build() } From 747c81c687c7ff5a94ea8c9c36b0f84680d22136 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 10 Oct 2023 10:48:13 +0200 Subject: [PATCH 04/14] Changelog. --- changelog.d/8662.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8662.misc diff --git a/changelog.d/8662.misc b/changelog.d/8662.misc new file mode 100644 index 0000000000..4a18120301 --- /dev/null +++ b/changelog.d/8662.misc @@ -0,0 +1 @@ +Take into account boolean "io.element.disable_network_constraint" from the .well-known file. From 973246819ad89f5062db7658f42e7f49e04f488f Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Tue, 10 Oct 2023 14:11:38 +0200 Subject: [PATCH 05/14] Fix Task :matrix-sdk-android:compileKotlinCryptoDebugUnitTestKotlin FAILED e: file:///home/runner/actions-runner/_work/element-android/element-android/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt:55:5 No value passed for parameter 'homeServerCapabilitiesDataSource' --- .../sdk/internal/session/pushers/DefaultPushersServiceTest.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt index a00ac3a17d..47d3dc2085 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt @@ -21,6 +21,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Test import org.matrix.android.sdk.test.fakes.FakeAddPusherTask import org.matrix.android.sdk.test.fakes.FakeGetPushersTask +import org.matrix.android.sdk.test.fakes.FakeHomeServerCapabilitiesDataSource import org.matrix.android.sdk.test.fakes.FakeMonarchy import org.matrix.android.sdk.test.fakes.FakeRemovePusherTask import org.matrix.android.sdk.test.fakes.FakeTaskExecutor @@ -41,6 +42,7 @@ class DefaultPushersServiceTest { private val togglePusherTask = FakeTogglePusherTask() private val removePusherTask = FakeRemovePusherTask() private val taskExecutor = FakeTaskExecutor() + private val homeServerCapabilitiesDataSource = FakeHomeServerCapabilitiesDataSource() private val pushersService = DefaultPushersService( workManagerProvider.instance, @@ -52,6 +54,7 @@ class DefaultPushersServiceTest { togglePusherTask, removePusherTask, taskExecutor.instance, + homeServerCapabilitiesDataSource.instance, ) @Test From d4c6a46e90d5e1b6f90b2d2e79e063c5ca9754ac Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 12 Oct 2023 18:12:49 +0200 Subject: [PATCH 06/14] Parse "io.element.disable_network_constraint" from login response, to ensure that the config is retrieved. The add pusher worker can be configured before the .well-known config is retrieved. --- .../sdk/api/auth/data/DiscoveryInformation.kt | 8 ++++- .../sdk/internal/di/WorkManagerProvider.kt | 9 +++-- .../sdk/internal/session/SessionModule.kt | 5 +++ .../session/pushers/DefaultPushersService.kt | 6 ++-- .../session/room/send/DefaultSendService.kt | 5 +-- .../timeline/TimelineSendEventWorkCommon.kt | 5 +-- .../session/sync/DefaultSyncService.kt | 7 ++-- .../internal/session/sync/job/SyncWorker.kt | 15 ++++---- .../workmanager/DefaultWorkManagerConfig.kt | 35 +++++++++++++++++++ .../session/workmanager/WorkManagerConfig.kt | 21 +++++++++++ .../pushers/DefaultPushersServiceTest.kt | 6 ++-- .../matrix/android/sdk/test/fakes/FakeWork.kt | 20 +++++++++++ .../sdk/test/fakes/FakeWorkManagerConfig.kt | 25 +++++++++++++ 13 files changed, 141 insertions(+), 26 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/DiscoveryInformation.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/DiscoveryInformation.kt index 384dcdce45..94390e2ffc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/DiscoveryInformation.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/DiscoveryInformation.kt @@ -36,5 +36,11 @@ data class DiscoveryInformation( * Note: matrix.org does not send this field */ @Json(name = "m.identity_server") - val identityServer: WellKnownBaseConfig? = null + val identityServer: WellKnownBaseConfig? = null, + + /** + * If set to true, the SDK will not use the network constraint when configuring Worker for the WorkManager. + */ + @Json(name = "io.element.disable_network_constraint") + val disableNetworkConstraint: Boolean? = null, ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt index 1852f05ce0..1728fe9f69 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt @@ -29,9 +29,8 @@ import androidx.work.WorkRequest import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.matrix.android.sdk.api.MatrixCoroutineDispatchers -import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.internal.session.SessionScope -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory import timber.log.Timber import java.util.concurrent.TimeUnit @@ -106,12 +105,12 @@ internal class WorkManagerProvider @Inject constructor( private const val MATRIX_SDK_TAG_PREFIX = "MatrixSDK-" fun getWorkConstraints( - homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + workManagerConfig: WorkManagerConfig, ): Constraints { - val withNetworkConstraint = homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not() + val widthNetworkConstraint = workManagerConfig.withNetworkConstraint() return Constraints.Builder() .apply { - if (withNetworkConstraint) { + if (widthNetworkConstraint) { setRequiredNetworkType(NetworkType.CONNECTED) } else { Timber.w("Network constraint is disabled") 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 4e778e04cf..54834f4263 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 @@ -97,6 +97,8 @@ import org.matrix.android.sdk.internal.session.room.tombstone.RoomTombstoneEvent import org.matrix.android.sdk.internal.session.typing.DefaultTypingUsersTracker import org.matrix.android.sdk.internal.session.user.accountdata.DefaultSessionAccountDataService import org.matrix.android.sdk.internal.session.widgets.DefaultWidgetURLFormatter +import org.matrix.android.sdk.internal.session.workmanager.DefaultWorkManagerConfig +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import retrofit2.Retrofit import java.io.File import javax.inject.Provider @@ -422,4 +424,7 @@ internal abstract class SessionModule { @Binds abstract fun bindPollAggregationProcessor(processor: DefaultPollAggregationProcessor): PollAggregationProcessor + + @Binds + abstract fun bindWorkManaerConfig(config: DefaultWorkManagerConfig): WorkManagerConfig } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt index 0d73d79662..690a6dd711 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt @@ -27,8 +27,8 @@ import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.pushers.gateway.PushGatewayNotifyTask +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.task.configureWith import org.matrix.android.sdk.internal.worker.WorkerParamsFactory @@ -46,7 +46,7 @@ internal class DefaultPushersService @Inject constructor( private val togglePusherTask: TogglePusherTask, private val removePusherTask: RemovePusherTask, private val taskExecutor: TaskExecutor, - private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + private val workManagerConfig: WorkManagerConfig, ) : PushersService { override suspend fun testPush( @@ -132,7 +132,7 @@ internal class DefaultPushersService @Inject constructor( private fun enqueueAddPusher(pusher: JsonPusher): UUID { val params = AddPusherWorker.Params(sessionId, pusher) val request = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) + .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig)) .setInputData(WorkerParamsFactory.toData(params)) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .build() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt index dd2d79741a..4b2610c033 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt @@ -55,6 +55,7 @@ import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.content.UploadContentWorker import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.worker.WorkerParamsFactory @@ -75,7 +76,7 @@ internal class DefaultSendService @AssistedInject constructor( private val localEchoRepository: LocalEchoRepository, private val eventSenderProcessor: EventSenderProcessor, private val cancelSendTracker: CancelSendTracker, - private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + private val workManagerConfig: WorkManagerConfig, ) : SendService { @AssistedFactory @@ -375,7 +376,7 @@ internal class DefaultSendService @AssistedInject constructor( val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams) return workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) + .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig)) .startChain(true) .setInputData(uploadWorkData) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt index 0295a857fe..ec52cfb2e2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt @@ -23,6 +23,7 @@ import androidx.work.OneTimeWorkRequest import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.worker.startChain import java.util.concurrent.TimeUnit @@ -36,7 +37,7 @@ import javax.inject.Inject */ internal class TimelineSendEventWorkCommon @Inject constructor( private val workManagerProvider: WorkManagerProvider, - private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + private val workManagerConfig: WorkManagerConfig, ) { fun postWork(roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND_OR_REPLACE): Cancelable { @@ -49,7 +50,7 @@ internal class TimelineSendEventWorkCommon @Inject constructor( inline fun createWork(data: Data, startChain: Boolean): OneTimeWorkRequest { return workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) + .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig)) .startChain(startChain) .setInputData(data) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt index 5c3ca5a6b1..280b8e6c21 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt @@ -23,6 +23,7 @@ import org.matrix.android.sdk.internal.session.SessionState import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.job.SyncThread import org.matrix.android.sdk.internal.session.sync.job.SyncWorker +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import timber.log.Timber import javax.inject.Inject import javax.inject.Provider @@ -34,7 +35,7 @@ internal class DefaultSyncService @Inject constructor( private val syncTokenStore: SyncTokenStore, private val syncRequestStateTracker: SyncRequestStateTracker, private val sessionState: SessionState, - private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + private val workManagerConfig: WorkManagerConfig, ) : SyncService { private var syncThread: SyncThread? = null @@ -42,7 +43,7 @@ internal class DefaultSyncService @Inject constructor( SyncWorker.requireBackgroundSync( workManagerProvider = workManagerProvider, sessionId = sessionId, - homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + workManagerConfig = workManagerConfig, ) } @@ -50,7 +51,7 @@ internal class DefaultSyncService @Inject constructor( SyncWorker.automaticallyBackgroundSync( workManagerProvider = workManagerProvider, sessionId = sessionId, - homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + workManagerConfig = workManagerConfig, serverTimeoutInSeconds = timeOutInSeconds, delayInSeconds = repeatDelayInSeconds, ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt index 15002ed43a..7a6b929164 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.SyncPresence import org.matrix.android.sdk.internal.session.sync.SyncTask +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker import org.matrix.android.sdk.internal.worker.SessionWorkerParams import org.matrix.android.sdk.internal.worker.WorkerParamsFactory @@ -60,7 +61,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, @Inject lateinit var syncTask: SyncTask @Inject lateinit var workManagerProvider: WorkManagerProvider - @Inject lateinit var homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource + @Inject lateinit var workManagerConfig: WorkManagerConfig override fun injectWith(injector: SessionComponent) { injector.inject(this) @@ -79,7 +80,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, automaticallyBackgroundSync( workManagerProvider = workManagerProvider, sessionId = params.sessionId, - homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + workManagerConfig = workManagerConfig, serverTimeoutInSeconds = params.timeout, delayInSeconds = params.delay, forceImmediate = hasToDeviceEvents @@ -89,7 +90,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, requireBackgroundSync( workManagerProvider = workManagerProvider, sessionId = params.sessionId, - homeServerCapabilitiesDataSource = homeServerCapabilitiesDataSource, + workManagerConfig = workManagerConfig, serverTimeoutInSeconds = 0 ) } @@ -127,7 +128,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, fun requireBackgroundSync( workManagerProvider: WorkManagerProvider, sessionId: String, - homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + workManagerConfig: WorkManagerConfig, serverTimeoutInSeconds: Long = 0 ) { val data = WorkerParamsFactory.toData( @@ -139,7 +140,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, ) ) val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) + .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig)) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setInputData(data) .startChain(true) @@ -151,7 +152,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, fun automaticallyBackgroundSync( workManagerProvider: WorkManagerProvider, sessionId: String, - homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, + workManagerConfig: WorkManagerConfig, serverTimeoutInSeconds: Long = 0, delayInSeconds: Long = 30, forceImmediate: Boolean = false @@ -166,7 +167,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters, ) ) val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder() - .setConstraints(WorkManagerProvider.getWorkConstraints(homeServerCapabilitiesDataSource)) + .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig)) .setInputData(data) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setInitialDelay(if (forceImmediate) 0 else delayInSeconds, TimeUnit.SECONDS) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt new file mode 100644 index 0000000000..aa3fd718cd --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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.workmanager + +import org.matrix.android.sdk.api.auth.data.Credentials +import org.matrix.android.sdk.api.extensions.orFalse +import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource +import javax.inject.Inject + +internal class DefaultWorkManagerConfig @Inject constructor( + private val credentials: Credentials, + private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, +) : WorkManagerConfig { + override fun withNetworkConstraint(): Boolean { + return if (credentials.discoveryInformation?.disableNetworkConstraint == true) { + false + } else { + homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not() + } + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt new file mode 100644 index 0000000000..6e9f2459ad --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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.workmanager + +internal interface WorkManagerConfig { + fun withNetworkConstraint(): Boolean +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt index 47d3dc2085..5037063833 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersServiceTest.kt @@ -21,11 +21,11 @@ import kotlinx.coroutines.test.runTest import org.junit.Test import org.matrix.android.sdk.test.fakes.FakeAddPusherTask import org.matrix.android.sdk.test.fakes.FakeGetPushersTask -import org.matrix.android.sdk.test.fakes.FakeHomeServerCapabilitiesDataSource import org.matrix.android.sdk.test.fakes.FakeMonarchy import org.matrix.android.sdk.test.fakes.FakeRemovePusherTask import org.matrix.android.sdk.test.fakes.FakeTaskExecutor import org.matrix.android.sdk.test.fakes.FakeTogglePusherTask +import org.matrix.android.sdk.test.fakes.FakeWorkManagerConfig import org.matrix.android.sdk.test.fakes.FakeWorkManagerProvider import org.matrix.android.sdk.test.fakes.internal.FakePushGatewayNotifyTask import org.matrix.android.sdk.test.fixtures.PusherFixture @@ -42,7 +42,7 @@ class DefaultPushersServiceTest { private val togglePusherTask = FakeTogglePusherTask() private val removePusherTask = FakeRemovePusherTask() private val taskExecutor = FakeTaskExecutor() - private val homeServerCapabilitiesDataSource = FakeHomeServerCapabilitiesDataSource() + private val fakeWorkManagerConfig = FakeWorkManagerConfig() private val pushersService = DefaultPushersService( workManagerProvider.instance, @@ -54,7 +54,7 @@ class DefaultPushersServiceTest { togglePusherTask, removePusherTask, taskExecutor.instance, - homeServerCapabilitiesDataSource.instance, + fakeWorkManagerConfig, ) @Test diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt new file mode 100644 index 0000000000..0d1c478663 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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.test.fakes + +class FakeWork { +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt new file mode 100644 index 0000000000..457bf29db0 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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.test.fakes + +import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig + +class FakeWorkManagerConfig : WorkManagerConfig { + override fun withNetworkConstraint(): Boolean { + return true + } +} From 7884b9dd5e3f19eea72631d93c372ab08cac8ffc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 13 Oct 2023 09:26:36 +0200 Subject: [PATCH 07/14] Cleanup --- .../sdk/internal/di/WorkManagerProvider.kt | 4 ++-- .../session/room/send/DefaultSendService.kt | 1 - .../timeline/TimelineSendEventWorkCommon.kt | 1 - .../session/sync/DefaultSyncService.kt | 1 - .../internal/session/sync/job/SyncWorker.kt | 1 - .../matrix/android/sdk/test/fakes/FakeWork.kt | 20 ------------------- 6 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt index 1728fe9f69..fe021e76dd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/WorkManagerProvider.kt @@ -107,10 +107,10 @@ internal class WorkManagerProvider @Inject constructor( fun getWorkConstraints( workManagerConfig: WorkManagerConfig, ): Constraints { - val widthNetworkConstraint = workManagerConfig.withNetworkConstraint() + val withNetworkConstraint = workManagerConfig.withNetworkConstraint() return Constraints.Builder() .apply { - if (widthNetworkConstraint) { + if (withNetworkConstraint) { setRequiredNetworkType(NetworkType.CONNECTED) } else { Timber.w("Network constraint is disabled") diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt index 4b2610c033..0c15573aaa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt @@ -53,7 +53,6 @@ import org.matrix.android.sdk.internal.crypto.store.IMXCommonCryptoStore import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.content.UploadContentWorker -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.task.TaskExecutor diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt index ec52cfb2e2..02c541c83d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineSendEventWorkCommon.kt @@ -22,7 +22,6 @@ import androidx.work.ListenableWorker import androidx.work.OneTimeWorkRequest import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.internal.di.WorkManagerProvider -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.worker.startChain diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt index 280b8e6c21..bca3f55e2f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt @@ -20,7 +20,6 @@ import org.matrix.android.sdk.api.session.sync.SyncService import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.SessionState -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.job.SyncThread import org.matrix.android.sdk.internal.session.sync.job.SyncWorker import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt index 7a6b929164..abee366730 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncWorker.kt @@ -25,7 +25,6 @@ import org.matrix.android.sdk.api.failure.isTokenError import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.SessionComponent -import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import org.matrix.android.sdk.internal.session.sync.SyncPresence import org.matrix.android.sdk.internal.session.sync.SyncTask import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt deleted file mode 100644 index 0d1c478663..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWork.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2023 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.test.fakes - -class FakeWork { -} From 64a7de53261ad6ba6c0bdee6c8c7346aebc3b413 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 13 Oct 2023 09:37:58 +0200 Subject: [PATCH 08/14] Ensure Boolean `io.element.disable_network_constraint` is explicitly set in the .well-known file. --- .../sdk/api/session/homeserver/HomeServerCapabilities.kt | 2 +- .../internal/database/migration/MigrateSessionTo054.kt | 1 + .../database/model/HomeServerCapabilitiesEntity.kt | 2 +- .../session/workmanager/DefaultWorkManagerConfig.kt | 9 +++++++-- 4 files changed, 10 insertions(+), 4 deletions(-) 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 a2ea5c4133..ecd03288fc 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 @@ -94,7 +94,7 @@ 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 = false, + val disableNetworkConstraint: Boolean? = null, ) { enum class RoomCapabilitySupport { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt index 0b58c8093d..19f65153cb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo054.kt @@ -25,6 +25,7 @@ internal class MigrateSessionTo054(realm: DynamicRealm) : RealmMigrator(realm, 5 override fun doMigrate(realm: DynamicRealm) { realm.schema.get("HomeServerCapabilitiesEntity") ?.addField(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, Boolean::class.java) + ?.setNullable(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, true) ?.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 a00dc29087..3891948418 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 @@ -37,7 +37,7 @@ internal open class HomeServerCapabilitiesEntity( var canRedactEventWithRelations: Boolean = false, var externalAccountManagementUrl: String? = null, var authenticationIssuer: String? = null, - var disableNetworkConstraint: Boolean = false, + var disableNetworkConstraint: Boolean? = null, ) : RealmObject() { companion object diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt index aa3fd718cd..159aefc6fd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -17,19 +17,24 @@ package org.matrix.android.sdk.internal.session.workmanager import org.matrix.android.sdk.api.auth.data.Credentials -import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import javax.inject.Inject +@Suppress("RedundantIf") internal class DefaultWorkManagerConfig @Inject constructor( private val credentials: Credentials, private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) : WorkManagerConfig { override fun withNetworkConstraint(): Boolean { return if (credentials.discoveryInformation?.disableNetworkConstraint == true) { + // Boolean `io.element.disable_network_constraint` explicitly set to `true` in the login response + false + } else if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint == true) { + // Boolean `io.element.disable_network_constraint` explicitly set to `true` in the .well-known file false } else { - homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not() + // Default, use the Network constraint + true } } } From 8d95eb7b16375dab3af9dad53adf1c93d59e6c1c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 13 Oct 2023 15:13:48 +0200 Subject: [PATCH 09/14] `disableNetworkConstraint` is now nullable, so do not default the Boolean to false. --- .../session/homeserver/GetHomeServerCapabilitiesTask.kt | 3 +-- 1 file changed, 1 insertion(+), 2 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 05997aeadd..f007f22366 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,7 +20,6 @@ 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 @@ -168,7 +167,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( } homeServerCapabilitiesEntity.authenticationIssuer = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.issuer homeServerCapabilitiesEntity.externalAccountManagementUrl = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.accountManagementUrl - homeServerCapabilitiesEntity.disableNetworkConstraint = getWellknownResult.wellKnown.disableNetworkConstraint.orFalse() + homeServerCapabilitiesEntity.disableNetworkConstraint = getWellknownResult.wellKnown.disableNetworkConstraint } homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult) From 3aa5f34ee7f9c5179b1bf3bf5cd35bb956690c12 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Fri, 13 Oct 2023 15:32:47 +0200 Subject: [PATCH 10/14] Update the NetworkConstraint handling in WorkManager config --- .../session/workmanager/DefaultWorkManagerConfig.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt index 159aefc6fd..aa0b7b48a0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -26,13 +26,16 @@ internal class DefaultWorkManagerConfig @Inject constructor( private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, ) : WorkManagerConfig { override fun withNetworkConstraint(): Boolean { - return if (credentials.discoveryInformation?.disableNetworkConstraint == true) { + val disableNetworkConstraint = homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint + return if (disableNetworkConstraint != null) { + // Boolean `io.element.disable_network_constraint` explicitly set in the .well-known file + disableNetworkConstraint.not() + } + else if (credentials.discoveryInformation?.disableNetworkConstraint == true) { // Boolean `io.element.disable_network_constraint` explicitly set to `true` in the login response false - } else if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint == true) { - // Boolean `io.element.disable_network_constraint` explicitly set to `true` in the .well-known file - false - } else { + } + else { // Default, use the Network constraint true } From 57d224e8ba5649999ac0eb4407c01af4dbd5f323 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Fri, 13 Oct 2023 16:39:05 +0200 Subject: [PATCH 11/14] fix Unexpected newlines --- .../session/workmanager/DefaultWorkManagerConfig.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt index aa0b7b48a0..b37597d1c5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -30,12 +30,10 @@ internal class DefaultWorkManagerConfig @Inject constructor( return if (disableNetworkConstraint != null) { // Boolean `io.element.disable_network_constraint` explicitly set in the .well-known file disableNetworkConstraint.not() - } - else if (credentials.discoveryInformation?.disableNetworkConstraint == true) { + } else if (credentials.discoveryInformation?.disableNetworkConstraint == true) { // Boolean `io.element.disable_network_constraint` explicitly set to `true` in the login response false - } - else { + } else { // Default, use the Network constraint true } From fd07835e45481c2cd94b578953d8a5b53934e3f4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 13 Oct 2023 22:01:46 +0200 Subject: [PATCH 12/14] Fix IDE warning --- .../internal/session/workmanager/DefaultWorkManagerConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt index b37597d1c5..44af0f7f7b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -20,7 +20,7 @@ import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource import javax.inject.Inject -@Suppress("RedundantIf") +@Suppress("RedundantIf", "IfThenToElvis") internal class DefaultWorkManagerConfig @Inject constructor( private val credentials: Credentials, private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource, From 17e9bd200bc1bb6de47e0ab30e3ab6cc39e8174a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 13 Oct 2023 22:02:52 +0200 Subject: [PATCH 13/14] Use Matrix.org copyright. --- .../internal/session/workmanager/DefaultWorkManagerConfig.kt | 2 +- .../sdk/internal/session/workmanager/WorkManagerConfig.kt | 2 +- .../org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt index 44af0f7f7b..804eaeb05c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/DefaultWorkManagerConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 New Vector Ltd + * Copyright (c) 2023 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/workmanager/WorkManagerConfig.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt index 6e9f2459ad..05523a6cb1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/workmanager/WorkManagerConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 New Vector Ltd + * Copyright (c) 2023 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/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt index 457bf29db0..e8b47bc408 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeWorkManagerConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 New Vector Ltd + * Copyright (c) 2023 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. From b14338d2c4b46fdfdadd3035e2b694c1a4970142 Mon Sep 17 00:00:00 2001 From: Yoan Pintas Date: Tue, 7 Nov 2023 14:12:27 +0100 Subject: [PATCH 14/14] Remove unused WebRTC dependency (#8658) --- changelog.d/8658.misc | 1 + vector-app/build.gradle | 2 +- vector/build.gradle | 4 ---- 3 files changed, 2 insertions(+), 5 deletions(-) create mode 100644 changelog.d/8658.misc diff --git a/changelog.d/8658.misc b/changelog.d/8658.misc new file mode 100644 index 0000000000..f4cf3d051d --- /dev/null +++ b/changelog.d/8658.misc @@ -0,0 +1 @@ +Remove unused WebRTC dependency diff --git a/vector-app/build.gradle b/vector-app/build.gradle index ce05b92902..808610510b 100644 --- a/vector-app/build.gradle +++ b/vector-app/build.gradle @@ -309,7 +309,7 @@ android { } } - flavorDimensions "store", "crypto" + flavorDimensions = ["store", "crypto"] productFlavors { gplay { diff --git a/vector/build.gradle b/vector/build.gradle index e45d23a11e..f1ec2b0d32 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -243,10 +243,6 @@ dependencies { implementation "androidx.emoji2:emoji2:1.3.0" - // WebRTC - // org.webrtc:google-webrtc is for development purposes only - // implementation 'org.webrtc:google-webrtc:1.0.+' - implementation('com.facebook.react:react-native-webrtc:111.0.0-jitsi-13672566@aar') // Jitsi api('org.jitsi.react:jitsi-meet-sdk:8.1.1') { exclude group: 'com.google.firebase'