Skip to content

Commit

Permalink
fix(Android): Exception raised on bluetooth receiver unregistration.
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed Aug 26, 2024
1 parent b822123 commit 96240e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion record_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.2.6
* fix: Improve amplitude computation.
* fix: java.lang.IllegalStateException: Failed to stop the muxer
* fix: java.lang.IllegalStateException: Failed to stop the muxer.
* fix: Exception raised on bluetooth receiver unregistration.
* chore: Upgrade to latest AGP.

## 1.2.5
* fix: Applying effects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ internal class RecorderWrapper(

private fun maybeStopBluetooth() {
bluetoothReceiver?.removeListener(this)
bluetoothReceiver?.unregister()

if (bluetoothReceiver?.hasListeners() != true) {
bluetoothReceiver?.unregister()
}
}

override fun onBlScoConnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BluetoothReceiver(
private val listeners = HashSet<BluetoothScoListener>()
private val devices = HashSet<AudioDeviceInfo>()
private var audioDeviceCallback: AudioDeviceCallback? = null
private var mRegistered: Boolean = false

init {
filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
Expand All @@ -34,6 +35,7 @@ class BluetoothReceiver(

fun register() {
context.registerReceiver(this, filter)
mRegistered = true

audioDeviceCallback = object : AudioDeviceCallback() {
override fun onAudioDevicesAdded(addedDevices: Array<AudioDeviceInfo>) {
Expand Down Expand Up @@ -71,7 +73,11 @@ class BluetoothReceiver(
}

listeners.clear()
context.unregisterReceiver(this)

if (mRegistered) {
context.unregisterReceiver(this)
mRegistered = false
}
}

fun addListener(listener: BluetoothScoListener) {
Expand All @@ -90,6 +96,7 @@ class BluetoothReceiver(
}
}

@Suppress("DEPRECATION")
fun startBluetooth(): Boolean {
if (!audioManager.isBluetoothScoAvailableOffCall) {
return false
Expand All @@ -102,6 +109,7 @@ class BluetoothReceiver(
return true
}

@Suppress("DEPRECATION")
fun stopBluetooth() {
if (audioManager.isBluetoothScoOn()) {
audioManager.stopBluetoothSco()
Expand Down

0 comments on commit 96240e3

Please sign in to comment.