Move the :libraries:wellknown logic into enterprise modules (#7429)

* Extract `IsEnterpriseBuild` use case

Having it inside `EnterpriseService` made having DI cycles with the `BuildMeta` provider too easy

* Rename `EnterpriseService.defaultHomeserverList()` to `homeserverAllowList()`

This seems more aligned with the way this list works

* Move most of the logic from `:libraries:wellknown` to `:enterprise:feature:enterprise`, both `shared` and `impl` modules

Ideally I would have added everything into `impl`, but some of the classes needed to be shared between the different `:enterprise:features` modules, and those are in the `shared` module, lacking a better name/strategy

* Add `EnterpriseService.isElementProEnforced`

With this, we don't need to provide the `RemoteEnterpriseConfig` anymore to any consumers, everything goes through `EnterpriseService` or other providers

* Remove `EnterpriseService.overriddenElementWellKnown`

This leaks the remote enterprise config/element well known contents to the app in a public interface.

* Create `CustomMapTilerConfigProvider` to avoid leaking the `RemoteEnterpriseConfig` in public APIs

This commit also starts moving some of the well-known related values to the enterprise modules

* Add missing docs to `EnterpriseService` and `SessionEnterpriseService`

* Fix tests

* Fix lint issues

* Bump enterprise module
This commit is contained in:
Jorge Martin Espinosa
2026-08-17 15:21:47 +02:00
committed by GitHub
parent f94566e44f
commit 8b2c207728
72 changed files with 246 additions and 1607 deletions
@@ -1,53 +0,0 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.features.wellknown.test
import io.element.android.libraries.androidutils.json.DefaultJsonProvider
import io.element.android.libraries.androidutils.json.JsonProvider
import io.element.android.libraries.wellknown.api.ElementWellKnown
import io.element.android.libraries.wellknown.api.ElementWellknownStore
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
import io.element.android.libraries.wellknown.impl.InternalElementWellKnown
import io.element.android.libraries.wellknown.impl.map
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.JsonDecodingException
import java.net.URL
class FakeElementWellknownStore(
initialData: Map<String, WellknownRetrieverResult<ElementWellKnown>> = emptyMap(),
private val jsonProvider: JsonProvider = DefaultJsonProvider(),
) : ElementWellknownStore {
private val cachedData = mutableMapOf<String, WellknownRetrieverResult<ElementWellKnown>>()
init {
initialData.forEach { (url, result) ->
cachedData[URL(url).host] = result
}
}
override suspend fun get(domain: String): WellknownRetrieverResult<ElementWellKnown> {
return cachedData[domain] ?: WellknownRetrieverResult.NotFound
}
@OptIn(ExperimentalSerializationApi::class)
override suspend fun update(domain: String, wellknown: String): Result<Unit> {
val json = jsonProvider()
val mapped = try {
json.decodeFromString<InternalElementWellKnown>(wellknown).map()
} catch (e: JsonDecodingException) {
return Result.failure(e)
}
cachedData[domain] = WellknownRetrieverResult.Success(mapped)
return Result.success(Unit)
}
override suspend fun delete(domain: String): Result<Unit> {
cachedData.remove(domain)
return Result.success(Unit)
}
}
@@ -1,24 +0,0 @@
/*
* Copyright (c) 2025 Element Creations Ltd.
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.features.wellknown.test
import io.element.android.libraries.wellknown.api.ElementWellKnown
import io.element.android.libraries.wellknown.api.EnterpriseRemoteConfigSource
import io.element.android.libraries.wellknown.api.WellknownRetriever
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
class FakeWellknownRetriever(
private val getElementWellKnownResult: (String, EnterpriseRemoteConfigSource) -> WellknownRetrieverResult<ElementWellKnown> = { _, _ ->
WellknownRetrieverResult.NotFound
},
) : WellknownRetriever {
override suspend fun getElementWellKnown(host: String, source: EnterpriseRemoteConfigSource): WellknownRetrieverResult<ElementWellKnown> {
return getElementWellKnownResult(host, source)
}
}
@@ -1,17 +0,0 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.features.wellknown.test
import io.element.android.libraries.matrix.api.UrlContentFetcher
import io.element.android.libraries.wellknown.api.WellknownRetriever
class FakeWellknownRetrieverFactory(
private val wellknownRetriever: WellknownRetriever = FakeWellknownRetriever(),
) : WellknownRetriever.Factory {
override fun create(urlContentFetcher: UrlContentFetcher): WellknownRetriever = wellknownRetriever
}
@@ -1,55 +0,0 @@
/*
* Copyright (c) 2025 Element Creations Ltd.
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.features.wellknown.test
import io.element.android.libraries.wellknown.api.CustomRecoveryPassphrase
import io.element.android.libraries.wellknown.api.ElementWellKnown
import io.element.android.libraries.wellknown.api.MapTilerConfig
fun anElementWellKnown(
registrationHelperUrl: String? = null,
enforceElementPro: Boolean? = null,
rageshakeUrl: String? = null,
brandColor: String? = null,
notificationSound: String? = null,
identityProviderAppScheme: String? = null,
customRecoveryPassphrase: CustomRecoveryPassphrase? = null,
contentScannerUrl: String? = null,
forceDisableE2EE: Boolean? = null,
mapTilerConfig: MapTilerConfig? = null,
) = ElementWellKnown(
registrationHelperUrl = registrationHelperUrl,
enforceElementPro = enforceElementPro,
rageshakeUrl = rageshakeUrl,
brandColor = brandColor,
notificationSound = notificationSound,
identityProviderAppScheme = identityProviderAppScheme,
customRecoveryPassphrase = customRecoveryPassphrase,
contentScannerUrl = contentScannerUrl,
forceDisableE2EE = forceDisableE2EE,
mapTilerConfig = mapTilerConfig,
)
fun aCustomRecoveryPassphrase(
minCharacterCount: Int = 8,
) = CustomRecoveryPassphrase(
minCharacterCount = minCharacterCount,
)
fun aMapTilerConfig(
apiKey: String = "test_api_key",
baseUrl: String? = null,
lightStyleId: String? = null,
darkStyleId: String? = null,
) = MapTilerConfig(
apiKey = apiKey,
baseUrl = baseUrl,
lightStyleId = lightStyleId,
darkStyleId = darkStyleId,
)