android.os.ParcelUuid Java Examples

The following examples show how to use android.os.ParcelUuid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android_9.0.0_r45   Author: lulululbj   File: ScanFilter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set partial filter on service data. For any bit in the mask, set it to 1 if it needs to
 * match the one in service data, otherwise set it to 0 to ignore that bit.
 * <p>
 * The {@code serviceDataMask} must have the same length of the {@code serviceData}.
 *
 * @throws IllegalArgumentException If {@code serviceDataUuid} is null or {@code
 * serviceDataMask} is {@code null} while {@code serviceData} is not or {@code
 * serviceDataMask} and {@code serviceData} has different length.
 */
public Builder setServiceData(ParcelUuid serviceDataUuid,
        byte[] serviceData, byte[] serviceDataMask) {
    if (serviceDataUuid == null) {
        throw new IllegalArgumentException("serviceDataUuid is null");
    }
    if (mServiceDataMask != null) {
        if (mServiceData == null) {
            throw new IllegalArgumentException(
                    "serviceData is null while serviceDataMask is not null");
        }
        // Since the mServiceDataMask is a bit mask for mServiceData, the lengths of the two
        // byte array need to be the same.
        if (mServiceData.length != mServiceDataMask.length) {
            throw new IllegalArgumentException(
                    "size mismatch for service data and service data mask");
        }
    }
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    return this;
}
 
Example #2
Source Project: physical-web   Author: google   File: BluetoothUuid.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if there any common ParcelUuids in uuidA and uuidB.
 *
 * @param uuidA - List of ParcelUuids
 * @param uuidB - List of ParcelUuids
 */
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) {
        return true;
    }
    if (uuidA == null) {
        return uuidB.length == 0 ? true : false;
    }
    if (uuidB == null) {
        return uuidA.length == 0 ? true : false;
    }
    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) {
            return true;
        }
    }
    return false;
}
 
Example #3
Source Project: Android-nRF-Mesh-Library   Author: NordicSemiconductor   File: NrfMeshRepository.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Starts reconnecting to the device
 */
private void startScan() {
    if (mIsScanning)
        return;

    mIsScanning = true;
    // Scanning settings
    final ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            // Refresh the devices list every second
            .setReportDelay(0)
            // Hardware filtering has some issues on selected devices
            .setUseHardwareFilteringIfSupported(false)
            // Samsung S6 and S6 Edge report equal value of RSSI for all devices. In this app we ignore the RSSI.
            /*.setUseHardwareBatchingIfSupported(false)*/
            .build();

    // Let's use the filter to scan only for Mesh devices
    final List<ScanFilter> filters = new ArrayList<>();
    filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid((MESH_PROXY_UUID))).build());

    final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
    scanner.startScan(filters, settings, scanCallback);
    Log.v(TAG, "Scan started");
    mHandler.postDelayed(mScannerTimeout, 20000);
}
 
Example #4
Source Project: RxAndroidBle   Author: Polidea   File: ScanRecordImplCompat.java    License: Apache License 2.0 6 votes vote down vote up
public ScanRecordImplCompat(
        @Nullable List<ParcelUuid> serviceUuids,
        SparseArray<byte[]> manufacturerData,
        Map<ParcelUuid, byte[]> serviceData,
        int advertiseFlags,
        int txPowerLevel,
        String localName,
        byte[] bytes
) {
    this.serviceUuids = serviceUuids;
    this.manufacturerSpecificData = manufacturerData;
    this.serviceData = serviceData;
    this.deviceName = localName;
    this.advertiseFlags = advertiseFlags;
    this.txPowerLevel = txPowerLevel;
    this.bytes = bytes;
}
 
Example #5
Source Project: android_9.0.0_r45   Author: lulululbj   File: ScanFilter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check if the uuid pattern is contained in a list of parcel uuids.
 *
 * @hide
 */
