From 43a13646717b408d7bf2edd6545b2ded5396a933 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 22 Sep 2026 21:04:04 +0200 Subject: [PATCH] Give the native call component its view of Matrix The factory lives in libraries/matrix/impl because that is the only module compiled against the Rust SDK, and is app-scoped because a call is started for whichever account it belongs to rather than the one on screen. Co-Authored-By: Claude Opus 5 (1M context) --- features/callnative/api/build.gradle.kts | 12 +++++- .../api/ElementCallTransportFactory.kt | 26 +++++++++++++ libraries/matrix/impl/build.gradle.kts | 35 ++++++++++++++++- .../di/DefaultElementCallTransportFactory.kt | 38 +++++++++++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 features/callnative/api/src/main/kotlin/io/element/android/features/callnative/api/ElementCallTransportFactory.kt create mode 100644 libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/di/DefaultElementCallTransportFactory.kt diff --git a/features/callnative/api/build.gradle.kts b/features/callnative/api/build.gradle.kts index 73c478ccb6..81e5976627 100644 --- a/features/callnative/api/build.gradle.kts +++ b/features/callnative/api/build.gradle.kts @@ -13,8 +13,18 @@ android { namespace = "io.element.android.features.callnative.api" } +// Temporary: `-PelementCallLocalVersion` points this at a locally published build of +// element-call-android. Goes with the repositories in settings.gradle.kts. +val elementCallVersion: String = providers.gradleProperty("elementCallLocalVersion") + .getOrElse(libs.versions.element.call.get()) + dependencies { - // api, not implementation: CallData is part of NativeCallEntryPoint's signature. + // api, not implementation: ElementCallMatrixTransport is part of ElementCallTransportFactory's + // signature, and CallData of NativeCallEntryPoint's. + // api, so that consumers of this module inherit the versions the BOM pins - the artifact + // below is declared without one. + api(platform("io.element.android:element-call-bom:$elementCallVersion")) + api(libs.element.call.api) api(projects.features.call.api) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix.api) diff --git a/features/callnative/api/src/main/kotlin/io/element/android/features/callnative/api/ElementCallTransportFactory.kt b/features/callnative/api/src/main/kotlin/io/element/android/features/callnative/api/ElementCallTransportFactory.kt new file mode 100644 index 0000000000..bda31738f0 --- /dev/null +++ b/features/callnative/api/src/main/kotlin/io/element/android/features/callnative/api/ElementCallTransportFactory.kt @@ -0,0 +1,26 @@ +/* + * 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.callnative.api + +import io.element.android.call.api.matrix.ElementCallMatrixTransport +import io.element.android.libraries.matrix.api.MatrixClient + +/** + * Makes the native call's view of Matrix for a session. + * + * The component's turnkey transport is built over a raw Rust SDK client, and only + * `libraries/matrix/impl` is compiled against the SDK. This is the seam that keeps it that way: the + * implementation lives there, everything else takes a [MatrixClient] and asks. + * + * A factory rather than a binding for the transport itself, because the call is started from app scope + * - a call can be placed for an account that is not the one on screen - and the session it belongs to + * is known only as an id until a client is fetched for it. + */ +fun interface ElementCallTransportFactory { + fun create(client: MatrixClient): ElementCallMatrixTransport +} diff --git a/libraries/matrix/impl/build.gradle.kts b/libraries/matrix/impl/build.gradle.kts index 13920980a2..6ef7891e10 100644 --- a/libraries/matrix/impl/build.gradle.kts +++ b/libraries/matrix/impl/build.gradle.kts @@ -20,16 +20,47 @@ android { setupDependencyInjection() +// Temporary: `-PelementCallLocalVersion` points this at a locally published build of +// element-call-android, because the library has no remote repository yet. Goes with the mavenLocal +// block in settings.gradle.kts. Only the BOM carries a version; every other artifact follows it. +val elementCallVersion: String = providers.gradleProperty("elementCallLocalVersion") + .getOrElse(libs.versions.element.call.get()) + +val usesLocalRustSdk = file("${rootDir.path}/libraries/rustsdk/matrix-rust-sdk.aar").exists() + +if (usesLocalRustSdk) { + // element-call-matrix declares the Rust SDK as an ordinary Maven dependency, so with the local + // AAR in place a debug classpath would carry two copies of org.matrix.rustcomponents.sdk. + // Point the library's dependency at the same local AAR the app is using. + configurations.matching { it.name.startsWith("debug") }.configureEach { + resolutionStrategy.dependencySubstitution { + substitute(module("org.matrix.rustcomponents:sdk-android")) + .using(project(":libraries:rustsdk")) + .because("the local Rust SDK AAR replaces the published one on debug builds") + } + } +} + dependencies { releaseImplementation(libs.matrix.sdk) - if (file("${rootDir.path}/libraries/rustsdk/matrix-rust-sdk.aar").exists()) { - println("\nNote: Using local binary of the Rust SDK.\n") + if (usesLocalRustSdk) { + println( + "\nNote: Using local binary of the Rust SDK." + + "\n element-call-matrix is substituted onto it as well, so the native call runs" + + "\n against this SDK rather than the one it was published against.\n" + ) debugImplementation(projects.libraries.rustsdk) } else { debugImplementation(libs.matrix.sdk) } implementation(variantOf(libs.rustls.platform.verifier) { artifactType("aar") }) + // The native call's Matrix transport. Only this module may hand it a raw SDK client. + implementation(platform("io.element.android:element-call-bom:$elementCallVersion")) + implementation(libs.element.call.api) + implementation(projects.features.callnative.api) + implementation(libs.element.call.matrix) + implementation(projects.appconfig) implementation(projects.features.enterprise.api) implementation(projects.libraries.androidutils) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/di/DefaultElementCallTransportFactory.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/di/DefaultElementCallTransportFactory.kt new file mode 100644 index 0000000000..14b59b14e6 --- /dev/null +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/di/DefaultElementCallTransportFactory.kt @@ -0,0 +1,38 @@ +/* + * 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.libraries.matrix.impl.di + +import dev.zacsweers.metro.AppScope +import dev.zacsweers.metro.ContributesBinding +import io.element.android.call.api.matrix.ElementCallMatrixTransport +import io.element.android.call.matrix.ElementCallSdkTransport +import io.element.android.features.callnative.api.ElementCallTransportFactory +import io.element.android.libraries.matrix.api.MatrixClient +import io.element.android.libraries.matrix.impl.RustMatrixClient + +/** + * Gives the native call component its view of Matrix. + * + * Here because this is the only module in the app compiled against the Rust SDK, and the component's + * turnkey transport needs a raw SDK client. No feature module ever sees the SDK, the rule that no + * feature depends on `libraries/matrix/impl` still holds, and the SDK version contract is checked where + * the app's own SDK pin lives. + * + * The transport is built on the client's own coroutine scope, which is what ties it to the session: the + * component has no shutdown of its own, so cancelling that scope at logout is the only thing that stops + * the RTC core and its to-device subscription. + */ +@ContributesBinding(AppScope::class) +class DefaultElementCallTransportFactory : ElementCallTransportFactory { + override fun create(client: MatrixClient): ElementCallMatrixTransport { + return ElementCallSdkTransport( + client = (client as RustMatrixClient).innerClient, + sessionScope = client.sessionCoroutineScope, + ) + } +}