OSDN Git Service

Fix advertise data size estimation
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 31 Mar 2017 23:49:13 +0000 (16:49 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Fri, 31 Mar 2017 23:52:48 +0000 (16:52 -0700)
UUID in service data field can be 2, 4, or 16 bytes long.

Test: manual
Bug: 36553478
Change-Id: Ib5ba2d16065496ca311e8642a15a7ea6bc84d4c1

core/java/android/bluetooth/le/BluetoothLeAdvertiser.java

index 242ee77..07d9b6d 100644 (file)
@@ -56,7 +56,6 @@ public final class BluetoothLeAdvertiser {
     // Flags field will be set by system.
     private static final int FLAGS_FIELD_BYTES = 3;
     private static final int MANUFACTURER_SPECIFIC_DATA_LENGTH = 2;
-    private static final int SERVICE_DATA_UUID_LENGTH = 2;
 
     private final IBluetoothManager mBluetoothManager;
     private final Handler mHandler;
@@ -383,7 +382,8 @@ public final class BluetoothLeAdvertiser {
             }
         }
         for (ParcelUuid uuid : data.getServiceData().keySet()) {
-            size += OVERHEAD_BYTES_PER_FIELD + SERVICE_DATA_UUID_LENGTH
+            int uuidLen = BluetoothUuid.uuidToBytes(uuid).length;
+            size += OVERHEAD_BYTES_PER_FIELD + uuidLen
                     + byteLength(data.getServiceData().get(uuid));
         }
         for (int i = 0; i < data.getManufacturerSpecificData().size(); ++i) {