public static boolean matchesServiceUuids(ParcelUuid uuid, ParcelUuid parcelUuidMask,
        List<ParcelUuid> uuids) {
    if (uuid == null) {
        return true;
    }
    if (uuids == null) {
        return false;
    }

    for (ParcelUuid parcelUuid : uuids) {
        UUID uuidMask = parcelUuidMask == null ? null : parcelUuidMask.getUuid();
        if (matchesServiceUuid(uuid.getUuid(), uuidMask, parcelUuid.getUuid())) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source Project: bitgatt   Author: Fitbit   File: MockScanResultProvider.java    License: Mozilla Public License 2.0 6 votes vote down vote up
MockScanResultProvider(int numberOfMockResults, int minRssi, int maxRssi){
    rnd = new Random(System.currentTimeMillis());
    scanResults = new ArrayList<>(numberOfMockResults);
    serviceDataMap = new HashMap<>();
    byte[] randomData = new byte[16];
    rnd.nextBytes(randomData);
    serviceDataMap.put(new ParcelUuid(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba")), randomData);
    for(int i=0; i < numberOfMockResults; i++) {
        ScanResult result = Mockito.mock(ScanResult.class);
        BluetoothDevice device = Mockito.mock(BluetoothDevice.class);
        ScanRecord record = Mockito.mock(ScanRecord.class);
        Mockito.when(device.getAddress()).thenReturn(randomMACAddress());
        Mockito.when(device.getName()).thenReturn("foobar-" + String.valueOf(i));
        Mockito.when(result.getDevice()).thenReturn(device);
        Mockito.when(result.getRssi()).thenReturn(-1 * (rnd.nextInt(Math.abs(minRssi) + 1 - Math.abs(maxRssi)) + Math.abs(maxRssi)));
        Assert.assertTrue("Rssi is less than zero", result.getRssi() < 0);
        Mockito.when(record.getDeviceName()).thenReturn("foobar-" + String.valueOf(i));
        Mockito.when(record.getServiceData()).thenReturn(serviceDataMap);
        scanResults.add(result);
    }
}
 
Example #7
Source Project: android-ponewheel   Author: ponewheel   File: BluetoothUtilImpl.java    License: MIT License 6 votes vote down vote up
void scanLeDevice(final boolean enable) {
    Timber.d("scanLeDevice enable = " + enable);
    if (enable) {
        mScanning = true;
        List<ScanFilter> filters_v2 = new ArrayList<>();
        ScanFilter scanFilter = new ScanFilter.Builder()
                .setServiceUuid(ParcelUuid.fromString(OWDevice.OnewheelServiceUUID))
                .build();
        filters_v2.add(scanFilter);
        //c03f7c8d-5e96-4a75-b4b6-333d36230365
        mBluetoothLeScanner.startScan(filters_v2, settings, mScanCallback);
    } else {
        mScanning = false;
        mBluetoothLeScanner.stopScan(mScanCallback);
        // added 10/23 to try cleanup
        mBluetoothLeScanner.flushPendingScanResults(mScanCallback);
    }
    mainActivity.invalidateOptionsMenu();
}
 
Example #8
Source Project: android_9.0.0_r45   Author: lulululbj   File: BluetoothGattCharacteristic.java    License: Apache License 2.0 6 votes vote down vote up
private BluetoothGattCharacteristic(Parcel in) {
    mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid();
    mInstance = in.readInt();
    mProperties = in.readInt();
    mPermissions = in.readInt();
    mKeySize = in.readInt();
    mWriteType = in.readInt();

    mDescriptors = new ArrayList<BluetoothGattDescriptor>();

    ArrayList<BluetoothGattDescriptor> descs =
            in.createTypedArrayList(BluetoothGattDescriptor.CREATOR);
    if (descs != null) {
        for (BluetoothGattDescriptor desc : descs) {
            desc.setCharacteristic(this);
            mDescriptors.add(desc);
        }
    }
}
 
Example #9
Source Project: android_9.0.0_r45   Author: lulululbj   File: BluetoothAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the UUIDs supported by the local Bluetooth adapter.
 *
 * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
 *
 * @return the UUIDs supported by the local Bluetooth Adapter.
 * @hide
 */
public ParcelUuid[] getUuids() {
    if (getState() != STATE_ON) {
        return null;
    }
    try {
        mServiceLock.readLock().lock();
        if (mService != null) {
            return mService.getUuids();
        }
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
    } finally {
        mServiceLock.readLock().unlock();
    }
    return null;
}
 
Example #10
Source Project: EFRConnect-android   Author: SiliconLabs   File: BluetoothUuid.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if all the ParcelUuids in ParcelUuidB are present in ParcelUuidA
 *
 * @param uuidA - Array of ParcelUuidsA
 * @param uuidB - Array of ParcelUuidsB
 */
public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) {
        return true;
    }
    if (uuidA == null) {
        return uuidB.length == 0;
    }
    if (uuidB == null) {
        return true;
    }
    HashSet<ParcelUuid> uuidSet = new HashSet<>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (!uuidSet.contains(uuid)) {
            return false;
        }
    }
    return true;
}
 
Example #11
Source Project: sample-bluetooth-le-gattserver   Author: androidthings   File: GattServerActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Begin advertising over Bluetooth that this device is connectable
 * and supports the Current Time Service.
 */
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(TimeProfile.TIME_SERVICE))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example #12
Source Project: bluetooth   Author: JimSeker   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
void discover() {
    mBluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();

    ScanFilter filter = new ScanFilter.Builder()
        .setServiceUuid( new ParcelUuid(UUID.fromString( getString(R.string.ble_uuid ) ) ) )
        .build();
    List<ScanFilter> filters = new ArrayList<ScanFilter>();
    filters.add( filter );

    ScanSettings settings = new ScanSettings.Builder()
        .setScanMode( ScanSettings.SCAN_MODE_LOW_LATENCY )
        .build();
    mBluetoothLeScanner.startScan(filters, settings, mScanCallback);
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            mBluetoothLeScanner.stopScan(mScanCallback);
        }
    }, 10000);
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: BluetoothUuid.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if there any common ParcelUuids in uuidA and uuidB.
 *
 * @param uuidA - List of ParcelUuids
 * @param uuidB - List of ParcelUuids
 */
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) return true;

    if (uuidA == null) {
        return uuidB.length == 0;
    }

    if (uuidB == null) {
        return uuidA.length == 0;
    }

    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) return true;
    }
    return false;
}
 
