[Bug] Potential memory leak fix for bluetooth pair-unpair scenario (#320)
This commit is contained in:
Родитель
25620c7557
Коммит
a32aa6cf89
|
@ -83,7 +83,6 @@ internal class AudioSessionManager(
|
|||
}
|
||||
(activity as LifecycleOwner).lifecycle.coroutineScope.launch {
|
||||
// On first launch we need to init the redux-state, check Bluetooth and Headset status
|
||||
|
||||
store.getStateFlow().collect {
|
||||
if (previousAudioDeviceSelectionStatus == null ||
|
||||
previousAudioDeviceSelectionStatus != it.localParticipantState.audioState.device
|
||||
|
@ -124,6 +123,7 @@ internal class AudioSessionManager(
|
|||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
intent?.apply {
|
||||
when (action) {
|
||||
BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED -> openProfileProxy()
|
||||
BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED -> updateBluetoothStatus()
|
||||
AudioManager.ACTION_HEADSET_PLUG -> updateHeadphoneStatus()
|
||||
}
|
||||
|
@ -295,8 +295,17 @@ internal class AudioSessionManager(
|
|||
}
|
||||
|
||||
private fun openProfileProxy() {
|
||||
if (btAdapter?.isEnabled == true)btAdapter?.run {
|
||||
getProfileProxy(context, this@AudioSessionManager, BluetoothProfile.HEADSET)
|
||||
if (btAdapter?.isEnabled == true && bluetoothAudioProxy == null) {
|
||||
btAdapter?.run {
|
||||
getProfileProxy(context, this@AudioSessionManager, BluetoothProfile.HEADSET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeProfileProxy() {
|
||||
btAdapter?.run {
|
||||
closeProfileProxy(BluetoothProfile.HEADSET, bluetoothAudioProxy)
|
||||
bluetoothAudioProxy = null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,5 +314,7 @@ internal class AudioSessionManager(
|
|||
updateBluetoothStatus()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) { }
|
||||
override fun onServiceDisconnected(profile: Int) {
|
||||
closeProfileProxy()
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче