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

Commit 85fe38dc authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

LeAudio: Remove inconsistency in BluetoothAdatper.getActiveDevices

UI expects to get all the devices which are in the active group.
On the other side, LeAudioService return OUT/IN active device which was
not used by the application.
With this patch, BluetoothLeAudio.getActiveDevices() will return devices
which belongs to the Active group, and first element is the Lead device.

Bug: 248188703
Test: atest BluetoothInstrumentationTests
Tag: #feature
Merged-In: I84a5d5871f20eed5ef0a07291c8c28787043d095
Change-Id: I84a5d5871f20eed5ef0a07291c8c28787043d095
(cherry picked from commit 7e35f013)
parent edcfbcf3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4234,8 +4234,8 @@ public class AdapterService extends Service {
                Log.e(TAG, "getActiveDevices: LeAudioService is null");
                } else {
                    activeDevices = mLeAudioService.getActiveDevices();
                    Log.i(TAG, "getActiveDevices: LeAudio devices: Out["
                            + activeDevices.get(0) + "] - In[" + activeDevices.get(1) + "]");
                    Log.i(TAG, "getActiveDevices: LeAudio devices: Lead["
                            + activeDevices.get(0) + "] - member_1[" + activeDevices.get(1) + "]");
                }
                break;
            default:
+20 −5
Original line number Diff line number Diff line
@@ -995,11 +995,11 @@ public class LeAudioService extends ProfileService {
     * Get the active LE audio 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.
     * which belongs to the group, represents the active LE audio group - it is called
     * Lead device.
     * 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.
     * @return List of active group members. First element is a Lead device.
     */
    public List<BluetoothDevice> getActiveDevices() {
        if (DBG) {
@@ -1013,8 +1013,23 @@ public class LeAudioService extends ProfileService {
        if (currentlyActiveGroupId == LE_AUDIO_GROUP_ID_INVALID) {
            return activeDevices;
        }
        activeDevices.set(0, mActiveAudioOutDevice);
        activeDevices.set(1, mActiveAudioInDevice);

        BluetoothDevice leadDevice = getConnectedGroupLeadDevice(currentlyActiveGroupId);
        activeDevices.set(0, leadDevice);

        int i = 1;
        for (BluetoothDevice dev : getGroupDevices(currentlyActiveGroupId)) {
            if (Objects.equals(dev, leadDevice)) {
                continue;
            }
            if (i == 1) {
                /* Already has a spot for first member */
                activeDevices.set(i++, dev);
            } else {
                /* Extend list with other members */
                activeDevices.add(dev);
            }
        }
        return activeDevices;
    }