Java 类android.os.ParcelUuid 实例源码

项目:RangeThings    文件:GattServer.java   
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) 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(GattProfile.SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
项目:ITagAntiLost    文件:NewDevicePresenter.java   
@Override
public void onScanResult(int callbackType, ScanResult result) {
  super.onScanResult(callbackType, result);
  if (result.getScanRecord() != null) {
    List<ParcelUuid> uuids = result.getScanRecord().getServiceUuids();
    if (uuids != null) {
      for (ParcelUuid uuid : uuids) {
        if (uuid.getUuid().equals(BleService.FIND_ME_SERVICE)) {
          if (!currentAddresses.contains(result.getDevice().getAddress()))
            viewStatePublisher.onNext(
                new NewDevicesViewState.NewDeviceState(
                    result.getDevice().getAddress(),
                    result.getScanRecord().getDeviceName())
            );
          break;
        }
      }
    }
  }
}
项目:android-ponewheel    文件:BluetoothUtilImpl.java   
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();
}
项目:OkBluetooth    文件:DeviceHolder.java   
@Override public void bind(BluetoothDevice device) {
  nameView.setText(device.getName());
  switch (device.getType()) {
    case DEVICE_TYPE_CLASSIC:
      typeView.setText("DEVICE_TYPE_CLASSIC");
      break;
    case DEVICE_TYPE_DUAL:
      typeView.setText("DEVICE_TYPE_DUAL");
      break;
    case DEVICE_TYPE_LE:
      typeView.setText("DEVICE_TYPE_LE");
      break;
    case DEVICE_TYPE_UNKNOWN:
      typeView.setText("DEVICE_TYPE_UNKNOWN");
      break;
    default:
      typeView.setText("What's this?");
      break;
  }
  addressView.setText(device.getAddress());
  ParcelUuid[] uuids = device.getUuids();
  uuidView.setText(Arrays.toString(uuids));
}
项目:mobly-bundled-snippets    文件:JsonSerializer.java   
public Bundle serializeBluetoothDevice(BluetoothDevice data) {
    Bundle result = new Bundle();
    result.putString("Address", data.getAddress());
    final String bondState =
            MbsEnums.BLUETOOTH_DEVICE_BOND_STATE.getString(data.getBondState());
    result.putString("BondState", bondState);
    result.putString("Name", data.getName());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        String deviceType = MbsEnums.BLUETOOTH_DEVICE_TYPE.getString(data.getType());
        result.putString("DeviceType", deviceType);
        ParcelUuid[] parcelUuids = data.getUuids();
        if (parcelUuids != null) {
            ArrayList<String> uuidStrings = new ArrayList<>(parcelUuids.length);
            for (ParcelUuid parcelUuid : parcelUuids) {
                uuidStrings.add(parcelUuid.getUuid().toString());
            }
            result.putStringArrayList("UUIDs", uuidStrings);
        }
    }
    return result;
}
项目:blefun-androidthings    文件:GattServer.java   
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(SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
项目:blefun-androidthings    文件:ScanActivity.java   
private void startLeScan() {
    mScanning = true;

    ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            .setReportDelay(1000)
            .build();
    List<ScanFilter> filters = new ArrayList<>();
    filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(SERVICE_UUID)).build());
    mScanner.startScan(filters, settings, mScanCallback);

    // Stops scanning after a pre-defined scan period.
    mStopScanHandler.postDelayed(mStopScanRunnable, SCAN_TIMEOUT_MS);

    invalidateOptionsMenu();
}
项目:AndroidMuseumBleManager    文件:ScanFilterCompat.java   
private 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;
}
项目:AndroidMuseumBleManager    文件:ScanFilterCompat.java   
/**
 * 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;
}
项目:AndroidMuseumBleManager    文件:BluetoothUuidCompat.java   
/**
 * 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<>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) return true;
    }
    return false;
}
项目:AndroidMuseumBleManager    文件:BluetoothUuidCompat.java   
/**
 * 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;
}
项目:sample-bluetooth-le-gattserver    文件:GattServerActivity.java   
/**
 * 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);
}
项目:AndroidBleManager    文件:BluetoothUuidCompat.java   
/**
 * 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<>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) return true;
    }
    return false;
}
项目:BleUARTPeripheral    文件:MainActivity.java   
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) 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)
            .addServiceUuid(new ParcelUuid(UARTProfile.UART_SERVICE))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
项目:AndroidBleManager    文件:ScanFilterCompat.java   
/**
 * 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;
}
项目:RxAndroidBle    文件:ScanFilter.java   
private 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;
}
项目:RxAndroidBle    文件:ScanFilter.java   
/**
 * 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 ScanFilter.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;
}
项目:AsteroidOSSync    文件:BleAdvertisingPacket.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
/*package*/ AdvertiseData getNativeData() {
    AdvertiseData.Builder data = new AdvertiseData.Builder();
    for (UUID id : serviceUuids)
    {
        data.addServiceUuid(new ParcelUuid(id));
    }
    if (m_manufacturerId != 0 && m_manData != null)
    {
        data.addManufacturerData(m_manufacturerId, m_manData);
    }
    if (serviceData != null && serviceData.size() > 0)
    {
        for (UUID dataUuid : serviceData.keySet())
        {
            data.addServiceData(new ParcelUuid(dataUuid), serviceData.get(dataUuid));
        }
    }
    data.setIncludeDeviceName(includeDeviceName());
    data.setIncludeTxPowerLevel(includeTxPowerLevel());
    return data.build();
}
项目:TappyBLE    文件:ScanFilter.java   
private 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;
}
项目:beacons-android    文件:EddystoneAdvertiser.java   
/**
 * Creates an Eddystone BLE advertiser. It does not start any actual transmission.
 * @param frameData              Frame data (without service data frame type or TX power bytes)
 * @param pos                    Frame data offset
 * @param len                    Frame data size
 */
