Bolster Bluetooth headset detection for Android 11 and older.
This commit is contained in:
parent
05edc715ef
commit
83e84228f5
2 changed files with 10 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue