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

Commit d0e8bb0d authored by Sarvesh Kalwit's avatar Sarvesh Kalwit
Browse files

Fix empty data mask detection

The ScanFilter class also denotes no-op data masks as a single 0 byte.
Update the MSFT Advertisement Monitor creation logic to handle this
case.

Bug: 360391998
Bug: 365787977
Flag: com.android.bluetooth.flags.le_scan_msft_support
Test: atest BluetoothInstrumentationTests:ScanManagerTest
Change-Id: Icb36acf9c050b95097da6d846e264161e2a97c6a
parent 5a8a8a3d
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ class MsftAdvMonitor {
        mMonitor.rssi_sampling_period = RSSI_SAMPLING_PERIOD;
        mMonitor.condition_type = MSFT_CONDITION_TYPE_PATTERNS;

        if (filter.getServiceDataUuid() != null && filter.getServiceDataMask() == null) {
        if (filter.getServiceDataUuid() != null && dataMaskIsEmpty(filter.getServiceDataMask())) {
            Pattern pattern = new Pattern();
            pattern.ad_type = (byte) 0x16; // Bluetooth Core Spec Part A, Section 1
            pattern.start_byte = FILTER_PATTERN_START_POSITION;
@@ -86,8 +86,7 @@ class MsftAdvMonitor {
            mPatterns.add(pattern);
        } else if (filter.getAdvertisingData() != null
                && filter.getAdvertisingData().length != 0
                && (filter.getAdvertisingDataMask() == null
                        || filter.getAdvertisingDataMask().length == 0)) {
                && dataMaskIsEmpty(filter.getAdvertisingDataMask())) {
            Pattern pattern = new Pattern();
            pattern.ad_type = (byte) filter.getAdvertisingDataType();
            pattern.start_byte = FILTER_PATTERN_START_POSITION;
@@ -112,4 +111,10 @@ class MsftAdvMonitor {
    Address getAddress() {
        return mAddress;
    }

    private boolean dataMaskIsEmpty(byte[] mask) {
        if (mask == null || mask.length == 0) return true;
        if (mask.length == 1 && mask[0] == 0) return true;
        return false;
    }
}