Skip to content

Commit

Permalink
Race conditions in changing states (#147)
Browse files Browse the repository at this point in the history
* Fix race conditions in changing states

* Update CHANGELOG.md [skip ci]
  • Loading branch information
ocarevs authored Mar 20, 2023
1 parent 961771c commit c6d9f3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

### 1.1.8 (Mar 6, 2023)
### 1.1.8 (Mar 17, 2023)

Bug Fixes

- Fixed issue where some Samsung Galaxy devices (S9, S21) would not route audio through USB headset when MODE_IN_COMMUNICATION is set.
- Fixed issue where IllegalStateException would be thrown when activating selected AudioDevice shortly after starting AudioSwitch.
- Fixed issue where after stopping AudioSwitch while having an active Bluetooth device would result in permanent audio focus gain.

### 1.1.7 (Feb 21, 2023)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ class AudioSwitch {
audioDeviceChangeListener = listener
when (state) {
STOPPED -> {
state = STARTED
enumerateDevices()
bluetoothHeadsetManager?.start(bluetoothDeviceConnectionListener)
wiredHeadsetReceiver.start(wiredDeviceConnectionListener)
state = STARTED
}
else -> {
logger.d(TAG, "Redundant start() invocation while already in the started or activated state")
Expand Down Expand Up @@ -197,13 +197,13 @@ class AudioSwitch {
fun activate() {
when (state) {
STARTED -> {
state = ACTIVATED
audioDeviceManager.cacheAudioState()

// Always set mute to false for WebRTC
audioDeviceManager.mute(false)
audioDeviceManager.setAudioFocus()
selectedDevice?.let { activate(it) }
state = ACTIVATED
}
ACTIVATED -> selectedDevice?.let { activate(it) }
STOPPED -> throw IllegalStateException()
Expand All @@ -217,11 +217,11 @@ class AudioSwitch {
fun deactivate() {
when (state) {
ACTIVATED -> {
state = STARTED
bluetoothHeadsetManager?.deactivate()

// Restore stored audio state
audioDeviceManager.restoreAudioState()
state = STARTED
}
STARTED, STOPPED -> {
}
Expand Down Expand Up @@ -358,10 +358,10 @@ class AudioSwitch {
} ?: false

private fun closeListeners() {
state = STOPPED
bluetoothHeadsetManager?.stop()
wiredHeadsetReceiver.stop()
audioDeviceChangeListener = null
state = STOPPED
}

companion object {
Expand Down

0 comments on commit c6d9f3b

Please sign in to comment.