From 28c1c078a030d21d926949f1fe401bc36305d47e Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 24 Feb 2026 13:38:53 +0100 Subject: [PATCH] Catch exceptions when setting or clearing an audio communication device in Element Call (#6226) --- .../call/impl/utils/WebViewAudioManager.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt index e27084f707..0c1ecf83cb 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt @@ -18,6 +18,7 @@ import android.webkit.JavascriptInterface import android.webkit.WebView import androidx.annotation.RequiresApi import androidx.core.content.getSystemService +import io.element.android.libraries.core.extensions.runCatchingExceptions import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -385,10 +386,18 @@ class WebViewAudioManager( currentDeviceId = device?.id if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (device != null) { - Timber.d("Setting communication device: ${device.id} - ${deviceName(device.type, device.productName.toString())}") - setCommunicationDevice(device) + runCatchingExceptions { + Timber.d("Setting communication device: ${device.id} - ${deviceName(device.type, device.productName.toString())}") + setCommunicationDevice(device) + }.onFailure { + Timber.e(it, "Could not set communication device.") + } } else { - audioManager.clearCommunicationDevice() + runCatchingExceptions { + clearCommunicationDevice() + }.onFailure { + Timber.e(it, "Could not clear communication device.") + } } } else { // On Android 11 and lower, we don't have the concept of communication devices