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

Commit 3c30e625 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I0766618b,I58c19cf9,I5821d922,I2400e404 into tm-qpr-dev

* changes:
  le_audio: Create descriptor for added from storage device
  Remove spare device address log
  Protect group from changing its integrity
  Invert getting first device from group logic
parents 1e815788 4304620e
Loading
Loading
Loading
Loading
+58 −34
Original line number Diff line number Diff line
@@ -448,6 +448,27 @@ public class LeAudioService extends ProfileService {
        return mVolumeControlService.getAudioDeviceGroupVolume(groupId);
    }

    LeAudioDeviceDescriptor createDeviceDescriptor(BluetoothDevice device) {
        LeAudioDeviceDescriptor descriptor = mDeviceDescriptors.get(device);
        if (descriptor == null) {

            // Limit the maximum number of devices to avoid DoS attack
            if (mDeviceDescriptors.size() >= MAX_LE_AUDIO_DEVICES) {
                Log.e(TAG, "Maximum number of LeAudio state machines reached: "
                        + MAX_LE_AUDIO_DEVICES);
                return null;
            }

            mDeviceDescriptors.put(device, new LeAudioDeviceDescriptor());
            descriptor = mDeviceDescriptors.get(device);
            Log.d(TAG, "Created descriptor for device: " + device);
        } else {
            Log.w(TAG, "Device: " + device + ", already exists");
        }

        return descriptor;
    }

    public boolean connect(BluetoothDevice device) {
        if (DBG) {
            Log.d(TAG, "connect(): " + device);
@@ -464,19 +485,10 @@ public class LeAudioService extends ProfileService {
        }

        synchronized (mGroupLock) {
            LeAudioDeviceDescriptor descriptor = mDeviceDescriptors.get(device);
            if (descriptor == null) {

                // Limit the maximum number of devices to avoid DoS attack
                if (mDeviceDescriptors.size() >= MAX_LE_AUDIO_DEVICES) {
                    Log.e(TAG, "Maximum number of LeAudio state machines reached: "
                            + MAX_LE_AUDIO_DEVICES);
            if (createDeviceDescriptor(device) == null) {
                return false;
            }

                mDeviceDescriptors.put(device, new LeAudioDeviceDescriptor());
            }

            LeAudioStateMachine sm = getOrCreateStateMachine(device);
            if (sm == null) {
                Log.e(TAG, "Ignored connect request for " + device + " : no state machine");
@@ -838,7 +850,7 @@ public class LeAudioService extends ProfileService {
        }
        synchronized (mGroupLock) {
            for (LeAudioDeviceDescriptor descriptor : mDeviceDescriptors.values()) {
                if (descriptor.mGroupId.equals(groupId)) {
                if (!descriptor.mGroupId.equals(groupId)) {
                    continue;
                }

@@ -1512,6 +1524,7 @@ public class LeAudioService extends ProfileService {
            int src_audio_location = stackEvent.valueInt4;
            int available_contexts = stackEvent.valueInt5;

            synchronized (mGroupLock) {
                LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
                if (descriptor != null) {
                    if (descriptor.mIsActive) {
@@ -1519,13 +1532,15 @@ public class LeAudioService extends ProfileService {
                                updateActiveDevices(groupId, descriptor.mDirection, direction,
                                descriptor.mIsActive);
                        if (!descriptor.mIsActive) {
                        notifyGroupStatusChanged(groupId, BluetoothLeAudio.GROUP_STATUS_INACTIVE);
                            notifyGroupStatusChanged(groupId,
                                    BluetoothLeAudio.GROUP_STATUS_INACTIVE);
                        }
                    }
                    descriptor.mDirection = direction;
                } else {
                    Log.e(TAG, "no descriptors for group: " + groupId);
                }
            }
        } else if (stackEvent.type == LeAudioStackEvent.EVENT_TYPE_SINK_AUDIO_LOCATION_AVAILABLE) {
            Objects.requireNonNull(stackEvent.device,
                    "Device should never be null, event: " + stackEvent);
@@ -2180,9 +2195,19 @@ public class LeAudioService extends ProfileService {

            LeAudioDeviceDescriptor deviceDescriptor = getDeviceDescriptor(device);
            if (deviceDescriptor == null) {
                Log.e(TAG, "handleGroupNodeAdded: No valid descriptor for device: " + device);
                deviceDescriptor = createDeviceDescriptor(device);
                if (deviceDescriptor == null) {
                    Log.e(TAG, "handleGroupNodeAdded: Can't create descriptor for added from"
                            + " storage device: " + device);
                    return;
                }

                LeAudioStateMachine sm = getOrCreateStateMachine(device);
                if (getOrCreateStateMachine(device) == null) {
                    Log.e(TAG, "Can't get state machine for device: " + device);
                    return;
                }
            }
            deviceDescriptor.mGroupId = groupId;

            LeAudioGroupDescriptor descriptor = mGroupDescriptors.get(groupId);
@@ -2226,6 +2251,7 @@ public class LeAudioService extends ProfileService {
            Log.d(TAG, "Removing device " + device + " grom group " + groupId);
        }

        synchronized (mGroupLock) {
            LeAudioGroupDescriptor groupDescriptor = getGroupDescriptor(groupId);
            if (DBG) {
                Log.d(TAG, "Lost lead device is " + groupDescriptor.mLostLeadDeviceWhileStreaming);
@@ -2234,7 +2260,6 @@ public class LeAudioService extends ProfileService {
                clearLostDevicesWhileStreaming(groupDescriptor);
            }

        synchronized (mGroupLock) {
            LeAudioDeviceDescriptor deviceDescriptor = getDeviceDescriptor(device);
            if (deviceDescriptor == null) {
                Log.e(TAG, "handleGroupNodeRemoved: No valid descriptor for device: " + device);
@@ -3098,7 +3123,6 @@ public class LeAudioService extends ProfileService {
                : mDeviceDescriptors.entrySet()) {
            LeAudioDeviceDescriptor descriptor = entry.getValue();

            ProfileService.println(sb, "  Device: " + entry.getKey());
            descriptor.mStateMachine.dump(sb);
            ProfileService.println(sb, "    mGroupId: " + descriptor.mGroupId);
            ProfileService.println(sb, "    mSinkAudioLocation: " + descriptor.mSinkAudioLocation);