Merge branch 'develop' into feature/bca/clean_up_legacy_crypto

This commit is contained in:
Benoit Marty 2023-11-07 14:13:56 +01:00 committed by GitHub
commit 454ba7bf7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 203 additions and 23 deletions

1
changelog.d/8658.misc Normal file
View File

@ -0,0 +1 @@
Remove unused WebRTC dependency

1
changelog.d/8662.misc Normal file
View File

@ -0,0 +1 @@
Take into account boolean "io.element.disable_network_constraint" from the .well-known file.

View File

@ -36,5 +36,11 @@ data class DiscoveryInformation(
* Note: matrix.org does not send this field * Note: matrix.org does not send this field
*/ */
@Json(name = "m.identity_server") @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,
) )

View File

@ -61,4 +61,10 @@ data class WellKnown(
*/ */
@Json(name = "org.matrix.msc2965.authentication") @Json(name = "org.matrix.msc2965.authentication")
val unstableDelegatedAuthConfig: DelegatedAuthConfig? = null, 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,
) )

View File

@ -90,6 +90,11 @@ data class HomeServerCapabilities(
* Authentication issuer for use with MSC3824 delegated OIDC, provided in Wellknown. * Authentication issuer for use with MSC3824 delegated OIDC, provided in Wellknown.
*/ */
val authenticationIssuer: String? = null, 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? = null,
) { ) {
enum class RoomCapabilitySupport { enum class RoomCapabilitySupport {

View File

@ -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.MigrateSessionTo051
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo052 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.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.Normalizer
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject import javax.inject.Inject
@ -78,7 +79,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
private val normalizer: Normalizer private val normalizer: Normalizer
) : MatrixRealmMigration( ) : MatrixRealmMigration(
dbName = "Session", dbName = "Session",
schemaVersion = 53L, schemaVersion = 54L,
) { ) {
/** /**
* Forces all RealmSessionStoreMigration instances to be equal. * Forces all RealmSessionStoreMigration instances to be equal.
@ -141,5 +142,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldVersion < 51) MigrateSessionTo051(realm).perform() if (oldVersion < 51) MigrateSessionTo051(realm).perform()
if (oldVersion < 52) MigrateSessionTo052(realm).perform() if (oldVersion < 52) MigrateSessionTo052(realm).perform()
if (oldVersion < 53) MigrateSessionTo053(realm).perform() if (oldVersion < 53) MigrateSessionTo053(realm).perform()
if (oldVersion < 54) MigrateSessionTo054(realm).perform()
} }
} }

View File

@ -50,6 +50,7 @@ internal object HomeServerCapabilitiesMapper {
canRedactRelatedEvents = entity.canRedactEventWithRelations, canRedactRelatedEvents = entity.canRedactEventWithRelations,
externalAccountManagementUrl = entity.externalAccountManagementUrl, externalAccountManagementUrl = entity.externalAccountManagementUrl,
authenticationIssuer = entity.authenticationIssuer, authenticationIssuer = entity.authenticationIssuer,
disableNetworkConstraint = entity.disableNetworkConstraint,
) )
} }

View File

@ -0,0 +1,31 @@
/*
* 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)
?.setNullable(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, true)
?.forceRefreshOfHomeServerCapabilities()
}
}

View File

@ -37,6 +37,7 @@ internal open class HomeServerCapabilitiesEntity(
var canRedactEventWithRelations: Boolean = false, var canRedactEventWithRelations: Boolean = false,
var externalAccountManagementUrl: String? = null, var externalAccountManagementUrl: String? = null,
var authenticationIssuer: String? = null, var authenticationIssuer: String? = null,
var disableNetworkConstraint: Boolean? = null,
) : RealmObject() { ) : RealmObject() {
companion object companion object

View File

@ -30,7 +30,9 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.android.sdk.internal.session.SessionScope
import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig
import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory
import timber.log.Timber
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -102,12 +104,20 @@ internal class WorkManagerProvider @Inject constructor(
companion object { companion object {
private const val MATRIX_SDK_TAG_PREFIX = "MatrixSDK-" private const val MATRIX_SDK_TAG_PREFIX = "MatrixSDK-"
/** fun getWorkConstraints(
* Default constraints: connected network. workManagerConfig: WorkManagerConfig,
*/ ): Constraints {
val workConstraints = Constraints.Builder() val withNetworkConstraint = workManagerConfig.withNetworkConstraint()
.setRequiredNetworkType(NetworkType.CONNECTED) return Constraints.Builder()
.build() .apply {
if (withNetworkConstraint) {
setRequiredNetworkType(NetworkType.CONNECTED)
} else {
Timber.w("Network constraint is disabled")
}
}
.build()
}
// Use min value, smaller value will be ignored // Use min value, smaller value will be ignored
const val BACKOFF_DELAY_MILLIS = WorkRequest.MIN_BACKOFF_MILLIS const val BACKOFF_DELAY_MILLIS = WorkRequest.MIN_BACKOFF_MILLIS

View File

@ -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.typing.DefaultTypingUsersTracker
import org.matrix.android.sdk.internal.session.user.accountdata.DefaultSessionAccountDataService 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.widgets.DefaultWidgetURLFormatter
import org.matrix.android.sdk.internal.session.workmanager.DefaultWorkManagerConfig
import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig
import retrofit2.Retrofit import retrofit2.Retrofit
import java.io.File import java.io.File
import javax.inject.Provider import javax.inject.Provider
@ -422,4 +424,7 @@ internal abstract class SessionModule {
@Binds @Binds
abstract fun bindPollAggregationProcessor(processor: DefaultPollAggregationProcessor): PollAggregationProcessor abstract fun bindPollAggregationProcessor(processor: DefaultPollAggregationProcessor): PollAggregationProcessor
@Binds
abstract fun bindWorkManaerConfig(config: DefaultWorkManagerConfig): WorkManagerConfig
} }

View File

@ -167,6 +167,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
} }
homeServerCapabilitiesEntity.authenticationIssuer = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.issuer homeServerCapabilitiesEntity.authenticationIssuer = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.issuer
homeServerCapabilitiesEntity.externalAccountManagementUrl = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.accountManagementUrl homeServerCapabilitiesEntity.externalAccountManagementUrl = getWellknownResult.wellKnown.unstableDelegatedAuthConfig?.accountManagementUrl
homeServerCapabilitiesEntity.disableNetworkConstraint = getWellknownResult.wellKnown.disableNetworkConstraint
} }
homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult) homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult)

View File

@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.session.pushers.gateway.PushGatewayNotifyTask 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.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith import org.matrix.android.sdk.internal.task.configureWith
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
@ -44,7 +45,8 @@ internal class DefaultPushersService @Inject constructor(
private val addPusherTask: AddPusherTask, private val addPusherTask: AddPusherTask,
private val togglePusherTask: TogglePusherTask, private val togglePusherTask: TogglePusherTask,
private val removePusherTask: RemovePusherTask, private val removePusherTask: RemovePusherTask,
private val taskExecutor: TaskExecutor private val taskExecutor: TaskExecutor,
private val workManagerConfig: WorkManagerConfig,
) : PushersService { ) : PushersService {
override suspend fun testPush( override suspend fun testPush(
@ -130,7 +132,7 @@ internal class DefaultPushersService @Inject constructor(
private fun enqueueAddPusher(pusher: JsonPusher): UUID { private fun enqueueAddPusher(pusher: JsonPusher): UUID {
val params = AddPusherWorker.Params(sessionId, pusher) val params = AddPusherWorker.Params(sessionId, pusher)
val request = workManagerProvider.matrixOneTimeWorkRequestBuilder<AddPusherWorker>() val request = workManagerProvider.matrixOneTimeWorkRequestBuilder<AddPusherWorker>()
.setConstraints(WorkManagerProvider.workConstraints) .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig))
.setInputData(WorkerParamsFactory.toData(params)) .setInputData(WorkerParamsFactory.toData(params))
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
.build() .build()

View File

@ -54,6 +54,7 @@ import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.session.content.UploadContentWorker import org.matrix.android.sdk.internal.session.content.UploadContentWorker
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor 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.task.TaskExecutor
import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.util.CancelableWork
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
@ -73,7 +74,8 @@ internal class DefaultSendService @AssistedInject constructor(
private val taskExecutor: TaskExecutor, private val taskExecutor: TaskExecutor,
private val localEchoRepository: LocalEchoRepository, private val localEchoRepository: LocalEchoRepository,
private val eventSenderProcessor: EventSenderProcessor, private val eventSenderProcessor: EventSenderProcessor,
private val cancelSendTracker: CancelSendTracker private val cancelSendTracker: CancelSendTracker,
private val workManagerConfig: WorkManagerConfig,
) : SendService { ) : SendService {
@AssistedFactory @AssistedFactory
@ -373,7 +375,7 @@ internal class DefaultSendService @AssistedInject constructor(
val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams) val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams)
return workManagerProvider.matrixOneTimeWorkRequestBuilder<UploadContentWorker>() return workManagerProvider.matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
.setConstraints(WorkManagerProvider.workConstraints) .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig))
.startChain(true) .startChain(true)
.setInputData(uploadWorkData) .setInputData(uploadWorkData)
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)

View File

@ -22,6 +22,7 @@ import androidx.work.ListenableWorker
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig
import org.matrix.android.sdk.internal.util.CancelableWork import org.matrix.android.sdk.internal.util.CancelableWork
import org.matrix.android.sdk.internal.worker.startChain import org.matrix.android.sdk.internal.worker.startChain
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -34,7 +35,8 @@ import javax.inject.Inject
* if not the chain will be doomed in failed state. * if not the chain will be doomed in failed state.
*/ */
internal class TimelineSendEventWorkCommon @Inject constructor( internal class TimelineSendEventWorkCommon @Inject constructor(
private val workManagerProvider: WorkManagerProvider private val workManagerProvider: WorkManagerProvider,
private val workManagerConfig: WorkManagerConfig,
) { ) {
fun postWork(roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND_OR_REPLACE): Cancelable { fun postWork(roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND_OR_REPLACE): Cancelable {
@ -47,7 +49,7 @@ internal class TimelineSendEventWorkCommon @Inject constructor(
inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest { inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest {
return workManagerProvider.matrixOneTimeWorkRequestBuilder<W>() return workManagerProvider.matrixOneTimeWorkRequestBuilder<W>()
.setConstraints(WorkManagerProvider.workConstraints) .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig))
.startChain(startChain) .startChain(startChain)
.setInputData(data) .setInputData(data)
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)

View File

@ -22,6 +22,7 @@ import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.session.SessionState import org.matrix.android.sdk.internal.session.SessionState
import org.matrix.android.sdk.internal.session.sync.job.SyncThread 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.sync.job.SyncWorker
import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Provider import javax.inject.Provider
@ -33,15 +34,26 @@ internal class DefaultSyncService @Inject constructor(
private val syncTokenStore: SyncTokenStore, private val syncTokenStore: SyncTokenStore,
private val syncRequestStateTracker: SyncRequestStateTracker, private val syncRequestStateTracker: SyncRequestStateTracker,
private val sessionState: SessionState, private val sessionState: SessionState,
private val workManagerConfig: WorkManagerConfig,
) : SyncService { ) : SyncService {
private var syncThread: SyncThread? = null private var syncThread: SyncThread? = null
override fun requireBackgroundSync() { override fun requireBackgroundSync() {
SyncWorker.requireBackgroundSync(workManagerProvider, sessionId) SyncWorker.requireBackgroundSync(
workManagerProvider = workManagerProvider,
sessionId = sessionId,
workManagerConfig = workManagerConfig,
)
} }
override fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long) { override fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long) {
SyncWorker.automaticallyBackgroundSync(workManagerProvider, sessionId, timeOutInSeconds, repeatDelayInSeconds) SyncWorker.automaticallyBackgroundSync(
workManagerProvider = workManagerProvider,
sessionId = sessionId,
workManagerConfig = workManagerConfig,
serverTimeoutInSeconds = timeOutInSeconds,
delayInSeconds = repeatDelayInSeconds,
)
} }
override fun stopAnyBackgroundSync() { override fun stopAnyBackgroundSync() {

View File

@ -27,6 +27,7 @@ import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.session.sync.SyncPresence 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.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.SessionSafeCoroutineWorker
import org.matrix.android.sdk.internal.worker.SessionWorkerParams import org.matrix.android.sdk.internal.worker.SessionWorkerParams
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
@ -59,6 +60,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
@Inject lateinit var syncTask: SyncTask @Inject lateinit var syncTask: SyncTask
@Inject lateinit var workManagerProvider: WorkManagerProvider @Inject lateinit var workManagerProvider: WorkManagerProvider
@Inject lateinit var workManagerConfig: WorkManagerConfig
override fun injectWith(injector: SessionComponent) { override fun injectWith(injector: SessionComponent) {
injector.inject(this) injector.inject(this)
@ -77,6 +79,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
automaticallyBackgroundSync( automaticallyBackgroundSync(
workManagerProvider = workManagerProvider, workManagerProvider = workManagerProvider,
sessionId = params.sessionId, sessionId = params.sessionId,
workManagerConfig = workManagerConfig,
serverTimeoutInSeconds = params.timeout, serverTimeoutInSeconds = params.timeout,
delayInSeconds = params.delay, delayInSeconds = params.delay,
forceImmediate = hasToDeviceEvents forceImmediate = hasToDeviceEvents
@ -86,6 +89,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
requireBackgroundSync( requireBackgroundSync(
workManagerProvider = workManagerProvider, workManagerProvider = workManagerProvider,
sessionId = params.sessionId, sessionId = params.sessionId,
workManagerConfig = workManagerConfig,
serverTimeoutInSeconds = 0 serverTimeoutInSeconds = 0
) )
} }
@ -123,6 +127,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
fun requireBackgroundSync( fun requireBackgroundSync(
workManagerProvider: WorkManagerProvider, workManagerProvider: WorkManagerProvider,
sessionId: String, sessionId: String,
workManagerConfig: WorkManagerConfig,
serverTimeoutInSeconds: Long = 0 serverTimeoutInSeconds: Long = 0
) { ) {
val data = WorkerParamsFactory.toData( val data = WorkerParamsFactory.toData(
@ -134,7 +139,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
) )
) )
val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<SyncWorker>() val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<SyncWorker>()
.setConstraints(WorkManagerProvider.workConstraints) .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig))
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
.setInputData(data) .setInputData(data)
.startChain(true) .startChain(true)
@ -146,6 +151,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
fun automaticallyBackgroundSync( fun automaticallyBackgroundSync(
workManagerProvider: WorkManagerProvider, workManagerProvider: WorkManagerProvider,
sessionId: String, sessionId: String,
workManagerConfig: WorkManagerConfig,
serverTimeoutInSeconds: Long = 0, serverTimeoutInSeconds: Long = 0,
delayInSeconds: Long = 30, delayInSeconds: Long = 30,
forceImmediate: Boolean = false forceImmediate: Boolean = false
@ -160,7 +166,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
) )
) )
val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<SyncWorker>() val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<SyncWorker>()
.setConstraints(WorkManagerProvider.workConstraints) .setConstraints(WorkManagerProvider.getWorkConstraints(workManagerConfig))
.setInputData(data) .setInputData(data)
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
.setInitialDelay(if (forceImmediate) 0 else delayInSeconds, TimeUnit.SECONDS) .setInitialDelay(if (forceImmediate) 0 else delayInSeconds, TimeUnit.SECONDS)

View File

@ -0,0 +1,41 @@
/*
* 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.session.workmanager
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource
import javax.inject.Inject
@Suppress("RedundantIf", "IfThenToElvis")
internal class DefaultWorkManagerConfig @Inject constructor(
private val credentials: Credentials,
private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource,
) : WorkManagerConfig {
override fun withNetworkConstraint(): Boolean {
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 {
// Default, use the Network constraint
true
}
}
}

View File

@ -0,0 +1,21 @@
/*
* 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.session.workmanager
internal interface WorkManagerConfig {
fun withNetworkConstraint(): Boolean
}

View File

@ -25,6 +25,7 @@ import org.matrix.android.sdk.test.fakes.FakeMonarchy
import org.matrix.android.sdk.test.fakes.FakeRemovePusherTask import org.matrix.android.sdk.test.fakes.FakeRemovePusherTask
import org.matrix.android.sdk.test.fakes.FakeTaskExecutor import org.matrix.android.sdk.test.fakes.FakeTaskExecutor
import org.matrix.android.sdk.test.fakes.FakeTogglePusherTask 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.FakeWorkManagerProvider
import org.matrix.android.sdk.test.fakes.internal.FakePushGatewayNotifyTask import org.matrix.android.sdk.test.fakes.internal.FakePushGatewayNotifyTask
import org.matrix.android.sdk.test.fixtures.PusherFixture import org.matrix.android.sdk.test.fixtures.PusherFixture
@ -41,6 +42,7 @@ class DefaultPushersServiceTest {
private val togglePusherTask = FakeTogglePusherTask() private val togglePusherTask = FakeTogglePusherTask()
private val removePusherTask = FakeRemovePusherTask() private val removePusherTask = FakeRemovePusherTask()
private val taskExecutor = FakeTaskExecutor() private val taskExecutor = FakeTaskExecutor()
private val fakeWorkManagerConfig = FakeWorkManagerConfig()
private val pushersService = DefaultPushersService( private val pushersService = DefaultPushersService(
workManagerProvider.instance, workManagerProvider.instance,
@ -52,6 +54,7 @@ class DefaultPushersServiceTest {
togglePusherTask, togglePusherTask,
removePusherTask, removePusherTask,
taskExecutor.instance, taskExecutor.instance,
fakeWorkManagerConfig,
) )
@Test @Test

View File

@ -0,0 +1,25 @@
/*
* 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.test.fakes
import org.matrix.android.sdk.internal.session.workmanager.WorkManagerConfig
class FakeWorkManagerConfig : WorkManagerConfig {
override fun withNetworkConstraint(): Boolean {
return true
}
}

View File

@ -307,7 +307,7 @@ android {
} }
} }
flavorDimensions "store" flavorDimensions = ["store"]
productFlavors { productFlavors {
gplay { gplay {

View File

@ -241,10 +241,6 @@ dependencies {
implementation "androidx.emoji2:emoji2:1.3.0" 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 // Jitsi
api('org.jitsi.react:jitsi-meet-sdk:8.1.1') { api('org.jitsi.react:jitsi-meet-sdk:8.1.1') {
exclude group: 'com.google.firebase' exclude group: 'com.google.firebase'