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

Commit 178a3f82 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk Committed by Grzegorz Kolodziejczyk
Browse files

le_audio: Disable Sound Effects for active Broadcast Assistant

While Broadcast Delegator has some source in receive state it may be
receiving broadcast (synced to BIG) or have this source suspended
(ready for/playing unicast stream). Sound Effects causes a unnecessary
delay for suspending Unicast stream, skipping resume for configured
Unicast for Sound Effect improves handover.

Tag: #bug
Bug: 349311566
Bug: 336468573
Test: atest BassClientStateMachineTest
Change-Id: I4811c85feea7636b929524209a1d07f54eb188ae
parent c7ebeb43
Loading
Loading
Loading
Loading
+50 −17
Original line number Diff line number Diff line
@@ -877,9 +877,45 @@ public class BassClientService extends ProfileService {
                && (leAudioService.getActiveDevices().contains(device));
    }

    private boolean isAnyDeviceFromActiveUnicastGroupReceivingBroadcast() {
        return getActiveBroadcastSinks().stream()
                .anyMatch(d -> isDevicePartOfActiveUnicastGroup(d));
    private boolean isEmptyBluetoothDevice(BluetoothDevice device) {
        if (device == null) {
            Log.e(TAG, "Device is null!");
            return true;
        }

        return device.getAddress().equals("00:00:00:00:00:00");
    }

    private boolean hasAnyConnectedDeviceExternalBroadcastSource() {
        for (BluetoothDevice device : getConnectedDevices()) {
            // Check if any connected device has add some source
            if (getAllSources(device).stream()
                    .anyMatch(
                            receiveState ->
                                    (!isEmptyBluetoothDevice(receiveState.getSourceDevice())
                                            && !isLocalBroadcast(receiveState)))) {
                return true;
            }
        }

        return false;
    }

    private void checkAndResetGroupAllowedContextMask() {
        LeAudioService leAudioService = mServiceFactory.getLeAudioService();
        if (leAudioService == null) {
            return;
        }

        if (leaudioAllowedContextMask()) {
            /* Restore allowed context mask for Unicast */
            if (mIsAllowedContextOfActiveGroupModified
                    && !hasAnyConnectedDeviceExternalBroadcastSource()) {
                leAudioService.setActiveGroupAllowedContextMask(
                        BluetoothLeAudio.CONTEXTS_ALL, BluetoothLeAudio.CONTEXTS_ALL);
                mIsAllowedContextOfActiveGroupModified = false;
            }
        }
    }

    private void localNotifyReceiveStateChanged(BluetoothDevice sink) {
@@ -917,16 +953,10 @@ public class BassClientService extends ProfileService {
                leAudioService.activeBroadcastAssistantNotification(false);
            }

            if (leaudioAllowedContextMask()) {
                /* Restore allowed context mask for active device */
                if (mIsAllowedContextOfActiveGroupModified) {
                    if (!isAnyDeviceFromActiveUnicastGroupReceivingBroadcast()) {
                        leAudioService.setActiveGroupAllowedContextMask(
                                BluetoothLeAudio.CONTEXTS_ALL, BluetoothLeAudio.CONTEXTS_ALL);
                    }
                    mIsAllowedContextOfActiveGroupModified = false;
                }
            }
            /* Restore allowed context mask for unicast in case if last connected broadcast
             * delegator device which has external source removes this source
             */
            checkAndResetGroupAllowedContextMask();
        }
    }

@@ -1073,9 +1103,8 @@ public class BassClientService extends ProfileService {
            return false;
        }
        boolean isRoomAvailable = false;
        String emptyBluetoothDevice = "00:00:00:00:00:00";
        for (BluetoothLeBroadcastReceiveState recvState : stateMachine.getAllSources()) {
            if (recvState.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
            if (isEmptyBluetoothDevice(recvState.getSourceDevice())) {
                isRoomAvailable = true;
                break;
            }
@@ -1347,6 +1376,11 @@ public class BassClientService extends ProfileService {
                log("Unbonded " + device + ". Removing state machine");
                removeStateMachine(device);
            }

            /* Restore allowed context mask for unicast in case if last connected broadcast
             * delegator device which has external source disconnectes.
             */
            checkAndResetGroupAllowedContextMask();
        } else if (toState == BluetoothProfile.STATE_CONNECTED) {
            handleReconnectingAudioSharingModeDevice(device);
        }
@@ -2729,8 +2763,7 @@ public class BassClientService extends ProfileService {
            List<BluetoothLeBroadcastReceiveState> recvStates =
                    new ArrayList<BluetoothLeBroadcastReceiveState>();
            for (BluetoothLeBroadcastReceiveState rs : stateMachine.getAllSources()) {
                String emptyBluetoothDevice = "00:00:00:00:00:00";
                if (!rs.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
                if (!isEmptyBluetoothDevice(rs.getSourceDevice())) {
                    recvStates.add(rs);
                }
            }