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

Commit b999ff39 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

LeAudioService: Improve getActiveDevice

We should just return one Output and one Input.
Bug: 150670922
Tag: #feature
Test: atest BluetoothInstrumentationTests
Sponsor: jpawlowski@

Change-Id: Iafaa178735cb39485138c54b577ed5d3af22690f
parent a60f73f6
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -770,27 +770,28 @@ public class LeAudioService extends ProfileService {
    }

    /**
     * Get the connected physical LeAudio devices that are active.
     * Get the active LE audio device.
     *
     * @return the list of active devices.
     * Note: When LE audio group is active, one of the Bluetooth device address
     * which belongs to the group, represents the active LE audio group.
     * Internally, this address is translated to LE audio group id.
     *
     * @return List of two elements. First element is an active output device
     *         and second element is an active input device.
     */
    public List<BluetoothDevice> getActiveDevices() {
        if (DBG) {
            Log.d(TAG, "getActiveDevices");
        }
        ArrayList<BluetoothDevice> activeDevices = new ArrayList<>();
        activeDevices.add(null);
        activeDevices.add(null);
        synchronized (mStateMachines) {
            if (mActiveDeviceGroupId == LE_AUDIO_GROUP_ID_INVALID) {
                return activeDevices;
            }
            for (BluetoothDevice device : mDeviceGroupIdMap.keySet()) {
                if (getConnectionState(device) != BluetoothProfile.STATE_CONNECTED) {
                    continue;
                }
                if (mDeviceGroupIdMap.get(device) == Integer.valueOf(mActiveDeviceGroupId)) {
                    activeDevices.add(device);
                }
            }
                activeDevices.add(0, mActiveAudioOutDevice);
                activeDevices.add(1, mActiveAudioInDevice);
        }
        return activeDevices;
    }
+25 −3
Original line number Diff line number Diff line
@@ -940,10 +940,12 @@ public class LeAudioServiceTest {
    @Test
    public void testGetActiveDevices() {
        int groupId = 1;
        int direction = 1;
        int snkAudioLocation = 3;
        int srcAudioLocation = 4;
        int availableContexts = 5;
        int nodeStatus = LeAudioStackEvent.GROUP_NODE_ADDED;

        // No active device
        assertThat(mService.getActiveDevices().isEmpty()).isTrue();
        int groupStatus = LeAudioStackEvent.GROUP_STATUS_ACTIVE;

        // Single active device
        doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class));
@@ -958,6 +960,26 @@ public class LeAudioServiceTest {
        mService.messageFromNative(nodeStatusChangedEvent);

        assertThat(mService.setActiveDevice(mSingleDevice)).isTrue();

        //Add location support
        LeAudioStackEvent audioConfChangedEvent =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
        audioConfChangedEvent.device = mSingleDevice;
        audioConfChangedEvent.valueInt1 = direction;
        audioConfChangedEvent.valueInt2 = groupId;
        audioConfChangedEvent.valueInt3 = snkAudioLocation;
        audioConfChangedEvent.valueInt4 = srcAudioLocation;
        audioConfChangedEvent.valueInt5 = availableContexts;
        mService.messageFromNative(audioConfChangedEvent);

        //Set group and device as active
        LeAudioStackEvent groupStatusChangedEvent =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_STATUS_CHANGED);
        groupStatusChangedEvent.device = mSingleDevice;
        groupStatusChangedEvent.valueInt1 = groupId;
        groupStatusChangedEvent.valueInt2 = groupStatus;
        mService.messageFromNative(groupStatusChangedEvent);

        assertThat(mService.getActiveDevices().contains(mSingleDevice)).isTrue();
    }