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

Commit 0d784f7d authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

[le audio] Update mBroadcastDescriptors before notifying by callbacks

Broadcast application might rely on getAllBroadcastMetadata() to check the active broadcasts.
There would be race conditions that we're notifying the clients before updating the mBroadcastDescriptors for getAllBroadcastMetadata().
We should notify by callbacks after updating the metadata.

This change only applied to le audio broadcast feature.
no-op, only sequence change.

Bug: 317395992
Bug: 316005152
Test: atest LeAudioServiceTest
Test: manual test with le audio broadcast audio sharing to confirm
start/stop broadcast has no issue

Change-Id: I6e6357facd64a1d688a3a43b0004ef69f883ff20
parent 1a30ed09
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -2538,10 +2538,8 @@ public class LeAudioService extends ProfileService {
            boolean success = stackEvent.valueBool1;
            if (success) {
                Log.d(TAG, "Broadcast broadcastId: " + broadcastId + " created.");
                notifyBroadcastStarted(broadcastId, BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);

                mBroadcastDescriptors.put(broadcastId, new LeAudioBroadcastDescriptor());

                notifyBroadcastStarted(broadcastId, BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);
                // Start sending the actual stream
                startBroadcast(broadcastId);

@@ -2560,23 +2558,22 @@ public class LeAudioService extends ProfileService {

        } else if (stackEvent.type == LeAudioStackEvent.EVENT_TYPE_BROADCAST_DESTROYED) {
            Integer broadcastId = stackEvent.valueInt1;
            LeAudioBroadcastDescriptor descriptor = mBroadcastDescriptors.get(broadcastId);
            if (descriptor == null) {
                Log.e(
                        TAG,
                        "EVENT_TYPE_BROADCAST_DESTROYED: No valid descriptor for broadcastId: "
                                + broadcastId);
            } else {
                mBroadcastDescriptors.remove(broadcastId);
            }

            // TODO: Improve reason reporting or extend the native stack event with reason code
            notifyOnBroadcastStopped(broadcastId, BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);

            BassClientService bassClientService = getBassClientService();
            if (bassClientService != null) {
                bassClientService.stopReceiversSourceSynchronization(broadcastId);
            }

            LeAudioBroadcastDescriptor descriptor = mBroadcastDescriptors.get(broadcastId);
            if (descriptor == null) {
                Log.e(TAG, "EVENT_TYPE_BROADCAST_DESTROYED: No valid descriptor for broadcastId: "
                        + broadcastId);
                return;
            }
            mBroadcastDescriptors.remove(broadcastId);

        } else if (stackEvent.type == LeAudioStackEvent.EVENT_TYPE_BROADCAST_STATE) {
            int broadcastId = stackEvent.valueInt1;
            int state = stackEvent.valueInt2;