mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Bolster Bluetooth headset detection for Android 11 and older.
This commit is contained in:
@@ -3282,7 +3282,7 @@ public class ConversationParentFragment extends Fragment
|
||||
@Override
|
||||
public void onRecorderStarted() {
|
||||
final AudioManagerCompat audioManager = ApplicationDependencies.getAndroidCallAudioManager();
|
||||
if (audioManager.isBluetoothAvailable()) {
|
||||
if (audioManager.isBluetoothHeadsetAvailable()) {
|
||||
connectToBluetoothAndBeginRecording();
|
||||
} else {
|
||||
Log.d(TAG, "Recording from phone mic because no bluetooth devices were available.");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.webrtc.audio;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioAttributes;
|
||||
@@ -52,11 +54,16 @@ public abstract class AudioManagerCompat {
|
||||
audioManager.stopBluetoothSco();
|
||||
}
|
||||
|
||||
public boolean isBluetoothAvailable() {
|
||||
public boolean isBluetoothHeadsetAvailable() {
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
return audioManager.getAvailableCommunicationDevices().stream().anyMatch(it -> AudioDeviceMapping.fromPlatformType(it.getType()) == SignalAudioManager.AudioDevice.BLUETOOTH);
|
||||
} else {
|
||||
return isBluetoothScoAvailableOffCall();
|
||||
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
return mBluetoothAdapter != null &&
|
||||
mBluetoothAdapter.isEnabled() &&
|
||||
// noinspection MissingPermission
|
||||
mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothAdapter.STATE_CONNECTED &&
|
||||
isBluetoothScoAvailableOffCall();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user