Search in sources :

Example 51 with ScanFilter

use of android.bluetooth.le.ScanFilter in project android_frameworks_base by crdroidandroid.

the class ScanFilterTest method testManufacturerSpecificData.

@SmallTest
public void testManufacturerSpecificData() {
    byte[] setManufacturerData = new byte[] { 0x02, 0x15 };
    int manufacturerId = 0xE0;
    ScanFilter filter = mFilterBuilder.setManufacturerData(manufacturerId, setManufacturerData).build();
    assertTrue("manufacturer data filter fails", filter.matches(mScanResult));
    byte[] emptyData = new byte[0];
    filter = mFilterBuilder.setManufacturerData(manufacturerId, emptyData).build();
    assertTrue("manufacturer data filter fails", filter.matches(mScanResult));
    byte[] prefixData = new byte[] { 0x02 };
    filter = mFilterBuilder.setManufacturerData(manufacturerId, prefixData).build();
    assertTrue("manufacturer data filter fails", filter.matches(mScanResult));
    // Test data mask
    byte[] nonMatchData = new byte[] { 0x02, 0x14 };
    filter = mFilterBuilder.setManufacturerData(manufacturerId, nonMatchData).build();
    assertFalse("manufacturer data filter fails", filter.matches(mScanResult));
    byte[] mask = new byte[] { (byte) 0xFF, (byte) 0x00 };
    filter = mFilterBuilder.setManufacturerData(manufacturerId, nonMatchData, mask).build();
    assertTrue("partial setManufacturerData filter fails", filter.matches(mScanResult));
}
Also used : ScanFilter(android.bluetooth.le.ScanFilter) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 52 with ScanFilter

use of android.bluetooth.le.ScanFilter in project android_frameworks_base by crdroidandroid.

the class ScanFilterTest method testsetServiceUuidFilter.

@SmallTest
public void testsetServiceUuidFilter() {
    ScanFilter filter = mFilterBuilder.setServiceUuid(ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB")).build();
    assertTrue("uuid filter fails", filter.matches(mScanResult));
    filter = mFilterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB")).build();
    assertFalse("uuid filter fails", filter.matches(mScanResult));
    filter = mFilterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB"), ParcelUuid.fromString("FFFFFFF0-FFFF-FFFF-FFFF-FFFFFFFFFFFF")).build();
    assertTrue("uuid filter fails", filter.matches(mScanResult));
}
Also used : ScanFilter(android.bluetooth.le.ScanFilter) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ScanFilter (android.bluetooth.le.ScanFilter)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)30 ParcelUuid (android.os.ParcelUuid)19 ScanSettings (android.bluetooth.le.ScanSettings)11 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)10 ArrayList (java.util.ArrayList)9 RequiresPermission (android.annotation.RequiresPermission)5 TargetApi (android.annotation.TargetApi)5 ScanCallback (android.bluetooth.le.ScanCallback)5 ScanRecord (android.bluetooth.le.ScanRecord)5 ScanResult (android.bluetooth.le.ScanResult)5 Message (android.os.Message)5 Parcel (android.os.Parcel)5 RemoteException (android.os.RemoteException)5 UUID (java.util.UUID)5 NonNull (android.support.annotation.NonNull)3 QueryBuilder (de.greenrobot.dao.query.QueryBuilder)2 BeaconParser (org.altbeacon.beacon.BeaconParser)1