summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/ScanResult.java
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2014-07-16 22:02:03 -0700
committerWei Wang <weiwa@google.com>2014-07-18 18:31:00 -0700
commit0afb91d1a96bb0068f9b32ec9a99f8391feb5537 (patch)
tree8b28a67077d0d46b2e850a9cd6d947e20e7ecc03 /framework/java/android/bluetooth/le/ScanResult.java
parent23bde57df4ffc46f8d518f775c2367bda84c78e3 (diff)
More API modification of BLE APIs (1/2).
Changed include: 1) Add serviceDataUuid to filter so it matches sanRecord and AdvertiseData. 2) Add raw bytes to ScanRecord and make ScanResult take a ScanRecord instead of raw bytes. 3) Change from setServiceUuid(List) to addServiceUuid(ParcelUuid). 4) Added include device name 5) Removed service not registered and added ADVERTISE_DATA_TOO_LARGE. 6) Fixed a few comments. Change-Id: Ibbe07183b1293835c4a84728d1cd2d61e5d627d3
Diffstat (limited to 'framework/java/android/bluetooth/le/ScanResult.java')
-rw-r--r--framework/java/android/bluetooth/le/ScanResult.java29
1 files changed, 17 insertions, 12 deletions
diff --git a/framework/java/android/bluetooth/le/ScanResult.java b/framework/java/android/bluetooth/le/ScanResult.java
index 7e6e8f81c7..9aee20094a 100644
--- a/framework/java/android/bluetooth/le/ScanResult.java
+++ b/framework/java/android/bluetooth/le/ScanResult.java
@@ -21,7 +21,6 @@ import android.bluetooth.BluetoothDevice;
import android.os.Parcel;
import android.os.Parcelable;
-import java.util.Arrays;
import java.util.Objects;
/**
@@ -32,7 +31,8 @@ public final class ScanResult implements Parcelable {
private BluetoothDevice mDevice;
// Scan record, including advertising data and scan response data.
- private byte[] mScanRecord;
+ @Nullable
+ private ScanRecord mScanRecord;
// Received signal strength.
private int mRssi;
@@ -43,9 +43,12 @@ public final class ScanResult implements Parcelable {
/**
* Constructor of scan result.
*
- * @hide
+ * @param device Remote bluetooth device that is found.
+ * @param scanRecord Scan record including both advertising data and scan response data.
+ * @param rssi Received signal strength.
+ * @param timestampNanos Device timestamp when the scan result was observed.
*/
- public ScanResult(BluetoothDevice device, byte[] scanRecord, int rssi,
+ public ScanResult(BluetoothDevice device, ScanRecord scanRecord, int rssi,
long timestampNanos) {
mDevice = device;
mScanRecord = scanRecord;
@@ -66,8 +69,8 @@ public final class ScanResult implements Parcelable {
dest.writeInt(0);
}
if (mScanRecord != null) {
- dest.writeInt(1);
- dest.writeByteArray(mScanRecord);
+ dest.writeInt(mScanRecord.getBytes().length);
+ dest.writeByteArray(mScanRecord.getBytes());
} else {
dest.writeInt(0);
}
@@ -80,7 +83,7 @@ public final class ScanResult implements Parcelable {
mDevice = BluetoothDevice.CREATOR.createFromParcel(in);
}
if (in.readInt() == 1) {
- mScanRecord = in.createByteArray();
+ mScanRecord = ScanRecord.parseFromBytes(in.createByteArray());
}
mRssi = in.readInt();
mTimestampNanos = in.readLong();
@@ -94,16 +97,15 @@ public final class ScanResult implements Parcelable {
/**
* Returns the remote bluetooth device identified by the bluetooth device address.
*/
- @Nullable
public BluetoothDevice getDevice() {
return mDevice;
}
/**
- * Returns the scan record, which can be a combination of advertisement and scan response.
+ * Returns the scan record, which is a combination of advertisement and scan response.
*/
@Nullable
- public byte[] getScanRecord() {
+ public ScanRecord getScanRecord() {
return mScanRecord;
}
@@ -136,17 +138,20 @@ public final class ScanResult implements Parcelable {
}
ScanResult other = (ScanResult) obj;
return Objects.equals(mDevice, other.mDevice) && (mRssi == other.mRssi) &&
- Objects.deepEquals(mScanRecord, other.mScanRecord)
+ Objects.equals(mScanRecord, other.mScanRecord)
&& (mTimestampNanos == other.mTimestampNanos);
}
@Override
public String toString() {
return "ScanResult{" + "mDevice=" + mDevice + ", mScanRecord="
- + Arrays.toString(mScanRecord) + ", mRssi=" + mRssi + ", mTimestampNanos="
+ + mScanRecord.toString() + ", mRssi=" + mRssi + ", mTimestampNanos="
+ mTimestampNanos + '}';
}
+ /**
+ * @hide
+ */
public static final Parcelable.Creator<ScanResult> CREATOR = new Creator<ScanResult>() {
@Override
public ScanResult createFromParcel(Parcel source) {