You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: do not set invalid BT devices as communication device (#2064)
### 💡 Overview
Currently we set A2DP BT devices as communication device even if they
dont have headset profile, this PR adds some safeguards and filtering to
prevent this
Copy file name to clipboardExpand all lines: packages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioDeviceEndpointUtils.kt
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,22 @@ internal class AudioDeviceEndpointUtils {
44
44
val endpoints:MutableList<AudioDeviceEndpoint> =mutableListOf()
45
45
var foundWiredHeadset =false
46
46
val omittedDevices =StringBuilder("omitting devices =[")
47
-
adiArr.toList().forEach { audioDeviceInfo ->
47
+
adiArr.forEach { audioDeviceInfo ->
48
+
/**
49
+
* Only devices in a sink role can be selected via AudioManager#setCommunicationDevice
50
+
* (API 31+). We enforce this at the endpoint construction level as a safety net
51
+
* because AudioDeviceCallback can surface devices that aren't valid call endpoints.
52
+
*/
53
+
val isInvalidCallEndpoint =!audioDeviceInfo.isSink
54
+
55
+
if (isInvalidCallEndpoint) {
56
+
omittedDevices.append(
57
+
"(type=[${audioDeviceInfo.type}],"+
58
+
" name=[${audioDeviceInfo.productName}]),"
59
+
)
60
+
return@forEach
61
+
}
62
+
48
63
val endpoint = getEndpointFromAudioDeviceInfo(audioDeviceInfo)
49
64
if (endpoint.type !=AudioDeviceEndpoint.TYPE_UNKNOWN) {
50
65
if (endpoint.type ==AudioDeviceEndpoint.TYPE_WIRED_HEADSET) {
@@ -115,11 +130,8 @@ internal class AudioDeviceEndpointUtils {
Copy file name to clipboardExpand all lines: packages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioManagerUtil.kt
+35-2Lines changed: 35 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,39 @@ internal class AudioManagerUtil {
25
25
}
26
26
}
27
27
28
+
/**
29
+
* Safe wrapper around [AudioManager.setCommunicationDevice] to avoid crashing the app on
30
+
* OEM-specific edge cases. On API 31+, Android requires that:
31
+
* - the device is a sink (output), and
32
+
* - the device is among [AudioManager.availableCommunicationDevices].
0 commit comments