Ensure Boolean io.element.disable_network_constraint is explicitly set in the .well-known file.

This commit is contained in:
Benoit Marty 2023-10-13 09:37:58 +02:00
parent 7884b9dd5e
commit 64a7de5326
4 changed files with 10 additions and 4 deletions

View File

@ -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 {

View File

@ -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()
}
}

View File

@ -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

View File

@ -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
}
}
}