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

Commit 7885ebc9 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

BluetoothLeAudio: Fix missing group id for device.

Telecom has registered callbacks for BluetoothLeAudio and in this way it
tracs devices being added/removed to/from group.
However, it could happen that callback is registered after device has
been added to the group. In such a case, Telecom will not be aware about
the group for the device. This patch fixes it.

Issue was visible when LeAudio device is already bonded and Bluetooth is
enabled.

Bug: 150670922
Bug: 227562754
Test: atest TelecomUnitTests

Change-Id: I81d13f2c629eb774cc277692da9e9f1bb31a0779
parent bf860e6f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -334,6 +334,14 @@ public class BluetoothDeviceManager {
                    Log.w(this, "LE audio service null when receiving device added broadcast");
                    return;
                }
                /* Check if group is known. */
                if (!mGroupsByDevice.containsKey(device)) {
                    int groupId = mBluetoothLeAudioService.getGroupId(device);
                    /* If it is not yet assigned, then it will be provided in the callback */
                    if (groupId != BluetoothLeAudio.GROUP_ID_INVALID) {
                        mGroupsByDevice.put(device, groupId);
                    }
                }
                targetDeviceMap = mLeAudioDevicesByAddress;
            } else if (deviceType == DEVICE_TYPE_HEARING_AID) {
                if (mBluetoothHearingAid == null) {
+39 −0
Original line number Diff line number Diff line
@@ -195,6 +195,45 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    @SmallTest
    @Test
    public void testLeAudioMissedGroupCallbackBeforeConnected() {
        /* This should be called on connection state changed */
        when(mBluetoothLeAudio.getGroupId(device5)).thenReturn(1);
        when(mBluetoothLeAudio.getGroupId(device6)).thenReturn(1);

        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device5,
                        BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device6,
                        BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
        when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5);
        assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
        assertEquals(1, mBluetoothDeviceManager.getUniqueConnectedDevices().size());
    }

    @SmallTest
    @Test
    public void testLeAudioGroupAvailableBeforeConnect() {
        /* Device is known (e.g. from storage) */
        leAudioCallbacksTest.getValue().onGroupNodeAdded(device5, 1);
        leAudioCallbacksTest.getValue().onGroupNodeAdded(device6, 1);
        /* Make sure getGroupId is not called for known devices */
        verify(mBluetoothLeAudio, never()).getGroupId(device5);
        verify(mBluetoothLeAudio, never()).getGroupId(device6);

        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device5,
                        BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device6,
                        BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
        when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5);
        assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
        assertEquals(1, mBluetoothDeviceManager.getUniqueConnectedDevices().size());
    }

    @SmallTest
    @Test
    public void testHearingAidDedup() {