Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de679fe3 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioService BtHelper: fix Bluetooth Headset to audio device mapping

Fix BtHelper.getTypeFromProfile() to return a refined audio device type
for HEADSET profile, consistent with BtHelper.getHeadsetAudioDevice()

Bug: 420508724
Test: repro steps in bug
Flag: android.media.audio.sco_managed_by_audio
Change-Id: I5847b95128cc9b31184cda0e30b35ddc1bd93383
parent 8bfe8a87
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1039,7 +1039,8 @@ public class AudioDeviceBroker {

    /*package*/ static BtDeviceInfo createBtDeviceInfo(@NonNull BtDeviceChangedData d,
            @NonNull BluetoothDevice device, int state) {
        int audioDevice = BtHelper.getTypeFromProfile(d.mInfo.getProfile(), d.mInfo.isLeOutput());
        int audioDevice = BtHelper.getTypeFromProfile(
                d.mInfo.getProfile(), d.mInfo.isLeOutput(), device);
        return new BtDeviceInfo(d, device, state, audioDevice, AudioSystem.AUDIO_FORMAT_DEFAULT);
    }

+2 −1
Original line number Diff line number Diff line
@@ -991,7 +991,8 @@ public class AudioDeviceInventory {
                "onBluetoothDeviceConfigChange addr=" + address
                    + " event=" + BtHelper.deviceEventToString(event)));

        int deviceType = BtHelper.getTypeFromProfile(btInfo.mProfile, btInfo.mIsLeOutput);
        int deviceType = BtHelper.getTypeFromProfile(
                btInfo.mProfile, btInfo.mIsLeOutput, btDevice);

        synchronized (mDevicesLock) {
            if (mDeviceBroker.hasScheduledA2dpConnection(btDevice, btInfo.mProfile)) {
+3 −2
Original line number Diff line number Diff line
@@ -1298,7 +1298,8 @@ public class BtHelper {
        return 0; // 0 is not a valid profile
    }

    /*package */ static int getTypeFromProfile(int profile, boolean isLeOutput) {
    /*package */ static int getTypeFromProfile(
            int profile, boolean isLeOutput, BluetoothDevice device) {
        switch (profile) {
            case BluetoothProfile.A2DP_SINK:
                return AudioSystem.DEVICE_IN_BLUETOOTH_A2DP;
@@ -1315,7 +1316,7 @@ public class BtHelper {
            case BluetoothProfile.LE_AUDIO_BROADCAST:
                return AudioSystem.DEVICE_OUT_BLE_BROADCAST;
            case BluetoothProfile.HEADSET:
                return AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
                return btHeadsetDeviceToAudioDevice(device).getInternalType();
            default:
                throw new IllegalArgumentException("Invalid profile " + profile);
        }