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

Commit a4b93f83 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk
Browse files

Protect group from changing its integrity

This CL adds missing synchronized blocks where are operations on group.

Tag: #feature
Bug: 261362580
Test: atest LeAudioServiceTest
Change-Id: I5821d922cd4834e6b19e79d31df7f47f82eb8eef
Merged-In: I5821d922cd4834e6b19e79d31df7f47f82eb8eef
(cherry picked from commit 33b43ec2)
parent 7cc1bc02
Loading
Loading
Loading
Loading
+22 −19
Original line number Original line Diff line number Diff line
@@ -1512,6 +1512,7 @@ public class LeAudioService extends ProfileService {
            int src_audio_location = stackEvent.valueInt4;
            int src_audio_location = stackEvent.valueInt4;
            int available_contexts = stackEvent.valueInt5;
            int available_contexts = stackEvent.valueInt5;


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


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


        synchronized (mGroupLock) {
            LeAudioDeviceDescriptor deviceDescriptor = getDeviceDescriptor(device);
            LeAudioDeviceDescriptor deviceDescriptor = getDeviceDescriptor(device);
            if (deviceDescriptor == null) {
            if (deviceDescriptor == null) {
                Log.e(TAG, "handleGroupNodeRemoved: No valid descriptor for device: " + device);
                Log.e(TAG, "handleGroupNodeRemoved: No valid descriptor for device: " + device);