Search in sources :

Example 41 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class ScanRecordTest method testParser.

@SmallTest
public void testParser() {
    byte[] scanRecord = new byte[] { // advertising flags
    0x02, // advertising flags
    0x01, // advertising flags
    0x1a, // 16 bit service uuids
    0x05, // 16 bit service uuids
    0x02, // 16 bit service uuids
    0x0b, // 16 bit service uuids
    0x11, // 16 bit service uuids
    0x0a, // 16 bit service uuids
    0x11, // name
    0x04, // name
    0x09, // name
    0x50, // name
    0x65, // name
    0x64, // tx power level
    0x02, // tx power level
    0x0A, // tx power level
    (byte) 0xec, // service data
    0x05, // service data
    0x16, // service data
    0x0b, // service data
    0x11, // service data
    0x50, // service data
    0x64, // manufacturer specific data
    0x05, // manufacturer specific data
    (byte) 0xff, // manufacturer specific data
    (byte) 0xe0, // manufacturer specific data
    0x00, // manufacturer specific data
    0x02, // manufacturer specific data
    0x15, // an unknown data type won't cause trouble
    0x03, // an unknown data type won't cause trouble
    0x50, // an unknown data type won't cause trouble
    0x01, // an unknown data type won't cause trouble
    0x02 };
    ScanRecord data = ScanRecord.parseFromBytes(scanRecord);
    assertEquals(0x1a, data.getAdvertiseFlags());
    ParcelUuid uuid1 = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
    ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    assertTrue(data.getServiceUuids().contains(uuid1));
    assertTrue(data.getServiceUuids().contains(uuid2));
    assertEquals("Ped", data.getDeviceName());
    assertEquals(-20, data.getTxPowerLevel());
    assertTrue(data.getManufacturerSpecificData().get(0x00E0) != null);
    assertArrayEquals(new byte[] { 0x02, 0x15 }, data.getManufacturerSpecificData().get(0x00E0));
    assertTrue(data.getServiceData().containsKey(uuid2));
    assertArrayEquals(new byte[] { 0x50, 0x64 }, data.getServiceData().get(uuid2));
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanRecord(android.bluetooth.le.ScanRecord) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 42 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class ScanFilterTest method testReadWriteParcel.

@SmallTest
public void testReadWriteParcel() {
    ScanFilter filter = mFilterBuilder.build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setDeviceName("Ped").build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setDeviceAddress("11:22:33:44:55:66").build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB")).build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB"), ParcelUuid.fromString("FFFFFFF0-FFFF-FFFF-FFFF-FFFFFFFFFFFF")).build();
    testReadWriteParcelForFilter(filter);
    byte[] serviceData = new byte[] { 0x50, 0x64 };
    ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    filter = mFilterBuilder.setServiceData(serviceDataUuid, serviceData).build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setServiceData(serviceDataUuid, new byte[0]).build();
    testReadWriteParcelForFilter(filter);
    byte[] serviceDataMask = new byte[] { (byte) 0xFF, (byte) 0xFF };
    filter = mFilterBuilder.setServiceData(serviceDataUuid, serviceData, serviceDataMask).build();
    testReadWriteParcelForFilter(filter);
    byte[] manufacturerData = new byte[] { 0x02, 0x15 };
    int manufacturerId = 0xE0;
    filter = mFilterBuilder.setManufacturerData(manufacturerId, manufacturerData).build();
    testReadWriteParcelForFilter(filter);
    filter = mFilterBuilder.setServiceData(serviceDataUuid, new byte[0]).build();
    testReadWriteParcelForFilter(filter);
    byte[] manufacturerDataMask = new byte[] { (byte) 0xFF, (byte) 0xFF };
    filter = mFilterBuilder.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask).build();
    testReadWriteParcelForFilter(filter);
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanFilter(android.bluetooth.le.ScanFilter) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 43 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class ScanFilterTest method testsetServiceDataFilter.

@SmallTest
public void testsetServiceDataFilter() {
    byte[] setServiceData = new byte[] { 0x50, 0x64 };
    ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    ScanFilter filter = mFilterBuilder.setServiceData(serviceDataUuid, setServiceData).build();
    assertTrue("service data filter fails", filter.matches(mScanResult));
    byte[] emptyData = new byte[0];
    filter = mFilterBuilder.setServiceData(serviceDataUuid, emptyData).build();
    assertTrue("service data filter fails", filter.matches(mScanResult));
    byte[] prefixData = new byte[] { 0x50 };
    filter = mFilterBuilder.setServiceData(serviceDataUuid, prefixData).build();
    assertTrue("service data filter fails", filter.matches(mScanResult));
    byte[] nonMatchData = new byte[] { 0x51, 0x64 };
    byte[] mask = new byte[] { (byte) 0x00, (byte) 0xFF };
    filter = mFilterBuilder.setServiceData(serviceDataUuid, nonMatchData, mask).build();
    assertTrue("partial service data filter fails", filter.matches(mScanResult));
    filter = mFilterBuilder.setServiceData(serviceDataUuid, nonMatchData).build();
    assertFalse("service data filter fails", filter.matches(mScanResult));
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanFilter(android.bluetooth.le.ScanFilter) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 44 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class AdvertiseDataTest method testServiceUuid.

@SmallTest
public void testServiceUuid() {
    Parcel parcel = Parcel.obtain();
    ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
    ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    AdvertiseData data = mAdvertiseDataBuilder.setIncludeDeviceName(true).addServiceUuid(uuid).addServiceUuid(uuid2).build();
    data.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    AdvertiseData dataFromParcel = AdvertiseData.CREATOR.createFromParcel(parcel);
    assertEquals(data, dataFromParcel);
}
Also used : ParcelUuid(android.os.ParcelUuid) Parcel(android.os.Parcel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 45 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class AdvertiseData method writeToParcel.

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeList(mServiceUuids);
    // mManufacturerSpecificData could not be null.
    dest.writeInt(mManufacturerSpecificData.size());
    for (int i = 0; i < mManufacturerSpecificData.size(); ++i) {
        dest.writeInt(mManufacturerSpecificData.keyAt(i));
        byte[] data = mManufacturerSpecificData.valueAt(i);
        if (data == null) {
            dest.writeInt(0);
        } else {
            dest.writeInt(1);
            dest.writeInt(data.length);
            dest.writeByteArray(data);
        }
    }
    dest.writeInt(mServiceData.size());
    for (ParcelUuid uuid : mServiceData.keySet()) {
        dest.writeParcelable(uuid, flags);
        byte[] data = mServiceData.get(uuid);
        if (data == null) {
            dest.writeInt(0);
        } else {
            dest.writeInt(1);
            dest.writeInt(data.length);
            dest.writeByteArray(data);
        }
    }
    dest.writeByte((byte) (getIncludeTxPowerLevel() ? 1 : 0));
    dest.writeByte((byte) (getIncludeDeviceName() ? 1 : 0));
}
Also used : ParcelUuid(android.os.ParcelUuid)

Aggregations

ParcelUuid (android.os.ParcelUuid)147 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 ScanFilter (android.bluetooth.le.ScanFilter)19 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ScanRecord (android.bluetooth.le.ScanRecord)10 BluetoothDevice (android.bluetooth.BluetoothDevice)9 Socket (java.net.Socket)9 DataOutputStream (java.io.DataOutputStream)8 ByteBuffer (java.nio.ByteBuffer)8 SparseArray (android.util.SparseArray)6 RequiresPermission (android.annotation.RequiresPermission)5 BluetoothClass (android.bluetooth.BluetoothClass)5 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)5 ScanCallback (android.bluetooth.le.ScanCallback)5