Handle bluetooth permission crash during calls.

This commit is contained in:
Cody Henthorne
2022-05-13 12:39:23 -04:00
committed by GitHub
parent 97d41fdd1e
commit a3bbf944e5
10 changed files with 65 additions and 2 deletions

View File

@@ -98,6 +98,7 @@ sealed class SignalAudioManager(protected val context: Context, protected val ev
interface EventListener {
@JvmSuppressWildcards
fun onAudioDeviceChanged(activeDevice: AudioDevice, devices: Set<AudioDevice>)
fun onBluetoothPermissionDenied()
}
}
@@ -121,6 +122,7 @@ class FullSignalAudioManager(context: Context, eventListener: EventListener?) :
private var audioDevices: MutableSet<AudioDevice> = mutableSetOf()
private var defaultAudioDevice: AudioDevice = AudioDevice.EARPIECE
private var userSelectedAudioDevice: AudioDevice = AudioDevice.NONE
private var previousBluetoothState: SignalBluetoothManager.State? = null
private var savedAudioMode = AudioManager.MODE_INVALID
private var savedIsSpeakerPhoneOn = false
@@ -294,6 +296,11 @@ class FullSignalAudioManager(context: Context, eventListener: EventListener?) :
autoSwitchToBluetooth = false
}
if (previousBluetoothState != null && previousBluetoothState != SignalBluetoothManager.State.PERMISSION_DENIED && signalBluetoothManager.state == SignalBluetoothManager.State.PERMISSION_DENIED) {
eventListener?.onBluetoothPermissionDenied()
}
previousBluetoothState = signalBluetoothManager.state
val newAudioDevice: AudioDevice = when {
audioDevices.contains(userSelectedAudioDevice) -> userSelectedAudioDevice
audioDevices.contains(defaultAudioDevice) -> defaultAudioDevice

View File

@@ -162,7 +162,16 @@ class SignalBluetoothManager(
return
}
val devices: List<BluetoothDevice>? = bluetoothHeadset?.connectedDevices
val devices: List<BluetoothDevice>?
try {
devices = bluetoothHeadset?.connectedDevices
} catch (e: SecurityException) {
Log.w(TAG, "Unable to get bluetooth devices", e)
stop()
state = State.PERMISSION_DENIED
return
}
if (devices == null || devices.isEmpty()) {
bluetoothDevice = null
state = State.UNAVAILABLE
@@ -320,6 +329,7 @@ class SignalBluetoothManager(
DISCONNECTING,
CONNECTING,
CONNECTED,
PERMISSION_DENIED,
ERROR;
fun shouldUpdate(): Boolean {