Example #14
Source Project: android_9.0.0_r45   Author: lulululbj   File: BluetoothUuid.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if all the ParcelUuids in ParcelUuidB are present in
 * ParcelUuidA
 *
 * @param uuidA - Array of ParcelUuidsA
 * @param uuidB - Array of ParcelUuidsB
 */
public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) return true;

    if (uuidA == null) {
        return uuidB.length == 0;
    }

    if (uuidB == null) return true;

    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (!uuidSet.contains(uuid)) return false;
    }
    return true;
}
 
Example #15
Source Project: Android-Scanner-Compat-Library   Author: NordicSemiconductor   File: ScanFilter.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ScanFilter(@Nullable final String name, @Nullable final String deviceAddress,
				   @Nullable final ParcelUuid uuid, @Nullable final ParcelUuid uuidMask,
				   @Nullable final ParcelUuid serviceDataUuid, @Nullable final byte[] serviceData,
				   @Nullable final byte[] serviceDataMask, final int manufacturerId,
				   @Nullable final byte[] manufacturerData,
				   @Nullable final byte[] manufacturerDataMask) {
	this.deviceName = name;
	this.serviceUuid = uuid;
	this.serviceUuidMask = uuidMask;
	this.deviceAddress = deviceAddress;
	this.serviceDataUuid = serviceDataUuid;
	this.serviceData = serviceData;
	this.serviceDataMask = serviceDataMask;
	this.manufacturerId = manufacturerId;
	this.manufacturerData = manufacturerData;
	this.manufacturerDataMask = manufacturerDataMask;
}
 
