Parse "io.element.disable_network_constraint" from .well-known file.

Migrate DB to 54.
This commit is contained in:
Benoit Marty 2023-10-06 18:03:45 +02:00
parent 60940c01df
commit 842aeb70e0
7 changed files with 48 additions and 1 deletions

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 = false,
) { ) {
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,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()
}
}

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 = false,
) : RealmObject() { ) : RealmObject() {
companion object companion object

View File

@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixPatterns.getServerName import org.matrix.android.sdk.api.MatrixPatterns.getServerName
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult 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.extensions.orTrue
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
import org.matrix.android.sdk.internal.auth.version.Versions import org.matrix.android.sdk.internal.auth.version.Versions
@ -167,6 +168,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.orFalse()
} }
homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult) homeServerCapabilitiesEntity.canLoginWithQrCode = canLoginWithQrCode(getCapabilitiesResult, getVersionResult)