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

Commit 4ab13f36 authored by Rongxuan Liu's avatar Rongxuan Liu Committed by Automerger Merge Worker
Browse files

Merge "le_audio: Disable Sound Effects for active Broadcast Assistant" into...

Merge "le_audio: Disable Sound Effects for active Broadcast Assistant" into main am: 310cf99d am: 0df804cb

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



Change-Id: I6ecb42a5fa0404f1db259750b6011b0a41ec2d1e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents cb646e4b 0df804cb
Loading
Loading
Loading
Loading
+50 −17
Original line number Original line Diff line number Diff line
@@ -878,9 +878,45 @@ public class BassClientService extends ProfileService {
                && (leAudioService.getActiveDevices().contains(device));
                && (leAudioService.getActiveDevices().contains(device));
    }
    }


    private boolean isAnyDeviceFromActiveUnicastGroupReceivingBroadcast() {
    private boolean isEmptyBluetoothDevice(BluetoothDevice device) {
        return getActiveBroadcastSinks().stream()
        if (device == null) {
                .anyMatch(d -> isDevicePartOfActiveUnicastGroup(d));
            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) {
    private void localNotifyReceiveStateChanged(BluetoothDevice sink) {
@@ -918,16 +954,10 @@ public class BassClientService extends ProfileService {
                leAudioService.activeBroadcastAssistantNotification(false);
                leAudioService.activeBroadcastAssistantNotification(false);
            }
            }


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


@@ -1074,9 +1104,8 @@ public class BassClientService extends ProfileService {
            return false;
            return false;
        }
        }
        boolean isRoomAvailable = false;
        boolean isRoomAvailable = false;
        String emptyBluetoothDevice = "00:00:00:00:00:00";
        for (BluetoothLeBroadcastReceiveState recvState : stateMachine.getAllSources()) {
        for (BluetoothLeBroadcastReceiveState recvState : stateMachine.getAllSources()) {
            if (recvState.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
            if (isEmptyBluetoothDevice(recvState.getSourceDevice())) {
                isRoomAvailable = true;
                isRoomAvailable = true;
                break;
                break;
            }
            }
@@ -1348,6 +1377,11 @@ public class BassClientService extends ProfileService {
                log("Unbonded " + device + ". Removing state machine");
                log("Unbonded " + device + ". Removing state machine");
                removeStateMachine(device);
                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) {
        } else if (toState == BluetoothProfile.STATE_CONNECTED) {
            handleReconnectingAudioSharingModeDevice(device);
            handleReconnectingAudioSharingModeDevice(device);
        }
        }
@@ -2730,8 +2764,7 @@ public class BassClientService extends ProfileService {
            List<BluetoothLeBroadcastReceiveState> recvStates =
            List<BluetoothLeBroadcastReceiveState> recvStates =
                    new ArrayList<BluetoothLeBroadcastReceiveState>();
                    new ArrayList<BluetoothLeBroadcastReceiveState>();
            for (BluetoothLeBroadcastReceiveState rs : stateMachine.getAllSources()) {
            for (BluetoothLeBroadcastReceiveState rs : stateMachine.getAllSources()) {
                String emptyBluetoothDevice = "00:00:00:00:00:00";
                if (!isEmptyBluetoothDevice(rs.getSourceDevice())) {
                if (!rs.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
                    recvStates.add(rs);
                    recvStates.add(rs);
                }
                }
            }
            }