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

Commit 6cca360b authored by Jack He's avatar Jack He Committed by Gerrit Code Review
Browse files

Merge changes I81d13f2c,Ic2773277

* changes:
  BluetoothLeAudio: Fix missing group id for device.
  BluetoothLeAudio: Return early from getLeAudioConnectedDevices
parents bb4f9ae4 7885ebc9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -214,6 +214,10 @@ public class BluetoothDeviceManager {
            // Let's get devices which are a group leaders
            ArrayList<BluetoothDevice> devices = new ArrayList<>();

            if (mGroupsByDevice.isEmpty() || mBluetoothLeAudioService == null) {
                return devices;
            }

            for (LinkedHashMap.Entry<BluetoothDevice, Integer> entry : mGroupsByDevice.entrySet()) {
               if (Objects.equals(entry.getKey(),
                        mBluetoothLeAudioService.getConnectedGroupLeadDevice(entry.getValue()))) {
@@ -330,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() {