public EddystoneAdvertiser(SettingsProvider provider, byte frameType, byte[] frameData,
                           int pos, int len)
{
    super(provider);

    mServiceData = new byte[2 + len];

    mServiceData[0] = frameType;
    mServiceData[1] = FRAME_TLM == frameType ? 0
            : AdvertisersManager.getZeroDistanceTxPower(provider.getTxPowerLevel());
    System.arraycopy(frameData, pos, mServiceData, 2, len);

    // an advertisement packet can have at most 31 bytes
    mAdvertiseData = new AdvertiseData.Builder()
            .setIncludeDeviceName(false)
            .setIncludeTxPowerLevel(false)
            .addServiceData(EDDYSTONE_SERVICE_UUID, mServiceData)
            .addServiceUuid(EDDYSTONE_SERVICE_UUID)
            .build();

    if (provider.isConnectable()) {
        mAdvertiseScanResponse = new AdvertiseData.Builder()
                .setIncludeDeviceName(true)
                .setIncludeTxPowerLevel(false)  // allows 3 more bytes for device name
                .addServiceUuid(new ParcelUuid(EddystoneGattService.UUID_EDDYSTONE_GATT_SERVICE))
                .build();
    }
}
项目:xDrip-plus    文件:BluetoothGlucoseMeter.java   
private void beginScan() {
    if (Build.VERSION.SDK_INT >= 21) {
        if (d) Log.d(TAG, "Preparing for scan...");

        // set up v21 scanner
        mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
        settings = new ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .build();
        filters = new ArrayList<>();

        filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(GLUCOSE_SERVICE)).build());
    }
    // all api versions
    scanLeDevice(true);
}
项目:appc-android-bluetooth    文件:BluetoothService.java   
private String[] getServiceDescriptions(ParcelUuid[] parcels)
{
    String[] retval = new String[parcels.length];
    int counter = 0;

    for(ParcelUuid p: parcels)
    {
        String nextService = getServiceDescription(p.getUuid());

        if(nextService != null)
        {
            retval[counter] = nextService;
            counter++;
        }
    }

    return retval;
}
项目:BeaconTag-Android-SDK    文件:BluetoothUuidUtils.java   
/**
 * 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;
}
项目:mobly-bundled-snippets    文件:JsonDeserializer.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static AdvertiseData jsonToBleAdvertiseData(JSONObject jsonObject) throws JSONException {
    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    if (jsonObject.has("IncludeDeviceName")) {
        builder.setIncludeDeviceName(jsonObject.getBoolean("IncludeDeviceName"));
    }
    if (jsonObject.has("IncludeTxPowerLevel")) {
        builder.setIncludeTxPowerLevel(jsonObject.getBoolean("IncludeTxPowerLevel"));
    }
    if (jsonObject.has("ServiceData")) {
        JSONArray serviceData = jsonObject.getJSONArray("ServiceData");
        for (int i = 0; i < serviceData.length(); i++) {
            JSONObject dataSet = serviceData.getJSONObject(i);
            ParcelUuid parcelUuid = ParcelUuid.fromString(dataSet.getString("UUID"));
            builder.addServiceUuid(parcelUuid);
            if (dataSet.has("Data")) {
                byte[] data = Base64.decode(dataSet.getString("Data"), Base64.DEFAULT);
                builder.addServiceData(parcelUuid, data);
            }
        }
    }
    if (jsonObject.has("ManufacturerData")) {
        JSONObject manufacturerData = jsonObject.getJSONObject("ManufacturerData");
        int manufacturerId = manufacturerData.getInt("ManufacturerId");
        byte[] manufacturerSpecificData =
                Base64.decode(jsonObject.getString("ManufacturerSpecificData"), Base64.DEFAULT);
        builder.addManufacturerData(manufacturerId, manufacturerSpecificData);
    }
    return builder.build();
}
项目:sdc-1-quickstart-android    文件:MainActivity.java   
/**
 * Callback when a BLE advertisement has been found.
 *
 * @param callbackType Determines how this callback was triggered.
 * @param result       A Bluetooth LE scan result.
 */