Example #16
Source Project: AndroidBleManager   Author: haodynasty   File: BluetoothUuidCompat.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if ParcelUuid is present in uuidArray
 *
 * @param uuidArray - Array of ParcelUuids
 * @param uuid
 */
public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
    if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
        return true;

    if (uuidArray == null)
        return false;

    for (ParcelUuid element : uuidArray) {
        if (element.equals(uuid)) return true;
    }
    return false;
}
 
Example #17
Source Project: xDrip   Author: NightscoutFoundation   File: ScanRecordImplCompatLocal.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the service data byte array associated with the {@code serviceUuid}. Returns
 * {@code null} if the {@code serviceDataUuid} is not found.
 */
@Nullable
public byte[] getServiceData(ParcelUuid serviceDataUuid) {
    if (serviceDataUuid == null) {
        return null;
    }
    return serviceData.get(serviceDataUuid);
}
 
Example #18
Source Project: bluetooth   Author: JimSeker   File: AdvertiseFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * start advertise
 * setup the power levels, the UUID, and the data
 * which is used the callback then call start advertising.
 */
private void start_advertise() {

    //define the power settings  could use ADVERTISE_MODE_LOW_POWER, ADVERTISE_MODE_BALANCED too.
    AdvertiseSettings settings = new AdvertiseSettings.Builder()
        .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
        .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
        .setConnectable(false)
        .build();
    //get the UUID needed.
    ParcelUuid pUuid = new ParcelUuid(UUID.fromString(getString(R.string.blue_uuid)));
    //build
    AdvertiseData data = new AdvertiseData.Builder()
        .setIncludeDeviceName(false)  //should be true, but we are bigger then 31bytes in the name?
        .addServiceUuid(pUuid)
        //this is where the text is added.
        .addServiceData(pUuid, text.getText().toString().getBytes(Charset.forName("UTF-8")))
        .build();
    advertisingCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            logthis("Advertising has started");
            logthis("message is " + text.getText().toString());
            advertising = true;
            advertise.setText("Stop Advertising");
            super.onStartSuccess(settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            logthis("Advertising onStartFailure: " + errorCode);
            advertising = false;
            advertise.setText("Start Advertising");
            super.onStartFailure(errorCode);
        }
    };

    advertiser.startAdvertising(settings, data, advertisingCallback);

}
 
Example #19
Source Project: Android-nRF-Mesh-Library   Author: NordicSemiconductor   File: AccessMessage.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected AccessMessage(final Parcel source) {
    super(source);
    final ParcelUuid parcelUuid = source.readParcelable(ParcelUuid.class.getClassLoader());
    if (parcelUuid != null) {
        label = parcelUuid.getUuid();
    }
    lowerTransportAccessPdu = readSparseArrayToParcelable(source);
    accessPdu = source.createByteArray();
    transportPdu = source.createByteArray();
}
 
Example #20
Source Project: Bluefruit_LE_Connect_Android_V2   Author: adafruit   File: BlePeripheralUart.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public static boolean isUartAdvertised(@NonNull BlePeripheral blePeripheral) {
    List<ParcelUuid> serviceUuids = blePeripheral.getScanRecord().getServiceUuids();
    boolean found = false;

    if (serviceUuids != null) {
        int i = 0;
        while (i < serviceUuids.size() && !found) {
            found = serviceUuids.get(i).getUuid().equals(kUartServiceUUID);
            i++;
        }
    }
    return found;
}
 
