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

Commit 6c32ec55 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge changes I3ccf5a20,I4105ac0d,I6925de36,I1219e1b0 am: baad81d7 am: f47f30b2

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

Change-Id: I967c6cc3497b10bafc97a2e1319d7caeeeec3e46
parents bdb018cc f47f30b2
Loading
Loading
Loading
Loading
+46 −10
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -110,11 +110,11 @@ public class LeAudioService extends ProfileService {
        public Integer mActiveContexts;
    }

    private final Map<Integer, LeAudioGroupDescriptor> mGroupDescriptors = new HashMap<>();
    private final Map<BluetoothDevice, LeAudioStateMachine> mStateMachines = new HashMap<>();
    private final Map<Integer, LeAudioGroupDescriptor> mGroupDescriptors = new LinkedHashMap<>();
    private final Map<BluetoothDevice, LeAudioStateMachine> mStateMachines = new LinkedHashMap<>();

    private final Map<BluetoothDevice, Integer> mDeviceGroupIdMap = new ConcurrentHashMap<>();
    private int mActiveDeviceGroupId = LE_AUDIO_GROUP_ID_INVALID;

    private final int mContextSupportingInputAudio =
            BluetoothLeAudio.CONTEXT_TYPE_COMMUNICATION |
            BluetoothLeAudio.CONTEXT_TYPE_MAN_MACHINE;
@@ -363,6 +363,15 @@ 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;
    }

    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        ArrayList<BluetoothDevice> devices = new ArrayList<>();
        if (states == null) {
@@ -500,6 +509,16 @@ public class LeAudioService extends ProfileService {
        return supportedAudioDirections;
    }

    private Integer getActiveGroupId() {
        for (Map.Entry<Integer, LeAudioGroupDescriptor> entry : mGroupDescriptors.entrySet()) {
            LeAudioGroupDescriptor descriptor = entry.getValue();
            if (descriptor.mIsActive) {
                return entry.getKey();
            }
        }
        return LE_AUDIO_GROUP_ID_INVALID;
    }

    private BluetoothDevice getFirstDeviceFromGroup(Integer groupId) {
        if (groupId != LE_AUDIO_GROUP_ID_INVALID) {
            for(Map.Entry<BluetoothDevice, Integer> entry : mDeviceGroupIdMap.entrySet()) {
@@ -677,19 +696,19 @@ public class LeAudioService extends ProfileService {
            groupId = mDeviceGroupIdMap.getOrDefault(device, LE_AUDIO_GROUP_ID_INVALID);
        }

        int currentlyActiveGroupId = getActiveGroupId();
        if (DBG) {
            Log.d(TAG, "setActiveDeviceGroup = " + groupId +
                       ", mActiveDeviceGroupId = " + mActiveDeviceGroupId +
                       ", currentlyActiveGroupId = " + currentlyActiveGroupId +
                       ", device: " + device);
        }

        if (groupId == mActiveDeviceGroupId) {
        if (groupId == currentlyActiveGroupId) {
            Log.w(TAG, "group is already active");
            return;
        }

        mLeAudioNativeInterface.groupSetActive(groupId);
        mActiveDeviceGroupId = groupId;
    }

    /**
@@ -733,7 +752,8 @@ public class LeAudioService extends ProfileService {
        activeDevices.add(null);
        activeDevices.add(null);
        synchronized (mStateMachines) {
            if (mActiveDeviceGroupId == LE_AUDIO_GROUP_ID_INVALID) {
            int currentlyActiveGroupId = getActiveGroupId();
            if (currentlyActiveGroupId == LE_AUDIO_GROUP_ID_INVALID) {
                return activeDevices;
            }
                activeDevices.add(0, mActiveAudioOutDevice);
@@ -1215,14 +1235,15 @@ public class LeAudioService extends ProfileService {
            Log.d(TAG, "SetVolume " + volume);
        }

        if (mActiveDeviceGroupId == LE_AUDIO_GROUP_ID_INVALID) {
        int currentlyActiveGroupId = getActiveGroupId();
        if (currentlyActiveGroupId == LE_AUDIO_GROUP_ID_INVALID) {
            Log.e(TAG, "There is no active group ");
            return;
        }

        VolumeControlService service = mServiceFactory.getVolumeControlService();
        if (service != null) {
            service.setVolumeGroup(mActiveDeviceGroupId, volume);
            service.setVolumeGroup(currentlyActiveGroupId, volume);
        }
    }

@@ -1298,6 +1319,21 @@ public class LeAudioService extends ProfileService {
            }
        }

        @Override
        public void getConnectedGroupLeadDevices(AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                LeAudioService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>(0);
                if (service != null) {
                    defaultValue = service.getConnectedGroupLeadDevices();
                }
                receiver.send(defaultValue);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void getDevicesMatchingConnectionStates(int[] states,
                AttributionSource source, SynchronousResultReceiver receiver) {
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ oneway interface IBluetoothLeAudio {
    void setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    void getConnectedGroupLeadDevices(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")

    /* Same value as bluetooth::groups::kGroupUnknown */
    const int LE_AUDIO_GROUP_ID_INVALID = -1;
+1 −1
Original line number Diff line number Diff line
@@ -441,7 +441,7 @@ bool LeAudioClientAudioSink::Start(
  }

  LOG(INFO) << __func__ << ": Le Audio Sink Open, bit rate: "
            << codec_configuration.bits_per_sample
            << int{codec_configuration.bits_per_sample}
            << ", num channels: " << int{codec_configuration.num_channels}
            << ", sample rate: " << codec_configuration.sample_rate
            << ", data interval: " << codec_configuration.data_interval_us;