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

Commit 9f2ca846 authored by Michal Belusiak's avatar Michal Belusiak Committed by Michal Belusiak (xWF)
Browse files

Bass: Use checking if broadcast is active instead of synced to BISes

Swap method isAnyReceiverReceivingBroadcast to isAnyReceiverActive where
is check of syncing to PA or BISes instead of check only syncing to BISes.

Method is used only in LeAudioService#isGroupReceivingBroadcast so checking active has more sens as unsyncing from BISes could be unintentional i.e. when music is paused.

Bug: 378615357
Bug: EXEMPT; simple change covered with unit test
Test: atest BassClientServiceTest
Change-Id: Idf2506d072494287c7b113beed2c27222bbbba67
parent a69c2fea
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -4054,16 +4054,14 @@ public class BassClientService extends ProfileService {
    }

    /** Check if any sink receivers are receiving broadcast stream */
    public boolean isAnyReceiverReceivingBroadcast(List<BluetoothDevice> devices) {
    public boolean isAnyReceiverActive(List<BluetoothDevice> devices) {
        for (BluetoothDevice device : devices) {
            for (BluetoothLeBroadcastReceiveState receiveState : getAllSources(device)) {
                for (int i = 0; i < receiveState.getNumSubgroups(); i++) {
                    if (isSyncedToBroadcastStream(receiveState.getBisSyncState().get(i))) {
                if (isReceiverActive(receiveState)) {
                    return true;
                }
            }
        }
        }

        return false;
    }
+1 −1
Original line number Diff line number Diff line
@@ -2939,7 +2939,7 @@ public class LeAudioService extends ProfileService {
            return false;
        }

        return bassClientService.isAnyReceiverReceivingBroadcast(getGroupDevices(groupId));
        return bassClientService.isAnyReceiverActive(getGroupDevices(groupId));
    }

    private void notifyGroupStreamStatusChanged(int groupId, int groupStreamStatus) {
+20 −11
Original line number Diff line number Diff line
@@ -4441,27 +4441,36 @@ public class BassClientServiceTest {
    }

    @Test
    public void testIsAnyReceiverReceivingBroadcast() {
    public void testIsAnyReceiverActive() {
        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        BluetoothLeBroadcastMetadata meta = createBroadcastMetadata(TEST_BROADCAST_ID);
        verifyAddSourceForGroup(meta);
        prepareRemoteSourceState(meta, true, false);
        prepareRemoteSourceState(meta, false, false);

        List<BluetoothDevice> devices = mBassClientService.getConnectedDevices();
        // Verify isAnyReceiverReceivingBroadcast returns false if no BIS synced
        assertThat(mBassClientService.isAnyReceiverReceivingBroadcast(devices)).isFalse();
        // Verify isAnyReceiverActive returns false if no PA and no BIS synced
        assertThat(mBassClientService.isAnyReceiverActive(devices)).isFalse();

        // Update receiver state with BIS sync
        injectRemoteSourceStateChanged(meta, true, true);
        // Update receiver state with PA sync
        injectRemoteSourceStateChanged(meta, true, false);
        BluetoothDevice invalidDevice = TestUtils.getTestDevice(mBluetoothAdapter, 2);
        // Verify isAnyReceiverReceivingBroadcast returns false if invalid device
        expect.that(mBassClientService.isAnyReceiverReceivingBroadcast(List.of(invalidDevice)))
                .isFalse();
        // Verify isAnyReceiverReceivingBroadcast returns true if BIS synced
        expect.that(mBassClientService.isAnyReceiverReceivingBroadcast(devices)).isTrue();
        // Verify isAnyReceiverActive returns false if invalid device
        expect.that(mBassClientService.isAnyReceiverActive(List.of(invalidDevice))).isFalse();
        // Verify isAnyReceiverActive returns true if PA synced
        expect.that(mBassClientService.isAnyReceiverActive(devices)).isTrue();

        // Update receiver state with PA and BIS sync
        injectRemoteSourceStateChanged(meta, true, true);
        // Verify isAnyReceiverActive returns true if PA and BIS synced
        expect.that(mBassClientService.isAnyReceiverActive(devices)).isTrue();

        // Update receiver state with BIS only sync
        injectRemoteSourceStateChanged(meta, false, true);
        // Verify isAnyReceiverActive returns true if BIS only synced
        expect.that(mBassClientService.isAnyReceiverActive(devices)).isTrue();
    }

    @Test