Example #21
Source Project: bitgatt   Author: Fitbit   File: BondTransactionTests.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void before() {
    this.mockContext = InstrumentationRegistry.getInstrumentation().getContext();
    services = new ArrayList<>();
    services.add(new ParcelUuid(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba")));
    CountDownLatch cd = new CountDownLatch(1);
    NoOpGattCallback cb = new NoOpGattCallback() {

        @Override
        public void onGattClientStarted() {
            FitbitBluetoothDevice device = new FitbitBluetoothDevice(MOCK_ADDRESS, "Stupid");
            conn = new GattConnection(device, mockContext.getMainLooper());
            conn.setMockMode(true);
            conn.setState(GattState.CONNECTED);
            // idempotent, can't put the same connection into the map more than once
            FitbitGatt.getInstance().putConnectionIntoDevices(device, conn);
            cd.countDown();
        }


    };
    FitbitGatt.getInstance().registerGattEventListener(cb);

    FitbitGatt.getInstance().startGattClient(mockContext);
    FitbitGatt.getInstance().setScanServiceUuidFilters(services);
    FitbitGatt.getInstance().initializeScanner(mockContext);
    try {
        cd.await(1, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        fail("Timeout during test setup");
    }
}
 
Example #22
Source Project: Android-nRF-Mesh-Library   Author: NordicSemiconductor   File: ScannerRepository.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Start scanning for Bluetooth devices.
 *
 * @param filterUuid UUID to filter scan results with
 */
public void startScan(final UUID filterUuid) {
    mFilterUuid = filterUuid;

    if (mScannerStateLiveData.isScanning()) {
        return;
    }

    if (mFilterUuid.equals(BleMeshManager.MESH_PROXY_UUID)) {
        final MeshNetwork network = mMeshManagerApi.getMeshNetwork();
        if (network != null) {
            if (!network.getNetKeys().isEmpty()) {
                mNetworkId = mMeshManagerApi.generateNetworkId(network.getNetKeys().get(0).getKey());
            }
        }
    }

    mScannerStateLiveData.scanningStarted();
    //Scanning settings
    final ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            // Refresh the devices list every second
            .setReportDelay(0)
            // Hardware filtering has some issues on selected devices
            .setUseHardwareFilteringIfSupported(false)
            // Samsung S6 and S6 Edge report equal value of RSSI for all devices. In this app we ignore the RSSI.
            /*.setUseHardwareBatchingIfSupported(false)*/
            .build();

    //Let's use the filter to scan only for unprovisioned mesh nodes.
    final List<ScanFilter> filters = new ArrayList<>();
    filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid((filterUuid))).build());

    final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
    scanner.startScan(filters, settings, mScanCallbacks);
}
 
Example #23
Source Project: bitgatt   Author: Fitbit   File: FitbitGattTest.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void setScanServiceUuidFilters() {
    List<ParcelUuid> filters = new ArrayList<>();

    fitbitGatt.setPeripheralScanner(scannerMock);
    fitbitGatt.setScanServiceUuidFilters(filters);

    verify(scannerMock).setServiceUuidFilters(filters);
    verifyNoMoreInteractions(scannerMock);
}
 
Example #24
Source Project: AndroidBleManager   Author: haodynasty   File: ScanFilterCompat.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set filter on partial service uuid. The {@code uuidMask} is the bit mask for the
 * {@code serviceUuid}. Set any bit in the mask to 1 to indicate a match is needed for the
 * bit in {@code serviceUuid}, and 0 to ignore that bit.
 *
 * @throws IllegalArgumentException If {@code serviceUuid} is {@code null} but
 *                                  {@code uuidMask} is not {@code null}.
 */
public Builder setServiceUuid(ParcelUuid serviceUuid, ParcelUuid uuidMask) {
    if (mUuidMask != null && mServiceUuid == null) {
        throw new IllegalArgumentException("uuid is null while uuidMask is not null!");
    }
    mServiceUuid = serviceUuid;
    mUuidMask = uuidMask;
    return this;
}
 
Example #25
Source Project: xDrip-plus   Author: jamorham   File: ScanRecordImplCompatLocal.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the service data byte array associated with the {@code serviceUuid}. Returns
 * {@code null} if the {@code serviceDataUuid} is not found.
 */
@Nullable
public byte[] getServiceData(ParcelUuid serviceDataUuid) {
    if (serviceDataUuid == null) {
        return null;
    }
    return serviceData.get(serviceDataUuid);
}
 
Example #26
Source Project: EFRConnect-android   Author: SiliconLabs   File: BluetoothUuid.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example #27
Source Project: 365browser   Author: mogoweb   File: WebContentsImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public WebContents createFromParcel(Parcel source) {
    Bundle bundle = source.readBundle();

    // Check the version.
    if (bundle.getLong(PARCEL_VERSION_KEY, -1) != 0) return null;

    // Check that we're in the same process.
    ParcelUuid parcelUuid = bundle.getParcelable(PARCEL_PROCESS_GUARD_KEY);
    if (sParcelableUUID.compareTo(parcelUuid.getUuid()) != 0) return null;

    // Attempt to retrieve the WebContents object from the native pointer.
    return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS_KEY));
}
 
