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

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

bass_client: Enable source monitoring only for external broadcast

There is no need to enable source stream direction for unicast.

Tag: #Bug
Bug: 329172203
Bug: 339612732
Flag: com.android.bluetooth.flags.leaudio_use_audio_mode_listener
Test: atest BassClientServiceTest#testHandleUnicastSourceStreamStatusChange
Change-Id: Ib4ef31e120b40b01bdade6e05b496b3fa546e412
parent dde70384
Loading
Loading
Loading
Loading
+32 −8
Original line number Original line Diff line number Diff line
@@ -757,7 +757,8 @@ public class BassClientService extends ProfileService {
            return;
            return;
        }
        }


        boolean isAssistantActive = isAnyReceiverReceivingBroadcast(getConnectedDevices());
        boolean isAssistantActive =
                areReceiversReceivingOnlyExternalBroadcast(getConnectedDevices());


        if (isAssistantActive) {
        if (isAssistantActive) {
            /* Assistant become active */
            /* Assistant become active */
@@ -2948,7 +2949,7 @@ public class BassClientService extends ProfileService {
        mUnicastSourceStreamStatus = Optional.of(status);
        mUnicastSourceStreamStatus = Optional.of(status);


        if (status == STATUS_LOCAL_STREAM_REQUESTED) {
        if (status == STATUS_LOCAL_STREAM_REQUESTED) {
            if (isAnyReceiverReceivingBroadcast(getConnectedDevices())) {
            if (areReceiversReceivingOnlyExternalBroadcast(getConnectedDevices())) {
                if (leaudioBroadcastAssistantPeripheralEntrustment()) {
                if (leaudioBroadcastAssistantPeripheralEntrustment()) {
                    cacheSuspendingSources(BassConstants.INVALID_BROADCAST_ID);
                    cacheSuspendingSources(BassConstants.INVALID_BROADCAST_ID);
                } else {
                } else {
@@ -2985,20 +2986,43 @@ public class BassClientService extends ProfileService {
            for (BluetoothLeBroadcastReceiveState receiveState : getAllSources(device)) {
            for (BluetoothLeBroadcastReceiveState receiveState : getAllSources(device)) {
                for (int i = 0; i < receiveState.getNumSubgroups(); i++) {
                for (int i = 0; i < receiveState.getNumSubgroups(); i++) {
                    Long syncState = receiveState.getBisSyncState().get(i);
                    Long syncState = receiveState.getBisSyncState().get(i);
                    /* Not synced to BIS of failed to sync to BIG */
                    /* Synced to BIS */
                    if (syncState == BassConstants.BIS_SYNC_NOT_SYNC_TO_BIS
                    if (syncState != BassConstants.BIS_SYNC_NOT_SYNC_TO_BIS
                            || syncState == BassConstants.BIS_SYNC_FAILED_SYNC_TO_BIG) {
                            && syncState != BassConstants.BIS_SYNC_FAILED_SYNC_TO_BIG) {
                        continue;
                    }

                        return true;
                        return true;
                    }
                    }
                }
                }
            }
            }
        }


        return false;
        return false;
    }
    }


    /** Check if any sink receivers are receiving broadcast stream */
    public boolean areReceiversReceivingOnlyExternalBroadcast(List<BluetoothDevice> devices) {
        boolean isReceivingExternalBroadcast = false;

        for (BluetoothDevice device : devices) {
            for (BluetoothLeBroadcastReceiveState receiveState : getAllSources(device)) {
                for (int i = 0; i < receiveState.getNumSubgroups(); i++) {
                    Long syncState = receiveState.getBisSyncState().get(i);
                    /* Synced to BIS */
                    if (syncState != BassConstants.BIS_SYNC_NOT_SYNC_TO_BIS
                            && syncState != BassConstants.BIS_SYNC_FAILED_SYNC_TO_BIG) {
                        if (isLocalBroadcast(receiveState)) {
                            return false;
                        } else {
                            isReceivingExternalBroadcast = true;
                        }
                    }

                }
            }
        }

        return isReceivingExternalBroadcast;
    }

    /** Get the active broadcast sink devices receiving broadcast stream */
    /** Get the active broadcast sink devices receiving broadcast stream */
    public List<BluetoothDevice> getActiveBroadcastSinks() {
    public List<BluetoothDevice> getActiveBroadcastSinks() {
        List<BluetoothDevice> activeSinks = new ArrayList<>();
        List<BluetoothDevice> activeSinks = new ArrayList<>();
+6 −0
Original line number Original line Diff line number Diff line
@@ -2645,6 +2645,12 @@ public class BassClientServiceTest {
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        BluetoothLeBroadcastMetadata meta = createBroadcastMetadata(TEST_BROADCAST_ID);
        BluetoothLeBroadcastMetadata meta = createBroadcastMetadata(TEST_BROADCAST_ID);

        /* Fake external broadcast - no Broadcast Metadata from LE Audio service */
        doReturn(new ArrayList<BluetoothLeBroadcastMetadata>())
                .when(mLeAudioService)
                .getAllBroadcastMetadata();

        verifyAddSourceForGroup(meta);
        verifyAddSourceForGroup(meta);
        for (BassClientStateMachine sm: mStateMachines.values()) {
        for (BassClientStateMachine sm: mStateMachines.values()) {
            if (sm.getDevice().equals(mCurrentDevice)) {
            if (sm.getDevice().equals(mCurrentDevice)) {