From aacad78cdb3fbd405ddcaeed2367bd518b5b871e Mon Sep 17 00:00:00 2001 From: Nicholas Tinsley Date: Thu, 1 Jun 2023 12:19:59 -0400 Subject: [PATCH] Delete redundant Bluetooth voice note codepath. Added some additional logging, as well. --- .../securesms/audio/BluetoothVoiceNoteUtil.kt | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/BluetoothVoiceNoteUtil.kt b/app/src/main/java/org/thoughtcrime/securesms/audio/BluetoothVoiceNoteUtil.kt index a91a0f3155..c6821088b2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/BluetoothVoiceNoteUtil.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/BluetoothVoiceNoteUtil.kt @@ -81,46 +81,31 @@ private class BluetoothVoiceNoteUtilLegacy(val context: Context, val listener: ( private var hasWarnedAboutBluetooth = false init { - if (Build.VERSION.SDK_INT < 31) { - audioHandler.post { - signalBluetoothManager.start() - Log.d(TAG, "Bluetooth manager started.") - } + audioHandler.post { + signalBluetoothManager.start() + Log.d(TAG, "Bluetooth manager started.") } } override fun connectBluetoothScoConnection() { - if (Build.VERSION.SDK_INT >= 31) { - val audioManager = ApplicationDependencies.getAndroidCallAudioManager() - val device: AudioDeviceInfo? = audioManager.connectedBluetoothDevice - if (device != null) { - val result: Boolean = audioManager.setCommunicationDevice(device) - if (result) { - Log.d(TAG, "Successfully set Bluetooth device as active communication device.") - } else { - Log.d(TAG, "Found Bluetooth device but failed to set it as active communication device.") - } - } else { - Log.d(TAG, "Could not find Bluetooth device in list of communications devices, falling back to current input.") + audioHandler.post { + if (signalBluetoothManager.state.shouldUpdate()) { + Log.d(TAG, "Bluetooth manager updating devices.") + signalBluetoothManager.updateDevice() } - listener() - } else { - audioHandler.post { - if (signalBluetoothManager.state.shouldUpdate()) { - signalBluetoothManager.updateDevice() - } - val currentState = signalBluetoothManager.state - if (currentState == SignalBluetoothManager.State.AVAILABLE) { - signalBluetoothManager.startScoAudio() - } else { - Log.d(TAG, "Recording from phone mic because bluetooth state was " + currentState + ", not " + SignalBluetoothManager.State.AVAILABLE) - uiThreadHandler.post { - if (currentState == SignalBluetoothManager.State.PERMISSION_DENIED && !hasWarnedAboutBluetooth) { - bluetoothPermissionDeniedHandler() - hasWarnedAboutBluetooth = true - } - listener() + val currentState = signalBluetoothManager.state + if (currentState == SignalBluetoothManager.State.AVAILABLE) { + Log.d(TAG, "Bluetooth manager state is AVAILABLE. Starting SCO connection.") + signalBluetoothManager.startScoAudio() + } else { + Log.d(TAG, "Recording from phone mic because bluetooth state was " + currentState + ", not " + SignalBluetoothManager.State.AVAILABLE) + uiThreadHandler.post { + if (currentState == SignalBluetoothManager.State.PERMISSION_DENIED && !hasWarnedAboutBluetooth) { + Log.d(TAG, "Warning about Bluetooth permissions.") + bluetoothPermissionDeniedHandler() + hasWarnedAboutBluetooth = true } + listener() } } }