From afe08f23939a2e0a563b2f5d4d0d66c841fc39d7 Mon Sep 17 00:00:00 2001 From: Adam Hammer Date: Mon, 13 May 2024 07:49:25 -0700 Subject: [PATCH] [BUGFIX][ANDROID] Infinite loop when closing Bluetooth Profile Proxy and Update SwiftLint 0.53 (#988) Update to SwiftLint 0.53 and add flag comments for Rooms support --- .../presentation/manager/AudioSessionManager.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/manager/AudioSessionManager.kt b/azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/manager/AudioSessionManager.kt index 197a042d8..eb19753ff 100644 --- a/azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/manager/AudioSessionManager.kt +++ b/azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/manager/AudioSessionManager.kt @@ -39,6 +39,7 @@ internal class AudioSessionManager( private val audioManager by lazy { context.getSystemService(Context.AUDIO_SERVICE) as AudioManager } private var bluetoothAudioProxy: BluetoothHeadset? = null private var initialized = false + private var isProxyOpen = false private val isBluetoothScoAvailable get() = try { @@ -294,16 +295,20 @@ internal class AudioSessionManager( } private fun openProfileProxy() { + if (isProxyOpen) return if (btAdapter?.isEnabled == true && bluetoothAudioProxy == null) { btAdapter?.run { getProfileProxy(context, this@AudioSessionManager, BluetoothProfile.HEADSET) + isProxyOpen = true } } } private fun closeProfileProxy() { - btAdapter?.run { - closeProfileProxy(BluetoothProfile.HEADSET, bluetoothAudioProxy) + if (!isProxyOpen) return + isProxyOpen = false + bluetoothAudioProxy?.let { + btAdapter?.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothAudioProxy) bluetoothAudioProxy = null } } @@ -314,6 +319,8 @@ internal class AudioSessionManager( } override fun onServiceDisconnected(profile: Int) { - closeProfileProxy() + if (isProxyOpen) { + closeProfileProxy() + } } }