Example #28
Source Project: android-beacon-library   Author: AltBeacon   File: ScanFilterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public List<ScanFilter> createScanFiltersForBeaconParsers(List<BeaconParser> beaconParsers) {
    List<ScanFilter> scanFilters = new ArrayList<ScanFilter>();
    // for each beacon parser, make a filter expression that includes all its desired
    // hardware manufacturers
    for (BeaconParser beaconParser: beaconParsers) {
        List<ScanFilterData> sfds = createScanFilterDataForBeaconParser(beaconParser);
        for (ScanFilterData sfd: sfds) {
            ScanFilter.Builder builder = new ScanFilter.Builder();
            if (sfd.serviceUuid != null) {
                // Use a 16 bit service UUID in a 128 bit form
                String serviceUuidString = String.format("0000%04X-0000-1000-8000-00805f9b34fb", sfd.serviceUuid);
                String serviceUuidMaskString = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
                ParcelUuid parcelUuid = ParcelUuid.fromString(serviceUuidString);
                ParcelUuid parcelUuidMask = ParcelUuid.fromString(serviceUuidMaskString);
                if (LogManager.isVerboseLoggingEnabled()) {
                    LogManager.d(TAG, "making scan filter for service: "+serviceUuidString+" "+parcelUuid);
                    LogManager.d(TAG, "making scan filter with service mask: "+serviceUuidMaskString+" "+parcelUuidMask);
                }
                builder.setServiceUuid(parcelUuid, parcelUuidMask);
            }
            else {
                builder.setServiceUuid(null);
                builder.setManufacturerData((int) sfd.manufacturer, sfd.filter, sfd.mask);
            }
            ScanFilter scanFilter = builder.build();
            if (LogManager.isVerboseLoggingEnabled()) {
                LogManager.d(TAG, "Set up a scan filter: "+scanFilter);
            }
            scanFilters.add(scanFilter);
        }
    }
    return scanFilters;
}
 
Example #29
Source Project: DeviceConnect-Android   Author: DeviceConnect   File: AbstractHOGPServer.java    License: MIT License 5 votes vote down vote up
/**
 * アドバタイジングを開始します.
 */
private void startAdvertising() {
    if (DEBUG) {
        Log.d(TAG, "startAdvertising");
    }

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            // set up advertising setting
            final AdvertiseSettings advertiseSettings = new AdvertiseSettings.Builder()
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .build();

            // set up advertising data
            final AdvertiseData advertiseData = new AdvertiseData.Builder()
                    .setIncludeTxPowerLevel(false)
                    .setIncludeDeviceName(true)
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            // set up scan result
            final AdvertiseData scanResult = new AdvertiseData.Builder()
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            mBluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, scanResult, mAdvertiseCallback);
        }
    });
}
 
Example #30
Source Project: RxAndroidBle   Author: Polidea   File: ScanFilter.java    License: Apache License 2.0 5 votes vote down vote up
ScanFilter(String name, String deviceAddress, ParcelUuid uuid,
           ParcelUuid uuidMask, ParcelUuid serviceDataUuid,
           byte[] serviceData, byte[] serviceDataMask,
           int manufacturerId, byte[] manufacturerData, byte[] manufacturerDataMask) {
    mDeviceName = name;
    mServiceUuid = uuid;
    mServiceUuidMask = uuidMask;
    mDeviceAddress = deviceAddress;
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    mManufacturerId = manufacturerId;
    mManufacturerData = manufacturerData;
    mManufacturerDataMask = manufacturerDataMask;
}