@stream-io/video-react-native-sdk 1.21.2 → 1.22.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/android/gradle.properties +3 -3
  2. package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt +10 -0
  3. package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativePackage.kt +2 -1
  4. package/android/src/main/java/com/streamvideo/reactnative/audio/AudioDeviceManager.kt +592 -0
  5. package/android/src/main/java/com/streamvideo/reactnative/audio/BluetoothManager.kt +755 -0
  6. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioDeviceEndpointUtils.kt +192 -0
  7. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioFocusUtil.kt +62 -0
  8. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioManagerUtil.kt +159 -0
  9. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/AudioSetupStoreUtil.kt +41 -0
  10. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/WebRtcAudioUtils.kt +250 -0
  11. package/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.kt +191 -0
  12. package/android/src/main/java/com/streamvideo/reactnative/model/AudioDeviceEndpoint.kt +136 -0
  13. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +12 -0
  14. package/dist/commonjs/components/Call/CallContent/CallContent.js +13 -9
  15. package/dist/commonjs/components/Call/CallContent/CallContent.js.map +1 -1
  16. package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js +9 -2
  17. package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
  18. package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js +3 -0
  19. package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
  20. package/dist/commonjs/components/Livestream/HostLivestream/HostLivestream.js +10 -6
  21. package/dist/commonjs/components/Livestream/HostLivestream/HostLivestream.js.map +1 -1
  22. package/dist/commonjs/components/Livestream/LivestreamControls/ViewerLivestreamControls.js +8 -4
  23. package/dist/commonjs/components/Livestream/LivestreamControls/ViewerLivestreamControls.js.map +1 -1
  24. package/dist/commonjs/components/Livestream/LivestreamLayout/LivestreamLayout.js +26 -27
  25. package/dist/commonjs/components/Livestream/LivestreamLayout/LivestreamLayout.js.map +1 -1
  26. package/dist/commonjs/components/Livestream/ViewerLivestream/ViewerLivestream.js +10 -6
  27. package/dist/commonjs/components/Livestream/ViewerLivestream/ViewerLivestream.js.map +1 -1
  28. package/dist/commonjs/hooks/useIsInPiPMode.js +3 -3
  29. package/dist/commonjs/hooks/useIsInPiPMode.js.map +1 -1
  30. package/dist/commonjs/hooks/usePermissionNotification.js +5 -5
  31. package/dist/commonjs/hooks/usePermissionNotification.js.map +1 -1
  32. package/dist/commonjs/index.js +12 -0
  33. package/dist/commonjs/index.js.map +1 -1
  34. package/dist/commonjs/modules/call-manager/CallManager.js +113 -0
  35. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -0
  36. package/dist/commonjs/modules/call-manager/PrevLibDetection.js +18 -0
  37. package/dist/commonjs/modules/call-manager/PrevLibDetection.js.map +1 -0
  38. package/dist/commonjs/modules/call-manager/index.js +24 -0
  39. package/dist/commonjs/modules/call-manager/index.js.map +1 -0
  40. package/dist/commonjs/modules/call-manager/native-module.d.js +4 -0
  41. package/dist/commonjs/modules/call-manager/native-module.d.js.map +1 -0
  42. package/dist/commonjs/modules/call-manager/types.js +2 -0
  43. package/dist/commonjs/modules/call-manager/types.js.map +1 -0
  44. package/dist/commonjs/providers/StreamCall/AppStateListener.js +5 -5
  45. package/dist/commonjs/providers/StreamCall/AppStateListener.js.map +1 -1
  46. package/dist/commonjs/theme/theme.js.map +1 -1
  47. package/dist/commonjs/utils/internal/rxSubjects.js +2 -2
  48. package/dist/commonjs/utils/internal/rxSubjects.js.map +1 -1
  49. package/dist/commonjs/version.js +1 -1
  50. package/dist/commonjs/version.js.map +1 -1
  51. package/dist/module/components/Call/CallContent/CallContent.js +14 -9
  52. package/dist/module/components/Call/CallContent/CallContent.js.map +1 -1
  53. package/dist/module/components/Call/CallContent/RTCViewPipIOS.js +9 -2
  54. package/dist/module/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
  55. package/dist/module/components/Call/CallContent/RTCViewPipNative.js +3 -0
  56. package/dist/module/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
  57. package/dist/module/components/Livestream/HostLivestream/HostLivestream.js +10 -5
  58. package/dist/module/components/Livestream/HostLivestream/HostLivestream.js.map +1 -1
  59. package/dist/module/components/Livestream/LivestreamControls/ViewerLivestreamControls.js +9 -4
  60. package/dist/module/components/Livestream/LivestreamControls/ViewerLivestreamControls.js.map +1 -1
  61. package/dist/module/components/Livestream/LivestreamLayout/LivestreamLayout.js +26 -27
  62. package/dist/module/components/Livestream/LivestreamLayout/LivestreamLayout.js.map +1 -1
  63. package/dist/module/components/Livestream/ViewerLivestream/ViewerLivestream.js +10 -5
  64. package/dist/module/components/Livestream/ViewerLivestream/ViewerLivestream.js.map +1 -1
  65. package/dist/module/hooks/useIsInPiPMode.js +4 -4
  66. package/dist/module/hooks/useIsInPiPMode.js.map +1 -1
  67. package/dist/module/hooks/usePermissionNotification.js +7 -6
  68. package/dist/module/hooks/usePermissionNotification.js.map +1 -1
  69. package/dist/module/icons/Back.js +1 -1
  70. package/dist/module/icons/Back.js.map +1 -1
  71. package/dist/module/icons/CameraSwitch.js +1 -1
  72. package/dist/module/icons/CameraSwitch.js.map +1 -1
  73. package/dist/module/icons/Mic.js +1 -1
  74. package/dist/module/icons/Mic.js.map +1 -1
  75. package/dist/module/icons/MicOff.js +1 -1
  76. package/dist/module/icons/MicOff.js.map +1 -1
  77. package/dist/module/icons/Phone.js +1 -1
  78. package/dist/module/icons/Phone.js.map +1 -1
  79. package/dist/module/icons/PinVertical.js +1 -1
  80. package/dist/module/icons/PinVertical.js.map +1 -1
  81. package/dist/module/icons/Reaction.js +1 -1
  82. package/dist/module/icons/Reaction.js.map +1 -1
  83. package/dist/module/icons/Spotlight.js +1 -1
  84. package/dist/module/icons/Spotlight.js.map +1 -1
  85. package/dist/module/icons/Video.js +1 -1
  86. package/dist/module/icons/Video.js.map +1 -1
  87. package/dist/module/icons/VideoSlash.js +1 -1
  88. package/dist/module/icons/VideoSlash.js.map +1 -1
  89. package/dist/module/index.js +1 -0
  90. package/dist/module/index.js.map +1 -1
  91. package/dist/module/modules/call-manager/CallManager.js +106 -0
  92. package/dist/module/modules/call-manager/CallManager.js.map +1 -0
  93. package/dist/module/modules/call-manager/PrevLibDetection.js +12 -0
  94. package/dist/module/modules/call-manager/PrevLibDetection.js.map +1 -0
  95. package/dist/module/modules/call-manager/index.js +4 -0
  96. package/dist/module/modules/call-manager/index.js.map +1 -0
  97. package/dist/module/modules/call-manager/native-module.d.js +2 -0
  98. package/dist/module/modules/call-manager/native-module.d.js.map +1 -0
  99. package/dist/module/modules/call-manager/types.js +2 -0
  100. package/dist/module/modules/call-manager/types.js.map +1 -0
  101. package/dist/module/providers/StreamCall/AppStateListener.js +6 -6
  102. package/dist/module/providers/StreamCall/AppStateListener.js.map +1 -1
  103. package/dist/module/theme/theme.js.map +1 -1
  104. package/dist/module/utils/internal/rxSubjects.js +1 -1
  105. package/dist/module/utils/internal/rxSubjects.js.map +1 -1
  106. package/dist/module/version.js +1 -1
  107. package/dist/module/version.js.map +1 -1
  108. package/dist/typescript/components/Call/CallContent/CallContent.d.ts +3 -2
  109. package/dist/typescript/components/Call/CallContent/CallContent.d.ts.map +1 -1
  110. package/dist/typescript/components/Call/CallContent/RTCViewPipIOS.d.ts +5 -0
  111. package/dist/typescript/components/Call/CallContent/RTCViewPipIOS.d.ts.map +1 -1
  112. package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts +6 -0
  113. package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts.map +1 -1
  114. package/dist/typescript/components/Livestream/HostLivestream/HostLivestream.d.ts.map +1 -1
  115. package/dist/typescript/components/Livestream/LivestreamControls/ViewerLivestreamControls.d.ts.map +1 -1
  116. package/dist/typescript/components/Livestream/LivestreamLayout/LivestreamLayout.d.ts.map +1 -1
  117. package/dist/typescript/components/Livestream/ViewerLivestream/ViewerLivestream.d.ts.map +1 -1
  118. package/dist/typescript/hooks/usePermissionNotification.d.ts.map +1 -1
  119. package/dist/typescript/icons/Back.d.ts +1 -1
  120. package/dist/typescript/icons/Back.d.ts.map +1 -1
  121. package/dist/typescript/icons/BadNetwork.d.ts +1 -1
  122. package/dist/typescript/icons/BadNetwork.d.ts.map +1 -1
  123. package/dist/typescript/icons/CameraSwitch.d.ts +1 -1
  124. package/dist/typescript/icons/CameraSwitch.d.ts.map +1 -1
  125. package/dist/typescript/icons/LivestreamControls.d.ts +1 -1
  126. package/dist/typescript/icons/LivestreamControls.d.ts.map +1 -1
  127. package/dist/typescript/icons/Lock.d.ts +1 -1
  128. package/dist/typescript/icons/Lock.d.ts.map +1 -1
  129. package/dist/typescript/icons/Maximize.d.ts +1 -1
  130. package/dist/typescript/icons/Maximize.d.ts.map +1 -1
  131. package/dist/typescript/icons/Mic.d.ts +1 -1
  132. package/dist/typescript/icons/Mic.d.ts.map +1 -1
  133. package/dist/typescript/icons/MicOff.d.ts +1 -1
  134. package/dist/typescript/icons/MicOff.d.ts.map +1 -1
  135. package/dist/typescript/icons/Phone.d.ts +1 -1
  136. package/dist/typescript/icons/Phone.d.ts.map +1 -1
  137. package/dist/typescript/icons/PhoneDown.d.ts +1 -1
  138. package/dist/typescript/icons/PhoneDown.d.ts.map +1 -1
  139. package/dist/typescript/icons/PinVertical.d.ts +1 -1
  140. package/dist/typescript/icons/PinVertical.d.ts.map +1 -1
  141. package/dist/typescript/icons/Reaction.d.ts +1 -1
  142. package/dist/typescript/icons/Reaction.d.ts.map +1 -1
  143. package/dist/typescript/icons/ScreenShare.d.ts +1 -1
  144. package/dist/typescript/icons/ScreenShare.d.ts.map +1 -1
  145. package/dist/typescript/icons/ScreenShareIndicator.d.ts +1 -1
  146. package/dist/typescript/icons/ScreenShareIndicator.d.ts.map +1 -1
  147. package/dist/typescript/icons/Spotlight.d.ts +1 -1
  148. package/dist/typescript/icons/Spotlight.d.ts.map +1 -1
  149. package/dist/typescript/icons/StopScreenShare.d.ts +1 -1
  150. package/dist/typescript/icons/StopScreenShare.d.ts.map +1 -1
  151. package/dist/typescript/icons/Video.d.ts +1 -1
  152. package/dist/typescript/icons/Video.d.ts.map +1 -1
  153. package/dist/typescript/icons/VideoSlash.d.ts +1 -1
  154. package/dist/typescript/icons/VideoSlash.d.ts.map +1 -1
  155. package/dist/typescript/index.d.ts +1 -0
  156. package/dist/typescript/index.d.ts.map +1 -1
  157. package/dist/typescript/modules/call-manager/CallManager.d.ts +67 -0
  158. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -0
  159. package/dist/typescript/modules/call-manager/PrevLibDetection.d.ts +13 -0
  160. package/dist/typescript/modules/call-manager/PrevLibDetection.d.ts.map +1 -0
  161. package/dist/typescript/modules/call-manager/index.d.ts +4 -0
  162. package/dist/typescript/modules/call-manager/index.d.ts.map +1 -0
  163. package/dist/typescript/modules/call-manager/types.d.ts +15 -0
  164. package/dist/typescript/modules/call-manager/types.d.ts.map +1 -0
  165. package/dist/typescript/providers/StreamCall/AppStateListener.d.ts.map +1 -1
  166. package/dist/typescript/theme/theme.d.ts +1 -2
  167. package/dist/typescript/theme/theme.d.ts.map +1 -1
  168. package/dist/typescript/utils/internal/rxSubjects.d.ts +1 -1
  169. package/dist/typescript/utils/internal/rxSubjects.d.ts.map +1 -1
  170. package/dist/typescript/version.d.ts +1 -1
  171. package/dist/typescript/version.d.ts.map +1 -1
  172. package/ios/PictureInPicture/StreamPictureInPictureController.swift +5 -0
  173. package/ios/RTCViewPip.swift +15 -0
  174. package/ios/RTCViewPipManager.mm +1 -0
  175. package/ios/StreamInCallManager.m +26 -0
  176. package/ios/StreamInCallManager.swift +303 -0
  177. package/ios/StreamVideoReactNative-Bridging-Header.h +1 -0
  178. package/ios/StreamVideoReactNative.m +6 -5
  179. package/ios/StreamVideoReactNative.xcodeproj/project.xcworkspace/xcuserdata/santhoshvaiyapuri.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  180. package/ios/StreamVideoReactNative.xcodeproj/xcuserdata/santhoshvaiyapuri.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  181. package/package.json +33 -35
  182. package/src/components/Call/CallContent/CallContent.tsx +14 -10
  183. package/src/components/Call/CallContent/RTCViewPipIOS.tsx +17 -2
  184. package/src/components/Call/CallContent/RTCViewPipNative.tsx +8 -0
  185. package/src/components/Livestream/HostLivestream/HostLivestream.tsx +8 -3
  186. package/src/components/Livestream/LivestreamControls/ViewerLivestreamControls.tsx +11 -5
  187. package/src/components/Livestream/LivestreamLayout/LivestreamLayout.tsx +38 -29
  188. package/src/components/Livestream/ViewerLivestream/ViewerLivestream.tsx +8 -3
  189. package/src/hooks/useIsInPiPMode.tsx +4 -4
  190. package/src/hooks/usePermissionNotification.tsx +7 -12
  191. package/src/icons/Back.tsx +2 -2
  192. package/src/icons/BadNetwork.tsx +1 -1
  193. package/src/icons/CameraSwitch.tsx +2 -2
  194. package/src/icons/LivestreamControls.tsx +1 -1
  195. package/src/icons/Lock.tsx +1 -1
  196. package/src/icons/Maximize.tsx +1 -1
  197. package/src/icons/Mic.tsx +2 -2
  198. package/src/icons/MicOff.tsx +2 -2
  199. package/src/icons/Phone.tsx +2 -2
  200. package/src/icons/PhoneDown.tsx +1 -1
  201. package/src/icons/PinVertical.tsx +2 -2
  202. package/src/icons/Reaction.tsx +2 -2
  203. package/src/icons/ScreenShare.tsx +1 -1
  204. package/src/icons/ScreenShareIndicator.tsx +1 -1
  205. package/src/icons/Spotlight.tsx +2 -2
  206. package/src/icons/StopScreenShare.tsx +1 -1
  207. package/src/icons/Video.tsx +2 -2
  208. package/src/icons/VideoSlash.tsx +2 -2
  209. package/src/index.ts +1 -0
  210. package/src/modules/call-manager/CallManager.ts +116 -0
  211. package/src/modules/call-manager/PrevLibDetection.ts +27 -0
  212. package/src/modules/call-manager/index.ts +5 -0
  213. package/src/modules/call-manager/native-module.d.ts +80 -0
  214. package/src/modules/call-manager/types.ts +25 -0
  215. package/src/providers/StreamCall/AppStateListener.tsx +6 -9
  216. package/src/theme/theme.ts +2 -2
  217. package/src/utils/internal/rxSubjects.ts +1 -1
  218. package/src/version.ts +1 -1
  219. package/CHANGELOG.md +0 -2783
