Methods Summary |
---|
public int | describeContents()
return 0;
|
public boolean | equals(java.lang.Object obj)
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
ScanFilter other = (ScanFilter) obj;
return Objects.equals(mDeviceName, other.mDeviceName) &&
Objects.equals(mDeviceAddress, other.mDeviceAddress) &&
mManufacturerId == other.mManufacturerId &&
Objects.deepEquals(mManufacturerData, other.mManufacturerData) &&
Objects.deepEquals(mManufacturerDataMask, other.mManufacturerDataMask) &&
Objects.deepEquals(mServiceDataUuid, other.mServiceDataUuid) &&
Objects.deepEquals(mServiceData, other.mServiceData) &&
Objects.deepEquals(mServiceDataMask, other.mServiceDataMask) &&
Objects.equals(mServiceUuid, other.mServiceUuid) &&
Objects.equals(mServiceUuidMask, other.mServiceUuidMask);
|
public java.lang.String | getDeviceAddress()
return mDeviceAddress;
|
public java.lang.String | getDeviceName()Returns the filter set the device name field of Bluetooth advertisement data.
return mDeviceName;
|
public byte[] | getManufacturerData()
return mManufacturerData;
|
public byte[] | getManufacturerDataMask()
return mManufacturerDataMask;
|
public int | getManufacturerId()Returns the manufacturer id. -1 if the manufacturer filter is not set.
return mManufacturerId;
|
public byte[] | getServiceData()
return mServiceData;
|
public byte[] | getServiceDataMask()
return mServiceDataMask;
|
public android.os.ParcelUuid | getServiceDataUuid()
return mServiceDataUuid;
|
public android.os.ParcelUuid | getServiceUuid()Returns the filter set on the service uuid.
return mServiceUuid;
|
public android.os.ParcelUuid | getServiceUuidMask()
return mServiceUuidMask;
|
public int | hashCode()
return Objects.hash(mDeviceName, mDeviceAddress, mManufacturerId, mManufacturerData,
mManufacturerDataMask, mServiceDataUuid, mServiceData, mServiceDataMask,
mServiceUuid, mServiceUuidMask);
|
public boolean | matches(ScanResult scanResult)Check if the scan filter matches a {@code scanResult}. A scan result is considered as a match
if it matches all the field filters.
if (scanResult == null) {
return false;
}
BluetoothDevice device = scanResult.getDevice();
// Device match.
if (mDeviceAddress != null
&& (device == null || !mDeviceAddress.equals(device.getAddress()))) {
return false;
}
ScanRecord scanRecord = scanResult.getScanRecord();
// Scan record is null but there exist filters on it.
if (scanRecord == null
&& (mDeviceName != null || mServiceUuid != null || mManufacturerData != null
|| mServiceData != null)) {
return false;
}
// Local name match.
if (mDeviceName != null && !mDeviceName.equals(scanRecord.getDeviceName())) {
return false;
}
// UUID match.
if (mServiceUuid != null && !matchesServiceUuids(mServiceUuid, mServiceUuidMask,
scanRecord.getServiceUuids())) {
return false;
}
// Service data match
if (mServiceDataUuid != null) {
if (!matchesPartialData(mServiceData, mServiceDataMask,
scanRecord.getServiceData(mServiceDataUuid))) {
return false;
}
}
// Manufacturer data match.
if (mManufacturerId >= 0) {
if (!matchesPartialData(mManufacturerData, mManufacturerDataMask,
scanRecord.getManufacturerSpecificData(mManufacturerId))) {
return false;
}
}
// All filters match.
return true;
|
private boolean | matchesPartialData(byte[] data, byte[] dataMask, byte[] parsedData)
if (parsedData == null || parsedData.length < data.length) {
return false;
}
if (dataMask == null) {
for (int i = 0; i < data.length; ++i) {
if (parsedData[i] != data[i]) {
return false;
}
}
return true;
}
for (int i = 0; i < data.length; ++i) {
if ((dataMask[i] & parsedData[i]) != (dataMask[i] & data[i])) {
return false;
}
}
return true;
|
private boolean | matchesServiceUuid(java.util.UUID uuid, java.util.UUID mask, java.util.UUID data)
if (mask == null) {
return uuid.equals(data);
}
if ((uuid.getLeastSignificantBits() & mask.getLeastSignificantBits()) !=
(data.getLeastSignificantBits() & mask.getLeastSignificantBits())) {
return false;
}
return ((uuid.getMostSignificantBits() & mask.getMostSignificantBits()) ==
(data.getMostSignificantBits() & mask.getMostSignificantBits()));
|
private boolean | matchesServiceUuids(android.os.ParcelUuid uuid, android.os.ParcelUuid parcelUuidMask, java.util.List 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;
|
public java.lang.String | toString()
return "BluetoothLeScanFilter [mDeviceName=" + mDeviceName + ", mDeviceAddress="
+ mDeviceAddress
+ ", mUuid=" + mServiceUuid + ", mUuidMask=" + mServiceUuidMask
+ ", mServiceDataUuid=" + Objects.toString(mServiceDataUuid) + ", mServiceData="
+ Arrays.toString(mServiceData) + ", mServiceDataMask="
+ Arrays.toString(mServiceDataMask) + ", mManufacturerId=" + mManufacturerId
+ ", mManufacturerData=" + Arrays.toString(mManufacturerData)
+ ", mManufacturerDataMask=" + Arrays.toString(mManufacturerDataMask) + "]";
|
public void | writeToParcel(android.os.Parcel dest, int flags)
dest.writeInt(mDeviceName == null ? 0 : 1);
if (mDeviceName != null) {
dest.writeString(mDeviceName);
}
dest.writeInt(mDeviceAddress == null ? 0 : 1);
if (mDeviceAddress != null) {
dest.writeString(mDeviceAddress);
}
dest.writeInt(mServiceUuid == null ? 0 : 1);
if (mServiceUuid != null) {
dest.writeParcelable(mServiceUuid, flags);
dest.writeInt(mServiceUuidMask == null ? 0 : 1);
if (mServiceUuidMask != null) {
dest.writeParcelable(mServiceUuidMask, flags);
}
}
dest.writeInt(mServiceDataUuid == null ? 0 : 1);
if (mServiceDataUuid != null) {
dest.writeParcelable(mServiceDataUuid, flags);
dest.writeInt(mServiceData == null ? 0 : 1);
if (mServiceData != null) {
dest.writeInt(mServiceData.length);
dest.writeByteArray(mServiceData);
dest.writeInt(mServiceDataMask == null ? 0 : 1);
if (mServiceDataMask != null) {
dest.writeInt(mServiceDataMask.length);
dest.writeByteArray(mServiceDataMask);
}
}
}
dest.writeInt(mManufacturerId);
dest.writeInt(mManufacturerData == null ? 0 : 1);
if (mManufacturerData != null) {
dest.writeInt(mManufacturerData.length);
dest.writeByteArray(mManufacturerData);
dest.writeInt(mManufacturerDataMask == null ? 0 : 1);
if (mManufacturerDataMask != null) {
dest.writeInt(mManufacturerDataMask.length);
dest.writeByteArray(mManufacturerDataMask);
}
}
|