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

Commit 6e76f356 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "leaudio: Add method to get device group lead" am: 673f938b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1948605

Change-Id: Icef9bf9b7b4d8b857250ca717ff500d06c780649
parents cd15d2b6 673f938b
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
@@ -458,6 +458,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;