@@ -0,0 +1,755 @@
1
+ /*
2
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+ package com.streamvideo.reactnative.audio
11
+
12
+ import android.Manifest
13
+ import android.annotation.SuppressLint
14
+ import android.bluetooth.BluetoothAdapter
15
+ import android.bluetooth.BluetoothClass
16
+ import android.bluetooth.BluetoothDevice
17
+ import android.bluetooth.BluetoothHeadset
18
+ import android.bluetooth.BluetoothManager
19
+ import android.bluetooth.BluetoothProfile
20
+ import android.content.BroadcastReceiver
21
+ import android.content.Context
22
+ import android.content.Intent
23
+ import android.content.IntentFilter
24
+ import android.content.pm.PackageManager
25
+ import android.media.AudioDeviceCallback
26
+ import android.media.AudioDeviceInfo
27
+ import android.media.AudioManager
28
+ import android.os.Build
29
+ import android.os.Handler
30
+ import android.os.Looper
31
+ import android.util.Log
32
+ import androidx.annotation.RequiresApi
33
+ import androidx.core.content.ContextCompat
34
+ import com.facebook.react.bridge.ReactApplicationContext
35
+ import com.streamvideo.reactnative.audio.AudioDeviceManager.Companion.runInAudioThread
36
+ import com.streamvideo.reactnative.audio.utils.AudioDeviceEndpointUtils
37
+ import com.streamvideo.reactnative.callmanager.StreamInCallManagerModule
38
+ import com.streamvideo.reactnative.model.AudioDeviceEndpoint
39
+
40
+ class BluetoothManager(
41
+ private val mReactContext: ReactApplicationContext,
42
+ private val audioDeviceManager: AudioDeviceManager,
43
+ ) {
44
+ // Bluetooth connection state.
45
+ enum class State {
46
+ // Bluetooth is not available; no adapter or Bluetooth is off.
47
+ UNINITIALIZED,
48
+
49
+ // Bluetooth error happened when trying to start Bluetooth.
50
+ ERROR,
51
+
52
+ // Bluetooth proxy object for the Headset profile exists, but no connected headset devices,
53
+ // SCO is not started or disconnected.
54
+ HEADSET_UNAVAILABLE,
55
+
56
+ // Bluetooth proxy object for the Headset profile connected, connected Bluetooth headset
57
+ // present, but SCO is not started or disconnected.
58
+ HEADSET_AVAILABLE,
59
+
60
+ // Bluetooth audio SCO connection with remote device is closing.
61
+ SCO_DISCONNECTING,
62
+
63
+ // Bluetooth audio SCO connection with remote device is initiated.
64
+ SCO_CONNECTING,
65
+
66
+ // Bluetooth audio SCO connection with remote device is established.
67
+ SCO_CONNECTED
68
+ }
69
+
70
+ private val mAudioManager =
71
+ mReactContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
72
+
73
+ var bluetoothState: State = State.UNINITIALIZED
74
+
75
+ private val btManagerPlatform: BluetoothManagerPlatform =
76
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) BluetoothManager31PlusImpl() else BluetoothManager23PlusImpl()
77
+
78
+ private fun updateAudioDeviceState() {
79
+ Log.d(TAG, "updateAudioDeviceState")
80
+ audioDeviceManager.updateAudioDeviceState()
81
+ }
82
+
83
+ /** Start the listeners */
84
+ fun start() = btManagerPlatform.start()
85
+
86
+ /** Stop the listeners */
87
+ fun stop() = btManagerPlatform.stop()
88
+
89
+ /** is audio flowing through BT communication device? */
90
+ fun isScoOn() = btManagerPlatform.isScoOn()
91
+
92
+ /** Start audio flowing through BT communication device. */
93
+ fun startScoAudio() = btManagerPlatform.startScoAudio()
94
+
95
+ /** Stop audio flowing through BT communication device. */
96
+ fun stopScoAudio() = btManagerPlatform.stopScoAudio()
97
+
98
+ /** Check if there is a BT headset connected and update the state accordingly */
99
+ fun updateDevice() = btManagerPlatform.updateDevice()
100
+
101
+ fun getDeviceName() = btManagerPlatform.getDeviceName()
102
+
103
+ abstract inner class BluetoothManagerPlatform {
104
+
105
+ abstract fun hasPermission(): Boolean
106
+
107
+ /** is audio flowing through BT communication device? */
108
+ abstract fun isScoOn(): Boolean
109
+
110
+ /** Start audio flowing through BT communication device. */
111
+ abstract fun startScoAudio(): Boolean
112
+
113
+ /** Check if there is a BT headset connected and update the state. */
114
+ abstract fun updateDevice()
115
+
116
+ /** Get the name of the connected BT device if present, otherwise null. */
117
+ abstract fun getDeviceName(): String?
118
+
119
+ /** Stop audio flowing through BT communication device. */
120
+ open fun stopScoAudio(): Boolean {
121
+ Log.d(
122
+ TAG, ("stopScoAudio: BT state=" + bluetoothState + ", " + "SCO is on: " + isScoOn())
123
+ )
124
+ return !(bluetoothState != State.SCO_CONNECTING && bluetoothState != State.SCO_CONNECTED)
125
+ }
126
+
127
+ /** Start the listeners */
128
+ open fun start(): Boolean {
129
+ Log.d(TAG, "start")
130
+ if (!hasPermission()) {
131
+ Log.w(
132
+ TAG, "App lacks BLUETOOTH permission"
133
+ )
134
+ return false
135
+ }
136
+
137
+ // Ensure that the device supports use of BT SCO audio for off call use cases.
138
+ if (!mAudioManager.isBluetoothScoAvailableOffCall) {
139
+ Log.e(TAG, "Bluetooth SCO audio is not available off call")
140
+ return false
141
+ }
142
+
143
+ return true
144
+ }
145
+
146
+ /* Stop the listeners */
147
+ open fun stop(): Boolean {
148
+ Log.d(
149
+ TAG, "stop: BT state=$bluetoothState"
150
+ )
151
+ // Close down remaining BT resources.
152
+ return bluetoothState != State.UNINITIALIZED
153
+ }
154
+ }
155
+
156
+ @RequiresApi(31)
157
+ inner class BluetoothManager31PlusImpl : BluetoothManagerPlatform() {
158
+
159
+ private var bluetoothAudioDevice: AudioDeviceInfo? = null
160
+
161
+ /** Get the connected BT device if present, otherwise null.
162
+ Note: this doesn't mean that the device is streaming the audio now. It is only connected.
163
+ */
164
+ private fun getAvailableBtDevice(): AudioDeviceInfo? {
165
+ val devices = mAudioManager.availableCommunicationDevices
166
+ for (device in devices) {
167
+ val isBtDevice =
168
+ AudioDeviceEndpoint.TYPE_BLUETOOTH == AudioDeviceEndpointUtils.remapAudioDeviceTypeToCallEndpointType(
169
+ device.type
170
+ )
171
+ if (isBtDevice) {
172
+ return device
173
+ }
174
+ }
175
+ return null
176
+ }
177
+
178
+ private var bluetoothAudioDeviceCallback: AudioDeviceCallback =
179
+ object : AudioDeviceCallback() {
180
+
181
+ override fun onAudioDevicesAdded(addedDevices: Array<out AudioDeviceInfo>?) {
182
+ if (addedDevices != null) {
183
+ runInAudioThread {
184
+ updateDeviceList()
185
+ }
186
+ }
187
+ }
188
+
189
+ override fun onAudioDevicesRemoved(removedDevices: Array<out AudioDeviceInfo>?) {
190
+ if (removedDevices != null) {
191
+ runInAudioThread {
192
+ updateDeviceList()
193
+ }
194
+ }
195
+ }
196
+
197
+ fun updateDeviceList() {
198
+ val currentBtDevice = bluetoothAudioDevice
199
+ val newBtDevice: AudioDeviceInfo? = getAvailableBtDevice()
200
+ if (currentBtDevice != null && newBtDevice == null) {
201
+ bluetoothState = State.HEADSET_UNAVAILABLE
202
+ } else if (currentBtDevice == null && newBtDevice != null) {
203
+ bluetoothState = State.HEADSET_AVAILABLE
204
+ } else if (currentBtDevice != null && newBtDevice != null && currentBtDevice.id != newBtDevice.id) {
205
+ updateDevice()
206
+ }
207
+ }
208
+ }
209
+
210
+ override fun hasPermission(): Boolean {
211
+ return mReactContext.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
212
+ }
213
+
214
+ override fun start(): Boolean {
215
+ if (!super.start()) {
216
+ return false
217
+ }
218
+ mAudioManager.registerAudioDeviceCallback(bluetoothAudioDeviceCallback, null)
219
+ bluetoothAudioDevice = getAvailableBtDevice()
220
+ bluetoothState =
221
+ if (bluetoothAudioDevice != null) State.HEADSET_AVAILABLE else State.HEADSET_UNAVAILABLE
222
+ Log.d(
223
+ TAG, "start done: BT state=$bluetoothState"
224
+ )
225
+ return true
226
+ }
227
+
228
+ override fun stop(): Boolean {
229
+ if (!super.start()) {
230
+ return false
231
+ }
232
+ // Stop BT SCO connection with remote device if needed.
233
+ stopScoAudio()
234
+ mAudioManager.unregisterAudioDeviceCallback(bluetoothAudioDeviceCallback)
235
+ bluetoothState = State.UNINITIALIZED
236
+ Log.d(
237
+ TAG, "stop done: BT state=$bluetoothState"
238
+ )
239
+ return true
240
+ }
241
+
242
+ override fun isScoOn(): Boolean {
243
+ val communicationDevice: AudioDeviceInfo? = mAudioManager.communicationDevice
244
+ if (communicationDevice !== null) {
245
+ val isOn =
246
+ AudioDeviceEndpoint.TYPE_BLUETOOTH == AudioDeviceEndpointUtils.remapAudioDeviceTypeToCallEndpointType(
247
+ communicationDevice.type
248
+ )
249
+ if (isOn) {
250
+ bluetoothAudioDevice = communicationDevice
251
+ return true
252
+ }
253
+ }
254
+ return false
255
+ }
256
+
257
+ override fun startScoAudio(): Boolean {
258
+ Log.d(
259
+ TAG, ("startSco: BT state=" + bluetoothState + ", SCO is on: " + isScoOn())
260
+ )
261
+ val currentBtDevice = bluetoothAudioDevice
262
+ if (currentBtDevice != null) {
263
+ mAudioManager.setCommunicationDevice(currentBtDevice)
264
+ bluetoothState = State.SCO_CONNECTED
265
+ Log.d(
266
+ TAG,
267
+ "Set bluetooth audio device as communication device: id=${currentBtDevice.id} name=${currentBtDevice.productName}"
268
+ )
269
+ return true
270
+ }
271
+ bluetoothState = State.HEADSET_UNAVAILABLE
272
+ Log.e(
273
+ TAG, "Cannot find any bluetooth SCO device to set as communication device"
274
+ )
275
+ return false
276
+ }
277
+
278
+ override fun updateDevice() {
279
+ if (bluetoothState == State.UNINITIALIZED) {
280
+ return
281
+ }
282
+ if (bluetoothState == State.SCO_CONNECTED) {
283
+ if (isScoOn()) {
284
+ return
285
+ }
286
+ }
287
+ bluetoothAudioDevice = getAvailableBtDevice()
288
+ val currentBtDevice = bluetoothAudioDevice
289
+ if (currentBtDevice != null) {
290
+ bluetoothState = State.HEADSET_AVAILABLE
291
+ Log.d(
292
+ TAG, ("Connected bluetooth headset: " + "name=" + currentBtDevice.productName)
293
+ )
294
+ } else {
295
+ bluetoothState = State.HEADSET_UNAVAILABLE
296
+ }
297
+ Log.d(
298
+ TAG, "updateDevice done: BT state=$bluetoothState"
299
+ )
300
+ }
301
+
302
+ override fun getDeviceName(): String? {
303
+ return bluetoothAudioDevice?.productName?.toString()
304
+ }
305
+
306
+ override fun stopScoAudio(): Boolean {
307
+ if (!super.stopScoAudio()) {
308
+ return false
309
+ }
310
+ mAudioManager.clearCommunicationDevice()
311
+ bluetoothState = State.SCO_DISCONNECTING
312
+ Log.d(TAG, "stopScoAudio done: BT state=$bluetoothState + SCO is on: ${isScoOn()}")
313
+ return true
314
+ }
315
+ }
316
+
317
+ @Suppress("DEPRECATION")
318
+ inner class BluetoothManager23PlusImpl : BluetoothManagerPlatform() {
319
+ private var scoConnectionAttempts: Int = 0
320
+ private var mBluetoothAdapter: BluetoothAdapter? = null
321
+ private var bluetoothHeadset: BluetoothHeadset? = null
322
+ private var bluetoothDevice: BluetoothDevice? = null
323
+ private val handler = Handler(Looper.getMainLooper())
324
+
325
+ private val bluetoothTimeoutRunnable = Runnable { bluetoothTimeout() }
326
+
327
+ private val bluetoothServiceListener: BluetoothProfile.ServiceListener =
328
+ object : BluetoothProfile.ServiceListener {
329
+ override fun onServiceConnected(profile: Int, proxy: BluetoothProfile?) {
330
+ if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
331
+ return
332
+ }
333
+ Log.d(
334
+ TAG, "BluetoothServiceListener.onServiceConnected: BT state=$bluetoothState"
335
+ )
336
+ // Android only supports one connected Bluetooth Headset at a time.
337
+ bluetoothHeadset = proxy as BluetoothHeadset
338
+ updateAudioDeviceState()
339
+ Log.d(
340
+ TAG, "onServiceConnected done: BT state=$bluetoothState"
341
+ )
342
+ }
343
+
344
+ override fun onServiceDisconnected(profile: Int) {
345
+ if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
346
+ return
347
+ }
348
+ Log.d(
349
+ TAG,
350
+ "BluetoothServiceListener.onServiceDisconnected: BT state=$bluetoothState"
351
+ )
352
+ stopScoAudio()
353
+ bluetoothHeadset = null
354
+ bluetoothDevice = null
355
+ bluetoothState = State.HEADSET_UNAVAILABLE
356
+ updateAudioDeviceState()
357
+ Log.d(
358
+ TAG, "onServiceDisconnected done: BT state=$bluetoothState"
359
+ )
360
+ }
361
+
362
+ }
363
+
364
+ private val bluetoothHeadsetReceiver: BroadcastReceiver = object : BroadcastReceiver() {
365
+ override fun onReceive(context: Context?, intent: Intent) {
366
+ if (bluetoothState == State.UNINITIALIZED) {
367
+ return
368
+ }
369
+ val action = intent.action
370
+ // Change in connection state of the Headset profile. Note that the
371
+ // change does not tell us anything about whether we're streaming
372
+ // audio to BT over SCO. Typically received when user turns on a BT
373
+ // headset while audio is active using another audio device.
374
+ if (action == BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED) {
375
+ val state = intent.getIntExtra(
376
+ BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_DISCONNECTED
377
+ )
378
+ Log.d(
379
+ TAG,
380
+ ("BluetoothHeadsetBroadcastReceiver.onReceive: " + "a=ACTION_CONNECTION_STATE_CHANGED, " + "s=" + stateToString(
381
+ state
382
+ ) + ", " + "sb=" + isInitialStickyBroadcast + ", " + "BT state: " + bluetoothState)
383
+ )
384
+ if (state == BluetoothHeadset.STATE_CONNECTED) {
385
+ scoConnectionAttempts = 0
386
+ updateAudioDeviceState()
387
+ } else if (state == BluetoothHeadset.STATE_CONNECTING) {
388
+ // No action needed.
389
+ } else if (state == BluetoothHeadset.STATE_DISCONNECTING) {
390
+ // No action needed.
391
+ } else if (state == BluetoothHeadset.STATE_DISCONNECTED) {
392
+ // Bluetooth is probably powered off during the call.
393
+ stopScoAudio()
394
+ updateAudioDeviceState()
395
+ }
396
+ // Change in the audio (SCO) connection state of the Headset profile.
397
+ // Typically received after call to startScoAudio() has finalized.
398
+ } else if (action == BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED) {
399
+ val state = intent.getIntExtra(
400
+ BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_AUDIO_DISCONNECTED
401
+ )
402
+ Log.d(
403
+ TAG,
404
+ ("BluetoothHeadsetBroadcastReceiver.onReceive: " + "a=ACTION_AUDIO_STATE_CHANGED, " + "s=" + stateToString(
405
+ state
406
+ ) + ", " + "sb=" + isInitialStickyBroadcast + ", " + "BT state: " + bluetoothState)
407
+ )
408
+ if (state == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
409
+ cancelTimer()
410
+ if (bluetoothState == State.SCO_CONNECTING) {
411
+ Log.d(
412
+ TAG, "+++ Bluetooth audio SCO is now connected"
413
+ )
414
+ bluetoothState = State.SCO_CONNECTED
415
+ scoConnectionAttempts = 0
416
+ updateAudioDeviceState()
417
+ } else {
418
+ Log.w(
419
+ TAG, "Unexpected state BluetoothHeadset.STATE_AUDIO_CONNECTED"
420
+ )
421
+ }
422
+ } else if (state == BluetoothHeadset.STATE_AUDIO_CONNECTING) {
423
+ Log.d(
424
+ TAG, "+++ Bluetooth audio SCO is now connecting..."
425
+ )
426
+ } else if (state == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
427
+ Log.d(
428
+ TAG, "+++ Bluetooth audio SCO is now disconnected"
429
+ )
430
+ if (isInitialStickyBroadcast) {
431
+ Log.d(
432
+ TAG, "Ignore STATE_AUDIO_DISCONNECTED initial sticky broadcast."
433
+ )
434
+ return
435
+ }
436
+ updateAudioDeviceState()
437
+ }
438
+ }
439
+ Log.d(
440
+ TAG, "onReceive done: BT state=$bluetoothState"
441
+ )
442
+ }
443
+
444
+ }
445
+
446
+ override fun hasPermission(): Boolean {
447
+ return mReactContext.checkSelfPermission(Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED
448
+ }
449
+
450
+ override fun isScoOn(): Boolean = mAudioManager.isBluetoothScoOn()
451
+
452
+ override fun startScoAudio(): Boolean {
453
+ Log.d(
454
+ TAG,
455
+ ("startSco: BT state=" + bluetoothState + ", " + "attempts: " + scoConnectionAttempts + ", " + "SCO is on: " + isScoOn())
456
+ )
457
+ if (scoConnectionAttempts >= MAX_SCO_CONNECTION_ATTEMPTS) {
458
+ Log.e(TAG, "BT SCO connection fails - no more attempts")
459
+ return false
460
+ }
461
+ if (bluetoothState == State.HEADSET_UNAVAILABLE) {
462
+ Log.e(TAG, "BT SCO connection fails - no headset available")
463
+ return false
464
+ }
465
+
466
+ // The SCO connection establishment can take several seconds, hence we cannot rely on the
467
+ // connection to be available when the method returns but instead register to receive the
468
+ // intent ACTION_SCO_AUDIO_STATE_UPDATED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.
469
+ // Start BT SCO channel and wait for ACTION_AUDIO_STATE_CHANGED.
470
+ Log.d(
471
+ TAG, "Starting Bluetooth SCO and waits for ACTION_AUDIO_STATE_CHANGED..."
472
+ )
473
+ bluetoothState = State.SCO_CONNECTING
474
+ startTimer()
475
+ mAudioManager.startBluetoothSco()
476
+ mAudioManager.setBluetoothScoOn(true)
477
+ scoConnectionAttempts++
478
+ Log.d(
479
+ TAG,
480
+ ("startScoAudio done: BT state=" + bluetoothState + ", " + "SCO is on: " + isScoOn())
481
+ )
482
+ return true
483
+ }
484
+
485
+ @SuppressLint("MissingPermission")
486
+ override fun updateDevice() {
487
+ val currBtHeadset = bluetoothHeadset
488
+ if (bluetoothState == State.UNINITIALIZED || currBtHeadset == null) {
489
+ return
490
+ }
491
+ // Get connected devices for the headset profile. Returns the set of
492
+ // devices which are in state STATE_CONNECTED. The BluetoothDevice class
493
+ // is just a thin wrapper for a Bluetooth hardware address.
494
+ val devices = getFinalConnectedDevices()
495
+ for (device in devices) {
496
+ Log.d(
497
+ TAG,
498
+ ("Connected bluetooth headset: " + "name=" + device.name + ", " + "state=" + stateToString(
499
+ currBtHeadset.getConnectionState(device)
500
+ ))
501
+ )
502
+ }
503
+ if (devices.isEmpty()) {
504
+ bluetoothDevice = null
505
+ bluetoothState = State.HEADSET_UNAVAILABLE
506
+ Log.d(TAG, "No connected bluetooth headset")
507
+ } else {
508
+ // Always use first device in list. Android only supports one device.
509
+ val firstBtDevice = devices[0]
510
+ bluetoothDevice = firstBtDevice
511
+ bluetoothState = State.HEADSET_AVAILABLE
512
+ Log.d(
513
+ TAG,
514
+ ("Connected bluetooth headset: " + "name=" + firstBtDevice.name + ", " + "state=" + stateToString(
515
+ currBtHeadset.getConnectionState(
516
+ bluetoothDevice
517
+ )
518
+ ) + ", SCO audio=" + currBtHeadset.isAudioConnected(
519
+ bluetoothDevice
520
+ ))
521
+ )
522
+ }
523
+
524
+ Log.d(
525
+ TAG, "updateDevice done: BT state=$bluetoothState"
526
+ )
527
+ }
528
+
529
+ @SuppressLint("MissingPermission")
530
+ override fun getDeviceName(): String? {
531
+ return bluetoothDevice?.name
532
+ }
533
+
534
+ @SuppressLint("MissingPermission")
535
+ override fun start(): Boolean {
536
+ if (!super.start()) {
537
+ return false
538
+ }
539
+ val bluetoothManager: BluetoothManager =
540
+ mReactContext.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
541
+ mBluetoothAdapter = bluetoothManager.adapter
542
+ bluetoothHeadset = null
543
+ bluetoothDevice = null
544
+ scoConnectionAttempts = 0
545
+
546
+ // Establish a connection to the HEADSET profile (includes both Bluetooth Headset and
547
+ // Hands-Free) proxy object and install a listener.
548
+ if (!getBluetoothProfileProxy(
549
+ mReactContext, bluetoothServiceListener
550
+ )
551
+ ) {
552
+ Log.e(
553
+ TAG, "BluetoothAdapter.getProfileProxy(HEADSET) failed"
554
+ )
555
+ return false
556
+ }
557
+
558
+ // Register receivers for BluetoothHeadset change notifications.
559
+ val bluetoothHeadsetFilter = IntentFilter()
560
+ // Register receiver for change in connection state of the Headset profile.
561
+ bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
562
+ // Register receiver for change in audio connection state of the Headset profile.
563
+ bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)
564
+ ContextCompat.registerReceiver(
565
+ mReactContext,
566
+ bluetoothHeadsetReceiver,
567
+ bluetoothHeadsetFilter,
568
+ ContextCompat.RECEIVER_NOT_EXPORTED
569
+ )
570
+ bluetoothState = State.HEADSET_UNAVAILABLE
571
+ Log.d(
572
+ TAG, "HEADSET profile state: " + stateToString(
573
+ mBluetoothAdapter?.getProfileConnectionState(
574
+ BluetoothProfile.HEADSET
575
+ ) ?: -1
576
+ )
577
+ )
578
+
579
+ Log.d(TAG, "Bluetooth proxy for headset profile has started")
580
+ Log.d(
581
+ TAG, "start done: BT state=$bluetoothState"
582
+ )
583
+ return true
584
+ }
585
+
586
+ override fun stop(): Boolean {
587
+ if (!super.stop()) {
588
+ return false
589
+ }
590
+ if (mBluetoothAdapter == null) {
591
+ return false
592
+ }
593
+ // Stop BT SCO connection with remote device if needed.
594
+ stopScoAudio()
595
+ try {
596
+ mReactContext.unregisterReceiver(bluetoothHeadsetReceiver)
597
+ bluetoothHeadset?.also {
598
+ mBluetoothAdapter!!.closeProfileProxy(BluetoothProfile.HEADSET, it)
599
+ }
600
+
601
+ } catch (exception: Exception) {
602
+ // The receiver was not registered.
603
+ // There is nothing to do in that case.
604
+ // Everything is fine.
605
+ }
606
+ cancelTimer()
607
+ return true
608
+ }
609
+
610
+ override fun stopScoAudio(): Boolean {
611
+ if (!super.stopScoAudio()) {
612
+ return false
613
+ }
614
+ cancelTimer()
615
+ mAudioManager.stopBluetoothSco()
616
+ mAudioManager.setBluetoothScoOn(false)
617
+
618
+ bluetoothState = State.SCO_DISCONNECTING
619
+ Log.d(
620
+ TAG,
621
+ ("stopScoAudio done: BT state=" + bluetoothState + ", " + "SCO is on: " + isScoOn())
622
+ )
623
+ return true
624
+ }
625
+
626
+ /**
627
+ * Called when start of the BT SCO channel takes too long time. Usually
628
+ * happens when the BT device has been turned on during an ongoing call.
629
+ */
630
+ @SuppressLint("MissingPermission")
631
+ private fun bluetoothTimeout() {
632
+ val btHeadset = bluetoothHeadset
633
+ if (bluetoothState == State.UNINITIALIZED || btHeadset == null) {
634
+ return
635
+ }
636
+
637
+ Log.d(
638
+ TAG,
639
+ ("bluetoothTimeout: BT state=" + bluetoothState + ", " + "attempts: " + scoConnectionAttempts + ", " + "SCO is on: " + isScoOn())
640
+ )
641
+ if (bluetoothState != State.SCO_CONNECTING) {
642
+ return
643
+ }
644
+ // Bluetooth SCO should be connecting; check the latest result.
645
+ var scoConnected = false
646
+ val devices: List<BluetoothDevice> = getFinalConnectedDevices()
647
+ if (devices.isNotEmpty()) {
648
+ bluetoothDevice = devices[0]
649
+ val currBtDevice = bluetoothDevice!!
650
+ if (btHeadset.isAudioConnected(currBtDevice)) {
651
+ Log.d(
652
+ TAG, "SCO connected with " + currBtDevice.name
653
+ )
654
+ scoConnected = true
655
+ } else {
656
+ Log.d(
657
+ TAG, "SCO is not connected with " + currBtDevice.name
658
+ )
659
+ }
660
+
661
+ if (scoConnected) {
662
+ // We thought BT had timed out, but it's actually on; updating state.
663
+ bluetoothState = State.SCO_CONNECTED
664
+ scoConnectionAttempts = 0
665
+ } else {
666
+ // Give up and "cancel" our request by calling stopBluetoothSco().
667
+ Log.w(TAG, "BT failed to connect after timeout")
668
+ stopScoAudio()
669
+ }
670
+ }
671
+ updateAudioDeviceState()
672
+ Log.d(
673
+ TAG, "bluetoothTimeout done: BT state=$bluetoothState"
674
+ )
675
+ }
676
+
677
+ @SuppressLint("MissingPermission")
678
+ private fun getFinalConnectedDevices(): List<BluetoothDevice> {
679
+ val connectedDevices = bluetoothHeadset?.connectedDevices ?: emptyList()
680
+ val finalDevices: MutableList<BluetoothDevice> = ArrayList()
681
+
682
+ Log.d(TAG, "getFinalConnectedDevices: connectedDevices=$connectedDevices")
683
+
684
+ for (device in connectedDevices) {
685
+ val majorClass = device.bluetoothClass.majorDeviceClass
686
+
687
+ if (majorClass == BluetoothClass.Device.Major.AUDIO_VIDEO) {
688
+ Log.d(TAG, "getFinalConnectedDevices: device=${device.name}")
689
+ finalDevices.add(device)
690
+ }
691
+ }
692
+ return finalDevices
693
+ }
694
+
695
+ private fun getBluetoothProfileProxy(
696
+ context: Context?, listener: BluetoothProfile.ServiceListener?
697
+ ): Boolean {
698
+ try {
699
+ return mBluetoothAdapter?.getProfileProxy(
700
+ context,
701
+ listener,
702
+ BluetoothProfile.HEADSET
703
+ ) ?: false
704
+ } catch (e: Exception) {
705
+ Log.e(TAG, "gBPP: hit exception while getting bluetooth profile", e)
706
+ return false
707
+ }
708
+ }
709
+
710
+ /** Starts timer which times out after BLUETOOTH_SCO_TIMEOUT_MS milliseconds. */
711
+ private fun startTimer() {
712
+ Log.d(TAG, "startTimer")
713
+ handler.postDelayed(
714
+ bluetoothTimeoutRunnable, BLUETOOTH_SCO_TIMEOUT_MS.toLong()
715
+ )
716
+ }
717
+
718
+ /** Cancels any outstanding timer tasks. */
719
+ private fun cancelTimer() {
720
+ Log.d(TAG, "cancelTimer")
721
+ handler.removeCallbacks(bluetoothTimeoutRunnable)
722
+ }
723
+ }
724
+
725
+ companion object {
726
+ private val TAG: String =
727
+ StreamInCallManagerModule.TAG + ":" + BluetoothManager::class.java.simpleName.toString()
728
+
729
+ // Timeout interval for starting or stopping audio to a Bluetooth SCO device.
730
+ private const val BLUETOOTH_SCO_TIMEOUT_MS: Int = 6000
731
+
732
+ // Maximum number of SCO connection attempts.
733
+ private const val MAX_SCO_CONNECTION_ATTEMPTS: Int = 10
734
+
735
+ private fun stateToString(state: Int): String {
736
+ return when (state) {
737
+ BluetoothAdapter.STATE_DISCONNECTED -> "DISCONNECTED"
738
+ BluetoothAdapter.STATE_CONNECTED -> "CONNECTED"
739
+ BluetoothAdapter.STATE_CONNECTING -> "CONNECTING"
740
+ BluetoothAdapter.STATE_DISCONNECTING -> "DISCONNECTING"
741
+ BluetoothAdapter.STATE_OFF -> "OFF"
742
+ BluetoothAdapter.STATE_ON -> "ON"
743
+ BluetoothAdapter.STATE_TURNING_OFF -> // Indicates the local Bluetooth adapter is turning off. Local clients should immediately
744
+ // attempt graceful disconnection of any remote links.
745
+ "TURNING_OFF"
746
+
747
+ BluetoothAdapter.STATE_TURNING_ON -> // Indicates the local Bluetooth adapter is turning on. However local clients should wait
748
+ // for STATE_ON before attempting to use the adapter.
749
+ "TURNING_ON"
750
+
751
+ else -> "INVALID"
752
+ }
753
+ }
754
+ }
755
+ }