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

Commit 64fd9c43 authored by Michal Belusiak's avatar Michal Belusiak
Browse files

BASS: Add periodic adv parse retries on bad scanRecord

That allow to try parse again periodic advertising report.
Update unit for such scenarios.
Update unit tests for cache removal.

Bug: 342549843
Bug: 333691526
Test: atest BassClientServiceTest
Change-Id: I2312f8e55ff7b60a4d90cb475d05eb4a5c8cdda6
parent cdb71885
Loading
Loading
Loading
Loading
+38 −21
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class BassClientService extends ProfileService {
    private static final String TAG = BassClientService.class.getSimpleName();
    private static final int MAX_BASS_CLIENT_STATE_MACHINES = 10;
    private static final int MAX_ACTIVE_SYNCED_SOURCES_NUM = 4;
    private static final int MAX_BIS_DISCOVERY_TRIES_NUM = 5;

    private static final int STATUS_LOCAL_STREAM_REQUESTED = 0;
    private static final int STATUS_LOCAL_STREAM_STREAMING = 1;
@@ -132,7 +133,7 @@ public class BassClientService extends ProfileService {
            new HashMap<>();
    private final PriorityQueue<SourceSyncRequest> mSourceSyncRequestsQueue =
            new PriorityQueue<>(sSourceSyncRequestComparator);
    private final Map<Integer, Boolean> mFirstTimeBisDiscoveryMap = new HashMap<Integer, Boolean>();
    private final Map<Integer, Integer> mBisDiscoveryCounterMap = new HashMap<Integer, Integer>();
    private final List<AddSourceData> mPendingSourcesToAdd = new ArrayList<AddSourceData>();

    private final Map<BluetoothDevice, List<Pair<Integer, Object>>> mPendingGroupOp =
@@ -1774,7 +1775,7 @@ public class BassClientService extends ProfileService {
        cancelActiveSync(null);
        mActiveSyncedSources.clear();
        mPeriodicAdvCallbacksMap.clear();
        mFirstTimeBisDiscoveryMap.clear();
        mBisDiscoveryCounterMap.clear();

        mSyncHandleToDeviceMap.clear();
        mSyncHandleToBaseDataMap.clear();
@@ -1849,7 +1850,7 @@ public class BassClientService extends ProfileService {
                        mPeriodicAdvCallbacksMap.remove(BassConstants.INVALID_SYNC_HANDLE);
                    }
                }
                mFirstTimeBisDiscoveryMap.put(syncHandle, true);
                mBisDiscoveryCounterMap.put(syncHandle, MAX_BIS_DISCOVERY_TRIES_NUM);

                synchronized (mPendingSourcesToAdd) {
                    Iterator<AddSourceData> iterator = mPendingSourcesToAdd.iterator();
@@ -1878,26 +1879,34 @@ public class BassClientService extends ProfileService {

        @Override
        public void onPeriodicAdvertisingReport(PeriodicAdvertisingReport report) {
            log("onPeriodicAdvertisingReport");
            Boolean first = mFirstTimeBisDiscoveryMap.get(report.getSyncHandle());
            int syncHandle = report.getSyncHandle();
            log("onPeriodicAdvertisingReport " + syncHandle);
            Integer bisCounter = mBisDiscoveryCounterMap.get(syncHandle);

            // Parse the BIS indices from report's service data
            if (first != null && first.booleanValue()) {
                parseScanRecord(report.getSyncHandle(), report.getData());
                mFirstTimeBisDiscoveryMap.put(report.getSyncHandle(), false);
            if (bisCounter != null && bisCounter != 0) {
                if (parseScanRecord(syncHandle, report.getData())) {
                    mBisDiscoveryCounterMap.put(syncHandle, 0);
                } else {
                    bisCounter--;
                    mBisDiscoveryCounterMap.put(syncHandle, bisCounter);
                    if (bisCounter == 0) {
                        cancelActiveSync(syncHandle);
                    }
                }
            }
        }

        @Override
        public void onSyncLost(int syncHandle) {
            log("OnSyncLost " + syncHandle);
            if (leaudioBroadcastMonitorSourceSyncStatus()) {
            int broadcastId = getBroadcastIdForSyncHandle(syncHandle);
            log("OnSyncLost: syncHandle=" + syncHandle + ", broadcastID=" + broadcastId);
            if (leaudioBroadcastMonitorSourceSyncStatus()) {
                if (broadcastId != BassConstants.INVALID_BROADCAST_ID) {
                    log("Notify broadcast source lost, broadcast id: " + broadcastId);
                    mCallbacks.notifySourceLost(broadcastId);
                }
            }
            int broadcastId = getBroadcastIdForSyncHandle(syncHandle);
            clearAllDataForSyncHandle(syncHandle);
            // Clear from cache to make possible sync again
            mCachedBroadcasts.remove(broadcastId);
@@ -1947,7 +1956,7 @@ public class BassClientService extends ProfileService {
        removeActiveSyncedSource(syncHandle);
        mPeriodicAdvCallbacksMap.remove(syncHandle);
        mSyncHandleToBaseDataMap.remove(syncHandle);
        mFirstTimeBisDiscoveryMap.remove(syncHandle);
        mBisDiscoveryCounterMap.remove(syncHandle);
        BluetoothDevice srcDevice = getDeviceForSyncHandle(syncHandle);
        mSyncHandleToDeviceMap.remove(syncHandle);
        int broadcastId = getBroadcastIdForSyncHandle(syncHandle);
@@ -2101,20 +2110,28 @@ public class BassClientService extends ProfileService {
        return true;
    }

    void parseBaseData(int syncHandle, byte[] serviceData) {
    boolean parseBaseData(int syncHandle, byte[] serviceData) {
        log("parseBaseData" + Arrays.toString(serviceData));
        BaseData base = BaseData.parseBaseData(serviceData);
        if (base != null) {
            updateBase(syncHandle, base);
            base.print();
            return true;
        } else {
            Log.e(TAG, "Seems BASE is not in parsable format");
            cancelActiveSync(syncHandle);
        }
        return false;
    }

    void parseScanRecord(int syncHandle, ScanRecord record) {
        log("parseScanRecord: " + record);
    boolean parseScanRecord(int syncHandle, ScanRecord record) {
        int broadcastId = getBroadcastIdForSyncHandle(syncHandle);
        log(
                "parseScanRecord: syncHandle="
                        + syncHandle
                        + ", broadcastID="
                        + broadcastId
                        + ", record="
                        + record);
        Map<ParcelUuid, byte[]> bmsAdvDataMap = record.getServiceData();
        if (bmsAdvDataMap != null) {
            for (Map.Entry<ParcelUuid, byte[]> entry : bmsAdvDataMap.entrySet()) {
@@ -2127,11 +2144,11 @@ public class BassClientService extends ProfileService {
        }
        byte[] advData = record.getServiceData(BassConstants.BASIC_AUDIO_UUID);
        if (advData != null) {
            parseBaseData(syncHandle, advData);
            return parseBaseData(syncHandle, advData);
        } else {
            Log.e(TAG, "No service data in Scan record");
            cancelActiveSync(syncHandle);
        }
        return false;
    }

    private String checkAndParseBroadcastName(ScanRecord record) {
+380 −1
Original line number Diff line number Diff line
@@ -2077,6 +2077,38 @@ public class BassClientServiceTest {
                        any(), any(), anyInt(), anyInt(), any(), any());
    }

    @Test
    public void testSyncEstablished_statusFailed() {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_EXTRACT_PERIODIC_SCANNER_FROM_STATE_MACHINE);

        prepareConnectedDeviceGroup();
        startSearchingForSources();

        // First scanResult
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());

        // Finish select with failed status
        BassClientService.PACallback callback = mBassClientService.new PACallback();
        callback.onSyncEstablished(
                TEST_SYNC_HANDLE,
                mSourceDevice,
                TEST_ADVERTISER_SID,
                0,
                200,
                BluetoothGatt.GATT_FAILURE);

        // Could try to sync again
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
    }

    @Test
    public void testSelectSource_wrongPublicBroadcastUUID() {
        mSetFlagsRule.enableFlags(
@@ -3877,6 +3909,10 @@ public class BassClientServiceTest {
        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
@@ -3927,6 +3963,23 @@ public class BassClientServiceTest {
                        TEST_SYNC_HANDLE, 0, 0, 0, ScanRecord.parseFromBytes(scanRecord));

        BassClientService.PACallback callback = mBassClientService.new PACallback();

        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);

        // Not canceled, not updated base
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);
        inOrder.verify(mMethodProxy, never())
                .periodicAdvertisingManagerUnregisterSync(any(), any());

        callback.onPeriodicAdvertisingReport(report);

        // Canceled, not updated base
@@ -3937,7 +3990,109 @@ public class BassClientServiceTest {
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(BassConstants.INVALID_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);
        verify(mMethodProxy).periodicAdvertisingManagerUnregisterSync(any(), any());
        inOrder.verify(mMethodProxy).periodicAdvertisingManagerUnregisterSync(any(), any());
    }

    @Test
    public void onPeriodicAdvertisingReport_wrongBaseData_cancelActiveSync() {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_EXTRACT_PERIODIC_SCANNER_FROM_STATE_MACHINE);
        mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS);

        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);

        byte[] scanRecord =
                new byte[] {
                    (byte) 0x02,
                    (byte) 0x01,
                    (byte) 0x1a, // advertising flags
                    (byte) 0x05,
                    (byte) 0x02,
                    (byte) 0x51,
                    (byte) 0x18,
                    (byte) 0x0a,
                    (byte) 0x11, // 16 bit service uuids
                    (byte) 0x04,
                    (byte) 0x09,
                    (byte) 0x50,
                    (byte) 0x65,
                    (byte) 0x64, // name
                    (byte) 0x02,
                    (byte) 0x0A,
                    (byte) 0xec, // tx power level
                    (byte) 0x19,
                    (byte) 0x16,
                    (byte) 0x51,
                    (byte) 0x18, // service data (base data with 18 bytes)
                    // LEVEL 1
                    (byte) 0x01,
                    (byte) 0x02,
                    (byte) 0x03, // presentationDelay
                    (byte) 0x01, // numSubGroups
                    // LEVEL 3
                    (byte) 0x04, // index
                    (byte) 0x03, // codecConfigLength
                    (byte) 0x02,
                    (byte) 'B',
                    (byte) 'C', // codecConfigInfo
                    (byte) 0x05,
                    (byte) 0xff,
                    (byte) 0xe0,
                    (byte) 0x00,
                    (byte) 0x02,
                    (byte) 0x15, // manufacturer specific data
                    (byte) 0x03,
                    (byte) 0x50,
                    (byte) 0x01,
                    (byte) 0x02, // an unknown data type won't cause trouble
                };
        PeriodicAdvertisingReport report =
                new PeriodicAdvertisingReport(
                        TEST_SYNC_HANDLE, 0, 0, 0, ScanRecord.parseFromBytes(scanRecord));

        BassClientService.PACallback callback = mBassClientService.new PACallback();

        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);
        callback.onPeriodicAdvertisingReport(report);

        // Not canceled, not updated base
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);
        inOrder.verify(mMethodProxy, never())
                .periodicAdvertisingManagerUnregisterSync(any(), any());

        callback.onPeriodicAdvertisingReport(report);

        // Canceled, not updated base
        assertThat(mBassClientService.getActiveSyncedSources()).isEmpty();
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE))
                .isFalse();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE)).isEqualTo(null);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(BassConstants.INVALID_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);
        inOrder.verify(mMethodProxy).periodicAdvertisingManagerUnregisterSync(any(), any());
    }

    @Test
@@ -3949,6 +4104,10 @@ public class BassClientServiceTest {
        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
@@ -4031,6 +4190,216 @@ public class BassClientServiceTest {
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isNotEqualTo(null);
        inOrder.verify(mMethodProxy, never())
                .periodicAdvertisingManagerUnregisterSync(any(), any());
    }

    @Test
    public void onPeriodicAdvertisingReport_updateBaseAfterWrongBaseData() {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_EXTRACT_PERIODIC_SCANNER_FROM_STATE_MACHINE);
        mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS);

        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);

        byte[] scanRecordNoBaseData =
                new byte[] {
                    0x02,
                    0x01,
                    0x1a, // advertising flags
                    0x05,
                    0x02,
                    0x0b,
                    0x11,
                    0x0a,
                    0x11, // 16 bit service uuids
                    0x04,
                    0x09,
                    0x50,
                    0x65,
                    0x64, // name
                    0x02,
                    0x0A,
                    (byte) 0xec, // tx power level
                    0x05,
                    0x16,
                    0x0b,
                    0x11,
                    0x50,
                    0x64, // service data
                    0x05,
                    (byte) 0xff,
                    (byte) 0xe0,
                    0x00,
                    0x02,
                    0x15, // manufacturer specific data
                    0x03,
                    0x50,
                    0x01,
                    0x02, // an unknown data type won't cause trouble
                };

        byte[] scanRecordWrongBaseData =
                new byte[] {
                    (byte) 0x02,
                    (byte) 0x01,
                    (byte) 0x1a, // advertising flags
                    (byte) 0x05,
                    (byte) 0x02,
                    (byte) 0x51,
                    (byte) 0x18,
                    (byte) 0x0a,
                    (byte) 0x11, // 16 bit service uuids
                    (byte) 0x04,
                    (byte) 0x09,
                    (byte) 0x50,
                    (byte) 0x65,
                    (byte) 0x64, // name
                    (byte) 0x02,
                    (byte) 0x0A,
                    (byte) 0xec, // tx power level
                    (byte) 0x19,
                    (byte) 0x16,
                    (byte) 0x51,
                    (byte) 0x18, // service data (base data with 18 bytes)
                    // LEVEL 1
                    (byte) 0x01,
                    (byte) 0x02,
                    (byte) 0x03, // presentationDelay
                    (byte) 0x01, // numSubGroups
                    // LEVEL 3
                    (byte) 0x04, // index
                    (byte) 0x03, // codecConfigLength
                    (byte) 0x02,
                    (byte) 'B',
                    (byte) 'C', // codecConfigInfo
                    (byte) 0x05,
                    (byte) 0xff,
                    (byte) 0xe0,
                    (byte) 0x00,
                    (byte) 0x02,
                    (byte) 0x15, // manufacturer specific data
                    (byte) 0x03,
                    (byte) 0x50,
                    (byte) 0x01,
                    (byte) 0x02, // an unknown data type won't cause trouble
                };

        byte[] scanRecordOk =
                new byte[] {
                    (byte) 0x02,
                    (byte) 0x01,
                    (byte) 0x1a, // advertising flags
                    (byte) 0x05,
                    (byte) 0x02,
                    (byte) 0x51,
                    (byte) 0x18,
                    (byte) 0x0a,
                    (byte) 0x11, // 16 bit service uuids
                    (byte) 0x04,
                    (byte) 0x09,
                    (byte) 0x50,
                    (byte) 0x65,
                    (byte) 0x64, // name
                    (byte) 0x02,
                    (byte) 0x0A,
                    (byte) 0xec, // tx power level
                    (byte) 0x19,
                    (byte) 0x16,
                    (byte) 0x51,
                    (byte) 0x18, // service data (base data with 18 bytes)
                    // LEVEL 1
                    (byte) 0x01,
                    (byte) 0x02,
                    (byte) 0x03, // presentationDelay
                    (byte) 0x01, // numSubGroups
                    // LEVEL 2
                    (byte) 0x01, // numSubGroups
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00, // UNKNOWN_CODEC
                    (byte) 0x02, // codecConfigLength
                    (byte) 0x01,
                    (byte) 'A', // codecConfigInfo
                    (byte) 0x03, // metaDataLength
                    (byte) 0x06,
                    (byte) 0x07,
                    (byte) 0x08, // metaData
                    // LEVEL 3
                    (byte) 0x04, // index
                    (byte) 0x03, // codecConfigLength
                    (byte) 0x02,
                    (byte) 'B',
                    (byte) 'C', // codecConfigInfo
                    (byte) 0x05,
                    (byte) 0xff,
                    (byte) 0xe0,
                    (byte) 0x00,
                    (byte) 0x02,
                    (byte) 0x15, // manufacturer specific data
                    (byte) 0x03,
                    (byte) 0x50,
                    (byte) 0x01,
                    (byte) 0x02, // an unknown data type won't cause trouble
                };

        BassClientService.PACallback callback = mBassClientService.new PACallback();

        PeriodicAdvertisingReport report =
                new PeriodicAdvertisingReport(
                        TEST_SYNC_HANDLE, 0, 0, 0, ScanRecord.parseFromBytes(scanRecordNoBaseData));
        callback.onPeriodicAdvertisingReport(report);
        report =
                new PeriodicAdvertisingReport(
                        TEST_SYNC_HANDLE,
                        0,
                        0,
                        0,
                        ScanRecord.parseFromBytes(scanRecordWrongBaseData));
        callback.onPeriodicAdvertisingReport(report);

        // Not canceled, not updated base
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isEqualTo(null);
        inOrder.verify(mMethodProxy, never())
                .periodicAdvertisingManagerUnregisterSync(any(), any());

        report =
                new PeriodicAdvertisingReport(
                        TEST_SYNC_HANDLE, 0, 0, 0, ScanRecord.parseFromBytes(scanRecordOk));
        callback.onPeriodicAdvertisingReport(report);

        // Not canceled, updated base
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(mSourceDevice);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(TEST_BROADCAST_ID);
        assertThat(mBassClientService.getBase(TEST_SYNC_HANDLE)).isNotEqualTo(null);
        inOrder.verify(mMethodProxy, never())
                .periodicAdvertisingManagerUnregisterSync(any(), any());
    }

    @Test
@@ -4285,6 +4654,10 @@ public class BassClientServiceTest {
        prepareConnectedDeviceGroup();
        startSearchingForSources();
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        InOrder inOrder = inOrder(mMethodProxy);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
        onSyncEstablished(mSourceDevice, TEST_SYNC_HANDLE);
        assertThat(mBassClientService.getActiveSyncedSources().size()).isEqualTo(1);
        assertThat(mBassClientService.getActiveSyncedSources().contains(TEST_SYNC_HANDLE)).isTrue();
@@ -4310,5 +4683,11 @@ public class BassClientServiceTest {
        assertThat(mBassClientService.getDeviceForSyncHandle(TEST_SYNC_HANDLE)).isEqualTo(null);
        assertThat(mBassClientService.getBroadcastIdForSyncHandle(TEST_SYNC_HANDLE))
                .isEqualTo(BassConstants.INVALID_BROADCAST_ID);

        // Could try to sync again
        onScanResult(mSourceDevice, TEST_BROADCAST_ID);
        inOrder.verify(mMethodProxy)
                .periodicAdvertisingManagerRegisterSync(
                        any(), any(), anyInt(), anyInt(), any(), any());
    }
}
+2 −2

File changed.

Contains only whitespace changes.