@Override
public void onScanResult(int callbackType, final ScanResult result) {
    super.onScanResult(callbackType, result);

    // Get the ScanRecord and check if it is defined (is nullable)
    final ScanRecord scanRecord = result.getScanRecord();
    if (scanRecord != null) {
        // Check if the Service UUIDs are defined (is nullable) and contain the discovery
        // UUID
        final List<ParcelUuid> serviceUuids = scanRecord.getServiceUuids();
        if (serviceUuids != null && serviceUuids.contains(DISCOVERY_UUID)) {
            // We have found our device, so update the GUI, stop scanning and start
            // connecting
            final BluetoothDevice device = result.getDevice();

            // We'll make sure the GUI is updated on the UI thread
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // At this point we have the device address and RSSI, so update those
                    deviceAddressTextView.setText(device.getAddress());
                    rssiTextView.setText(getString(R.string.rssi, result.getRssi()));
                }
            });

            stopDiscovery();

            bluetoothGatt = device.connectGatt(
                    MainActivity.this,
                    // False here, as we want to directly connect to the device
                    false,
                    bluetoothGattCallback
            );
        }
    }
}
项目:AndroidMuseumBleManager    文件:ScanFilterCompat.java   
private ScanFilterCompat(@Nullable String name, @Nullable String deviceAddress, @Nullable ParcelUuid uuid,
                         @Nullable ParcelUuid uuidMask, @Nullable ParcelUuid serviceDataUuid,
                         @Nullable byte[] serviceData, @Nullable byte[] serviceDataMask,
                         int manufacturerId, @Nullable byte[] manufacturerData, @Nullable byte[] manufacturerDataMask) {
    mDeviceName = name;
    mServiceUuid = uuid;
    mServiceUuidMask = uuidMask;
    mDeviceAddress = deviceAddress;
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    mManufacturerId = manufacturerId;
    mManufacturerData = manufacturerData;
    mManufacturerDataMask = manufacturerDataMask;
}
项目:AndroidMuseumBleManager    文件:ScanFilterCompat.java   
/**
 * 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;
}
项目:AndroidMuseumBleManager    文件:ScanFilterCompat.java   
/**
 * Set filtering on service data.
 *
 * @throws IllegalArgumentException If {@code serviceDataUuid} is null.
 */
public Builder setServiceData(ParcelUuid serviceDataUuid, byte[] serviceData) {
    if (serviceDataUuid == null) {
        throw new IllegalArgumentException("serviceDataUuid is null");
    }
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = null; // clear service data mask
    return this;
}
项目:AndroidMuseumBleManager    文件:BluetoothUuidCompat.java   
/**
 * 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;
}
项目:AndroidMuseumBleManager    文件:BluetoothUuidCompat.java   
/**
 * 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);
}
项目:AndroidMuseumBleManager    文件:BluetoothUuidCompat.java   
/**
 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
 */
