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

Commit 42f37e1c authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Rahul Sabnis
Browse files

leaudio: Add method to get device group lead

When Le Audio group is active in the system, it is represented by one
group member which becames Active Device.
With this patch, we want to expose group lead device which will be used
as an Active Device for connected group.

This is needed e.g. by telecom so it knows, which devices should be
presented in the Dialer for each Le Audio group.

Bug: 150670922
Tag: #feature
Test: build
Sponsor: jpawlowski@
Change-Id: I401ef3ceaeb334b35697dd88e2c1a9b1d5d2eac9
parent d796637e
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -364,13 +364,8 @@ public class LeAudioService extends ProfileService {
        }
    }

    public List<BluetoothDevice> getConnectedGroupLeadDevices() {
        List<BluetoothDevice> devices = new ArrayList<>();
        for (Map.Entry<Integer, LeAudioGroupDescriptor> entry : mGroupDescriptors.entrySet()) {
            Integer groupId = entry.getKey();
            devices.add(getFirstDeviceFromGroup(groupId));
        }
        return devices;
    public BluetoothDevice getConnectedGroupLeadDevice(int groupId) {
        return getFirstDeviceFromGroup(groupId);
    }

    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
@@ -1321,13 +1316,13 @@ public class LeAudioService extends ProfileService {
        }

        @Override
        public void getConnectedGroupLeadDevices(AttributionSource source,
        public void getConnectedGroupLeadDevice(int groupId, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                LeAudioService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>(0);
                BluetoothDevice defaultValue = null;
                if (service != null) {
                    defaultValue = service.getConnectedGroupLeadDevices();
                    defaultValue = service.getConnectedGroupLeadDevice(groupId);
                }
                receiver.send(defaultValue);
            } catch (RuntimeException e) {
+39 −0
Original line number Diff line number Diff line
@@ -450,6 +450,45 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
        return defaultValue;
    }

    /**
     * Get lead device for a group.
     *
     * Lead device is the device that can be used as an active device in the system.
     * Active devices points to the Audio Device for the Le Audio group.
     * This method returns a list of Lead devices for all the connected LE Audio
     * groups and those devices should be used in the setActiveDevice() method by other parts
     * of the system, which wants to setActive a particular Le Audio Group.
     *
     * Note: getActiveDevice() returns the Lead device for the currently active LE Audio group.
     * Note: When lead device gets disconnected, there will be new lead device for the group.
     *
     * @param groupId The group id.
     * @return group lead device.
     */
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public @Nullable BluetoothDevice getConnectedGroupLeadDevice(int groupId) {
        if (VDBG) log("getConnectedGroupLeadDevice()");
        final IBluetoothLeAudio service = getService();
        final BluetoothDevice defaultValue = null;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (mAdapter.isEnabled()) {
            try {
                final SynchronousResultReceiver<BluetoothDevice> recv =
                        new SynchronousResultReceiver();
                service.getConnectedGroupLeadDevice(groupId, mAttributionSource, recv);
                return Attributable.setAttributionSource(
                        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue),
                        mAttributionSource);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
        }
        return defaultValue;
    }

    /**
     * {@inheritDoc}
     */
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ oneway interface IBluetoothLeAudio {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void getConnectedGroupLeadDevices(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    void getConnectedGroupLeadDevice(int groupId, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);

    /* Same value as bluetooth::groups::kGroupUnknown */
    const int LE_AUDIO_GROUP_ID_INVALID = -1;