diff options
author | Wei Wang <weiwa@google.com> | 2014-08-04 21:08:34 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2014-08-04 22:21:38 -0700 |
commit | 475a4f7727a082ccf289ce406e75c463750a515c (patch) | |
tree | 03202ef63ecd8e3798627e3deada0c712cabc061 /src/com/android/bluetooth/gatt | |
parent | 62fb56f2ba7d998e3e7416fc19d25ea91cc85111 (diff) | |
download | android_packages_apps_Bluetooth-475a4f7727a082ccf289ce406e75c463750a515c.tar.gz android_packages_apps_Bluetooth-475a4f7727a082ccf289ce406e75c463750a515c.tar.bz2 android_packages_apps_Bluetooth-475a4f7727a082ccf289ce406e75c463750a515c.zip |
Workaround for reversed mac addresses in batch scan.
b/16803363
Change-Id: I47299ed2a6191e7f05c229feb1f1f0424e486907
Diffstat (limited to 'src/com/android/bluetooth/gatt')
-rw-r--r-- | src/com/android/bluetooth/gatt/GattService.java | 19 | ||||
-rw-r--r-- | src/com/android/bluetooth/gatt/ScanManager.java | 5 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java index a50149be3..92a69c016 100644 --- a/src/com/android/bluetooth/gatt/GattService.java +++ b/src/com/android/bluetooth/gatt/GattService.java @@ -33,7 +33,6 @@ import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; import android.content.Intent; import android.os.IBinder; -import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; import android.os.SystemClock; @@ -49,7 +48,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -975,11 +973,14 @@ public class GattService extends ProfileService { } private Set<ScanResult> parseTruncatedResults(int numRecords, byte[] batchRecord) { + if (DBG) Log.d(TAG, "batch record " + Arrays.toString(batchRecord)); Set<ScanResult> results = new HashSet<ScanResult>(numRecords); for (int i = 0; i < numRecords; ++i) { byte[] record = extractBytes(batchRecord, i * TRUNCATED_RESULT_SIZE, TRUNCATED_RESULT_SIZE); - byte[] address = extractBytes(batchRecord, 0, 6); + byte[] address = extractBytes(record, 0, 6); + // TODO: remove temp hack. + reverse(address); BluetoothDevice device = mAdapter.getRemoteDevice(address); int rssi = record[8]; // Timestamp is in every 50 ms. @@ -1003,6 +1004,8 @@ public class GattService extends ProfileService { int position = 0; while (position < batchRecord.length) { byte[] address = extractBytes(batchRecord, position, 6); + // TODO: remove temp hack. + reverse(address); BluetoothDevice device = mAdapter.getRemoteDevice(address); position += 6; // Skip address type. @@ -1031,6 +1034,16 @@ public class GattService extends ProfileService { return results; } + // Reverse byte array. + private void reverse(byte[] address) { + int len = address.length; + for (int i = 0; i < len / 2; ++i) { + byte b = address[i]; + address[i] = address[len - 1 - i]; + address[len - 1 - i] = b; + } + } + // Helper method to extract bytes from byte array. private static byte[] extractBytes(byte[] scanRecord, int start, int length) { byte[] bytes = new byte[length]; diff --git a/src/com/android/bluetooth/gatt/ScanManager.java b/src/com/android/bluetooth/gatt/ScanManager.java index d44f1ab21..e6e8a42df 100644 --- a/src/com/android/bluetooth/gatt/ScanManager.java +++ b/src/com/android/bluetooth/gatt/ScanManager.java @@ -256,7 +256,6 @@ public class ScanManager { private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000; private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000; - // The logic is AND for each filter field. private static final int LIST_LOGIC_TYPE = 0x1111111; private static final int FILTER_LOGIC_TYPE = 1; @@ -386,8 +385,8 @@ public class ScanManager { waitForCallback(); int scanMode = getResultType(client.settings); // TODO: configure scan parameters. - int scanIntervalUnit = 8; - int scanWindowUnit = 8; + int scanIntervalUnit = 2400; + int scanWindowUnit = 2400; int discardRule = DISCARD_OLDEST_WHEN_BUFFER_FULL; int addressType = 0; logd("Starting BLE batch scan, scanMode -" + scanMode); |