public static boolean is32BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    if (is16BitUuid(parcelUuid)) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
}
项目:AndroidMuseumBleManager    文件:ScanRecordCompat.java   
/**
 * 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 mServiceData.get(serviceDataUuid);
}
项目:AndroidMuseumBleManager    文件:ScanRecordCompat.java   
private ScanRecordCompat(@Nullable List<ParcelUuid> serviceUuids,
                   SparseArray<byte[]> manufacturerData,
                   Map<ParcelUuid, byte[]> serviceData,
                   int advertiseFlags, int txPowerLevel,
                   String localName, byte[] bytes) {
    mServiceUuids = serviceUuids;
    mManufacturerSpecificData = manufacturerData;
    mServiceData = serviceData;
    mDeviceName = localName;
    mAdvertiseFlags = advertiseFlags;
    mTxPowerLevel = txPowerLevel;
    mBytes = bytes;
}
项目:AndroidMuseumBleManager    文件:ScanRecordCompat.java   
private static int parseServiceUuid(byte[] scanRecord, int currentPos, int dataLength,
                                    int uuidLength, List<ParcelUuid> serviceUuids) {
    while (dataLength > 0) {
        byte[] uuidBytes = extractBytes(scanRecord, currentPos,
                uuidLength);
        serviceUuids.add(BluetoothUuidCompat.parseUuidFrom(uuidBytes));
        dataLength -= uuidLength;
        currentPos += uuidLength;
    }
    return currentPos;
}
项目:Android-DFU-App    文件:ScannerFragment.java   
public static ScannerFragment getInstance(final UUID uuid) {
    final ScannerFragment fragment = new ScannerFragment();

    final Bundle args = new Bundle();
    if (uuid != null)
        args.putParcelable(PARAM_UUID, new ParcelUuid(uuid));
    fragment.setArguments(args);
    return fragment;
}
项目:noise    文件:BluetoothSyncService.java   
private AdvertiseData buildAdvertiseData() {
    AdvertiseData.Builder builder = new AdvertiseData.Builder();

    // We are including this device's physical MAC address in the advertisement to enable higher bandwidth pair-free communication over Bluetooth Classic sockets.
    // While our communications will always be anonymous by design, this still has privacy implications:
    // If an attacker manages to associate an address with a person, they will be able to determine if that person is nearby as long as the app is installed on that phone.
    builder.addServiceUuid(new ParcelUuid(serviceUuidAndAddress));
    // TODO: Include some portion of the sync bit string/Bloom filter from the database
    builder.setIncludeDeviceName(false);
    return builder.build();
}
项目:BLE-HID-Peripheral-for-Android    文件:HidPeripheral.java   
/**
 * Starts advertising
 */
public final void startAdvertising() {
    handler.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 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 Builder()
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            Log.d(TAG, "advertiseData: " + advertiseData + ", scanResult: " + scanResult);
            bluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, scanResult, advertiseCallback);
        }
    });
}
项目:UDOOBluLib-android    文件:UdooBluService.java   
public void scanLeDevice(final boolean enable, final BluScanCallBack scanCallback) {
    List<ScanFilter> scanFilters = new ArrayList<>();
    ScanFilter scanFilter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(UDOOBLE.UUID_SENSORS_SERV)).build();
    scanFilters.add(scanFilter);

    ScanSettings scanSettings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            .build();

    UdooBluException udooBluException = checkBluetooth(getApplicationContext());
    if (udooBluException != null) {
        if (scanCallback != null)
            scanCallback.onError(udooBluException);
    } else {
        mLEScanner = mBtAdapter.getBluetoothLeScanner();
        if (enable && mScanning.compareAndSet(false, true)) {
            mLEScanner.startScan(scanFilters, scanSettings, scanCallback);
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLEScanner.stopScan(scanCallback);
                    mScanning.set(false);
                    if (scanCallback != null)
                        scanCallback.onScanFinished();
                }
            }, SCAN_PERIOD);
        } else {
            mScanning.set(false);
            mLEScanner.stopScan(scanCallback);
            if (scanCallback != null)
                scanCallback.onScanFinished();
        }
    }
}
项目:mesh-core-on-android    文件:JniCallbacks.java   
public void pbgattAdvertiseStart(byte[] serviceData) {

    if(D){
        Log.d(TAG, "pbgattAdvertiseStart");
    }

    ParcelUuid uu = ParcelUuid.fromString(UUID_PB_SVC);

    mBluetoothLeAdvertiser.startAdvertising(createAdvSettings(true,0), 
                                            createAdvertiseData(uu, serviceData),
                                            mAdvertiseCallback);
}
项目:mesh-core-on-android    文件:JniCallbacks.java   
private AdvertiseData createAdvertiseData(ParcelUuid uuid, byte[] serviceData){      
    AdvertiseData.Builder mDataBuilder = new AdvertiseData.Builder();
    mDataBuilder.addServiceUuid(uuid);
mDataBuilder.addServiceData(uuid, serviceData);
AdvertiseData mAdvertiseData = mDataBuilder.build();

if(mAdvertiseData==null){
    Log.e(TAG, "mAdvertiseSettings == null");
}
return mAdvertiseData;
  }