mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Handle bluetooth permission crash during calls.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user