From a91e1fa2ae7a84a6f7daa6cb5d489b39ea818b4f Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Thu, 4 Jun 2026 15:08:19 +0200 Subject: [PATCH] Make Vulkan a *not required* feature (#6961) * Make Vulkan a *not required* feature * Add `DeviceHasVulkanSupport` helper to check this on runtime * When trying to open a screen with a map in it, check if vulkan is supported and display a new error dialog in that case * Fix random lint issue * Update screenshots --------- Co-authored-by: ElementBot --- .../home/impl/components/RoomSummaryRow.kt | 4 +- .../api/RenderingMapsNotSupportedDialog.kt | 30 +++++++++ .../impl/src/main/AndroidManifest.xml | 10 ++- .../messages/impl/MessagesFlowNode.kt | 64 ++++++++++++++----- .../impl/DefaultMessagesEntryPointTest.kt | 3 + .../system/DeviceHasVulkanSupport.kt | 31 +++++++++ .../src/main/res/values/localazy.xml | 2 + ...nderingMapsNotSupportedDialog_Day_0_en.png | 3 + ...eringMapsNotSupportedDialog_Night_0_en.png | 3 + 9 files changed, 132 insertions(+), 18 deletions(-) create mode 100644 features/location/api/src/main/kotlin/io/element/android/features/location/api/RenderingMapsNotSupportedDialog.kt create mode 100644 libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/DeviceHasVulkanSupport.kt create mode 100644 tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Night_0_en.png diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt index 934f60aa29..ba9a204a64 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt @@ -75,10 +75,10 @@ internal fun RoomSummaryRow( room: RoomListRoomSummary, hideInviteAvatars: Boolean, isInviteSeen: Boolean, - showUnreadCount: Boolean = false, onClick: (RoomListRoomSummary) -> Unit, - eventSink: (RoomListEvent) -> Unit, modifier: Modifier = Modifier, + showUnreadCount: Boolean = false, + eventSink: (RoomListEvent) -> Unit, ) { Box(modifier = modifier) { when (room.displayType) { diff --git a/features/location/api/src/main/kotlin/io/element/android/features/location/api/RenderingMapsNotSupportedDialog.kt b/features/location/api/src/main/kotlin/io/element/android/features/location/api/RenderingMapsNotSupportedDialog.kt new file mode 100644 index 0000000000..a4d65763ab --- /dev/null +++ b/features/location/api/src/main/kotlin/io/element/android/features/location/api/RenderingMapsNotSupportedDialog.kt @@ -0,0 +1,30 @@ +/* + * 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.location.api + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import io.element.android.libraries.designsystem.components.dialogs.ErrorDialog +import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.designsystem.preview.PreviewsDayNight +import io.element.android.libraries.ui.strings.CommonStrings + +@Composable +fun RenderingMapsNotSupportedDialog(onSubmit: () -> Unit) { + ErrorDialog( + title = stringResource(CommonStrings.vulkan_not_supported_dialog_title_android), + content = stringResource(CommonStrings.vulkan_not_supported_dialog_content_android), + onSubmit = onSubmit, + ) +} + +@PreviewsDayNight +@Composable +internal fun RenderingMapsNotSupportedDialogPreview() = ElementPreview { + RenderingMapsNotSupportedDialog(onSubmit = {}) +} diff --git a/features/location/impl/src/main/AndroidManifest.xml b/features/location/impl/src/main/AndroidManifest.xml index e92ca68077..e56a13e644 100644 --- a/features/location/impl/src/main/AndroidManifest.xml +++ b/features/location/impl/src/main/AndroidManifest.xml @@ -5,13 +5,21 @@ ~ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. ~ Please see LICENSE files in the repository root for full details. --> - + + + + ( backstack = BackStack( initialElement = plugins.filterIsInstance().first().initialTarget.toNavTarget(), @@ -188,6 +194,8 @@ class MessagesFlowNode( private val callback: MessagesEntryPoint.Callback = callback() + private var displayVulkanNotSupportedError by mutableStateOf(false) + override fun onBuilt() { super.onBuilt() lifecycle.subscribe( @@ -267,7 +275,11 @@ class MessagesFlowNode( } override fun navigateToSendLocation() { - backstack.push(NavTarget.SendLocation(Timeline.Mode.Live)) + if (hasVulkanSupport()) { + backstack.push(NavTarget.SendLocation(Timeline.Mode.Live)) + } else { + displayVulkanNotSupportedError = true + } } override fun navigateToCreatePoll() { @@ -279,7 +291,11 @@ class MessagesFlowNode( } override fun navigateToCurrentLiveLocation() { - backstack.push(NavTarget.LocationViewer(ShowLocationMode.Live(senderId = sessionId))) + if (hasVulkanSupport()) { + backstack.push(NavTarget.LocationViewer(ShowLocationMode.Live(senderId = sessionId))) + } else { + displayVulkanNotSupportedError = true + } } override fun navigateToRoomCall(roomId: RoomId, isAudioCall: Boolean) { @@ -506,7 +522,11 @@ class MessagesFlowNode( } override fun navigateToSendLocation() { - backstack.push(NavTarget.SendLocation(Timeline.Mode.Thread(navTarget.threadRootId))) + if (hasVulkanSupport()) { + backstack.push(NavTarget.SendLocation(Timeline.Mode.Thread(navTarget.threadRootId))) + } else { + displayVulkanNotSupportedError = true + } } override fun navigateToCreatePoll() { @@ -518,7 +538,11 @@ class MessagesFlowNode( } override fun navigateToCurrentLiveLocation() { - backstack.push(NavTarget.LocationViewer(ShowLocationMode.Live(senderId = sessionId))) + if (hasVulkanSupport()) { + backstack.push(NavTarget.LocationViewer(ShowLocationMode.Live(senderId = sessionId))) + } else { + displayVulkanNotSupportedError = true + } } override fun navigateToRoomCall(roomId: RoomId, isAudioCall: Boolean) { @@ -607,18 +631,23 @@ class MessagesFlowNode( ) } is TimelineItemLocationContent -> { - val mode = when (event.content.mode) { - is TimelineItemLocationContent.Mode.Live -> ShowLocationMode.Live(event.senderId) - is TimelineItemLocationContent.Mode.Static -> ShowLocationMode.Static( - location = event.content.mode.location, - senderName = event.safeSenderName, - senderId = event.senderId, - senderAvatarUrl = event.senderAvatar.url, - timestamp = event.sentTimeMillis, - assetType = event.content.assetType, - ) + if (hasVulkanSupport()) { + val mode = when (event.content.mode) { + is TimelineItemLocationContent.Mode.Live -> ShowLocationMode.Live(event.senderId) + is TimelineItemLocationContent.Mode.Static -> ShowLocationMode.Static( + location = event.content.mode.location, + senderName = event.safeSenderName, + senderId = event.senderId, + senderAvatarUrl = event.senderAvatar.url, + timestamp = event.sentTimeMillis, + assetType = event.content.assetType, + ) + } + NavTarget.LocationViewer(mode = mode).takeIf { locationService.isServiceAvailable() } + } else { + displayVulkanNotSupportedError = true + null } - NavTarget.LocationViewer(mode = mode).takeIf { locationService.isServiceAvailable() } } else -> null } @@ -691,6 +720,11 @@ class MessagesFlowNode( @Composable override fun View(modifier: Modifier) { mentionSpanTheme.updateStyles() + + if (displayVulkanNotSupportedError) { + RenderingMapsNotSupportedDialog { displayVulkanNotSupportedError = false } + } + CompositionLocalProvider( LocalMentionSpanUpdater provides mentionSpanUpdater ) { diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/DefaultMessagesEntryPointTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/DefaultMessagesEntryPointTest.kt index dc50fca2c3..9679e23a23 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/DefaultMessagesEntryPointTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/DefaultMessagesEntryPointTest.kt @@ -23,6 +23,7 @@ import io.element.android.features.messages.api.MessagesEntryPoint import io.element.android.features.messages.impl.pinned.banner.createPinnedEventsTimelineProvider import io.element.android.features.messages.impl.timeline.createTimelineController import io.element.android.features.poll.test.create.FakeCreatePollEntryPoint +import io.element.android.libraries.androidutils.system.DeviceHasVulkanSupport import io.element.android.libraries.dateformatter.test.FakeDateFormatter import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId @@ -42,6 +43,7 @@ import io.element.android.services.analytics.test.FakeAnalyticsService import io.element.android.tests.testutils.lambda.lambdaError import io.element.android.tests.testutils.node.TestParentNode import io.element.android.tests.testutils.testCoroutineDispatchers +import io.mockk.mockk import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test @@ -85,6 +87,7 @@ class DefaultMessagesEntryPointTest { knockRequestsListEntryPoint = FakeKnockRequestsListEntryPoint(), dateFormatter = FakeDateFormatter(), coroutineDispatchers = testCoroutineDispatchers(), + hasVulkanSupport = DeviceHasVulkanSupport(mockk(relaxed = true)) ) } val callback = object : MessagesEntryPoint.Callback { diff --git a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/DeviceHasVulkanSupport.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/DeviceHasVulkanSupport.kt new file mode 100644 index 0000000000..e8e5edcca0 --- /dev/null +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/DeviceHasVulkanSupport.kt @@ -0,0 +1,31 @@ +/* + * 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.androidutils.system + +import android.content.Context +import dev.zacsweers.metro.Inject +import io.element.android.libraries.di.annotations.ApplicationContext + +private const val VULKAN_VERSION_1_0 = 0x400003 + +/** + * Checks if the device supports Vulkan 1.0. + * + * This is needed for the location screens that contain maps using MapLibre UI components. + * + * Needed until https://github.com/maplibre/maplibre-native/issues/3079 is resolved and we can automatically choose between OpenGL and Vulkan renderers, + * or no devices support OpenGL anymore. + */ +@Inject +class DeviceHasVulkanSupport( + @ApplicationContext private val context: Context, +) { + operator fun invoke(): Boolean { + return context.packageManager.hasSystemFeature("android.hardware.vulkan.version", VULKAN_VERSION_1_0) + } +} diff --git a/libraries/ui-strings/src/main/res/values/localazy.xml b/libraries/ui-strings/src/main/res/values/localazy.xml index 823c0fad72..75b6ab1ee7 100644 --- a/libraries/ui-strings/src/main/res/values/localazy.xml +++ b/libraries/ui-strings/src/main/res/values/localazy.xml @@ -546,4 +546,6 @@ Are you sure you want to continue?" "You don\'t have access to this message" "Unable to decrypt message" "This message was blocked either because you did not verify your device or because the sender needs to verify your digital identity." + "Your device is too old, a device with Android 8 or newer is required." + "Rendering maps is not supported" diff --git a/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Day_0_en.png new file mode 100644 index 0000000000..cf35ad0fa8 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f64455657f0f8a5ac7eec71ee206721a79b25dacf470d105a0e6497e570204a +size 23954 diff --git a/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Night_0_en.png new file mode 100644 index 0000000000..41cdb80dc8 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.location.api_RenderingMapsNotSupportedDialog_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43bd5f04f170372b120fa2223c632d6a969c45b6d4fe61b161a7109318f9941f +size 22658