diff options
author | Wei Wang <weiwa@google.com> | 2014-07-25 15:14:55 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2014-07-27 23:12:26 -0700 |
commit | ab2ed62f15d0dac0f8ef825ff2d3677c9ae18f44 (patch) | |
tree | 017c806c09540c337bb47bae3d915865183cb3c4 /core/java/android/bluetooth | |
parent | 56e079efc672bdc129a759630fd579f63d0eea02 (diff) | |
download | frameworks_base-ab2ed62f15d0dac0f8ef825ff2d3677c9ae18f44.zip frameworks_base-ab2ed62f15d0dac0f8ef825ff2d3677c9ae18f44.tar.gz frameworks_base-ab2ed62f15d0dac0f8ef825ff2d3677c9ae18f44.tar.bz2 |
Split manu id and manu data.
b/16407380
Change-Id: I39f6ce0ab4cccadec809f0a4f518f5d2c77a90b7
Diffstat (limited to 'core/java/android/bluetooth')
-rw-r--r-- | core/java/android/bluetooth/le/ScanFilter.java | 35 | ||||
-rw-r--r-- | core/java/android/bluetooth/le/ScanRecord.java | 13 | ||||
-rw-r--r-- | core/java/android/bluetooth/le/ScanResult.java | 4 |
3 files changed, 35 insertions, 17 deletions
diff --git a/core/java/android/bluetooth/le/ScanFilter.java b/core/java/android/bluetooth/le/ScanFilter.java index 0ae11b0..2ce18b0 100644 --- a/core/java/android/bluetooth/le/ScanFilter.java +++ b/core/java/android/bluetooth/le/ScanFilter.java @@ -107,7 +107,7 @@ public final class ScanFilter implements Parcelable { dest.writeParcelable(mServiceUuidMask, flags); } } - dest.writeInt(mServiceDataUuid == null? 0 : 1); + dest.writeInt(mServiceDataUuid == null ? 0 : 1); if (mServiceDataUuid != null) { dest.writeParcelable(mServiceDataUuid, flags); dest.writeInt(mServiceData == null ? 0 : mServiceData.length); @@ -235,6 +235,14 @@ public final class ScanFilter implements Parcelable { } /** + * @hide + */ + @Nullable + public ParcelUuid getServiceDataUuid() { + return mServiceDataUuid; + } + + /** * Returns the manufacturer id. -1 if the manufacturer filter is not set. */ public int getManufacturerId() { @@ -287,15 +295,21 @@ public final class ScanFilter implements Parcelable { } // Service data match - if (mServiceData != null && - !matchesPartialData(mServiceData, mServiceDataMask, scanRecord.getServiceData())) { - return false; + if (mServiceData != null) { + if (!Objects.equals(mServiceDataUuid, scanRecord.getServiceDataUuid()) || + !matchesPartialData(mServiceData, mServiceDataMask, + scanRecord.getServiceData())) { + return false; + } } // Manufacturer data match. - if (mManufacturerData != null && !matchesPartialData(mManufacturerData, - mManufacturerDataMask, scanRecord.getManufacturerSpecificData())) { - return false; + if (mManufacturerData != null) { + if (mManufacturerId != scanRecord.getManufacturerId() || + !matchesPartialData(mManufacturerData, + mManufacturerDataMask, scanRecord.getManufacturerSpecificData())) { + return false; + } } // All filters match. return true; @@ -353,7 +367,8 @@ public final class ScanFilter implements Parcelable { public String toString() { return "BluetoothLeScanFilter [mDeviceName=" + mDeviceName + ", mDeviceAddress=" + mDeviceAddress - + ", mUuid=" + mServiceUuid + ", mUuidMask=" + mServiceUuidMask + ", mServiceData=" + + ", mUuid=" + mServiceUuid + ", mUuidMask=" + mServiceUuidMask + + ", mServiceDataUuid=" + Objects.toString(mServiceDataUuid) + ", mServiceData=" + Arrays.toString(mServiceData) + ", mServiceDataMask=" + Arrays.toString(mServiceDataMask) + ", mManufacturerId=" + mManufacturerId + ", mManufacturerData=" + Arrays.toString(mManufacturerData) @@ -363,7 +378,7 @@ public final class ScanFilter implements Parcelable { @Override public int hashCode() { return Objects.hash(mDeviceName, mDeviceAddress, mManufacturerId, mManufacturerData, - mManufacturerDataMask, mServiceData, mServiceDataMask, + mManufacturerDataMask, mServiceDataUuid, mServiceData, mServiceDataMask, mServiceUuid, mServiceUuidMask); } @@ -381,6 +396,7 @@ public final class ScanFilter implements Parcelable { 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) && @@ -498,6 +514,7 @@ public final class ScanFilter implements Parcelable { "size mismatch for service data and service data mask"); } } + mServiceDataUuid = serviceDataUuid; mServiceData = serviceData; mServiceDataMask = serviceDataMask; return this; diff --git a/core/java/android/bluetooth/le/ScanRecord.java b/core/java/android/bluetooth/le/ScanRecord.java index dd03308..e564c7d 100644 --- a/core/java/android/bluetooth/le/ScanRecord.java +++ b/core/java/android/bluetooth/le/ScanRecord.java @@ -225,20 +225,21 @@ public final class ScanRecord { txPowerLevel = scanRecord[currentPos]; break; case DATA_TYPE_SERVICE_DATA: - serviceData = extractBytes(scanRecord, currentPos, dataLength); - // The first two bytes of the service data are service data UUID. + // The first two bytes of the service data are service data UUID in little + // endian. The rest bytes are service data. int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT; byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength); serviceDataUuid = BluetoothUuid.parseUuidFrom(serviceDataUuidBytes); + serviceData = extractBytes(scanRecord, currentPos + 2, dataLength - 2); break; case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA: - manufacturerSpecificData = extractBytes(scanRecord, currentPos, - dataLength); // The first two bytes of the manufacturer specific data are // manufacturer ids in little endian. - manufacturerId = ((manufacturerSpecificData[1] & 0xFF) << 8) + - (manufacturerSpecificData[0] & 0xFF); + manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8) + + (scanRecord[currentPos] & 0xFF); + manufacturerSpecificData = extractBytes(scanRecord, currentPos + 2, + dataLength - 2); break; default: // Just ignore, we don't handle such data type. diff --git a/core/java/android/bluetooth/le/ScanResult.java b/core/java/android/bluetooth/le/ScanResult.java index 9aee200..a0bdaff 100644 --- a/core/java/android/bluetooth/le/ScanResult.java +++ b/core/java/android/bluetooth/le/ScanResult.java @@ -69,7 +69,7 @@ public final class ScanResult implements Parcelable { dest.writeInt(0); } if (mScanRecord != null) { - dest.writeInt(mScanRecord.getBytes().length); + dest.writeInt(1); dest.writeByteArray(mScanRecord.getBytes()); } else { dest.writeInt(0); @@ -145,7 +145,7 @@ public final class ScanResult implements Parcelable { @Override public String toString() { return "ScanResult{" + "mDevice=" + mDevice + ", mScanRecord=" - + mScanRecord.toString() + ", mRssi=" + mRssi + ", mTimestampNanos=" + + Objects.toString(mScanRecord) + ", mRssi=" + mRssi + ", mTimestampNanos=" + mTimestampNanos + '}'; } |