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

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

AudioService : BtHleper: fix late BT profile service connection

When a Bluetooth profile service connection callback is received,
more than one device can be already active for some profiles with both
input and output devices (LE Audio, Headset...).

Bug: 316857273
Test: turn BT ON/OFF with LE headset connected.
Change-Id: Ie6b2c257a0ebd61133426eff347ecde72ecd12a3
parent 3708fe21
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1992,7 +1992,7 @@ public class AudioDeviceInventory {
            // TODO: return;
        } else {
            AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                    "A2DP source device addr=" + Utils.anonymizeBluetoothAddress(address)
                    "A2DP sink device addr=" + Utils.anonymizeBluetoothAddress(address)
                            + " now available").printLog(TAG));
        }

+15 −11
Original line number Diff line number Diff line
@@ -634,17 +634,18 @@ public class BtHelper {
            return;
        }
        List<BluetoothDevice> activeDevices = adapter.getActiveDevices(profile);
        if (activeDevices.isEmpty() || activeDevices.get(0) == null) {
            return;
        BluetoothProfileConnectionInfo bpci = new BluetoothProfileConnectionInfo(profile);
        for (BluetoothDevice device : activeDevices) {
            if (device == null) {
                continue;
            }
            AudioDeviceBroker.BtDeviceChangedData data = new AudioDeviceBroker.BtDeviceChangedData(
                activeDevices.get(0), null, new BluetoothProfileConnectionInfo(profile),
                "mBluetoothProfileServiceListener");
        AudioDeviceBroker.BtDeviceInfo info =
                mDeviceBroker.createBtDeviceInfo(data, activeDevices.get(0),
                        BluetoothProfile.STATE_CONNECTED);
                    device, null, bpci, "mBluetoothProfileServiceListener");
            AudioDeviceBroker.BtDeviceInfo info = mDeviceBroker.createBtDeviceInfo(
                    data, device, BluetoothProfile.STATE_CONNECTED);
            mDeviceBroker.postBluetoothActiveDevice(info, 0 /* delay */);
        }
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
@@ -678,8 +679,11 @@ public class BtHelper {
        if (adapter != null) {
            List<BluetoothDevice> activeDevices =
                    adapter.getActiveDevices(BluetoothProfile.HEADSET);
            if (activeDevices.size() > 0 && activeDevices.get(0) != null) {
                onSetBtScoActiveDevice(activeDevices.get(0));
            for (BluetoothDevice device : activeDevices) {
                if (device == null) {
                    continue;
                }
                onSetBtScoActiveDevice(device);
            }
        } else {
            Log.e(TAG, "onHeadsetProfileConnected: Null BluetoothAdapter");