OSDN Git Service

Vectors as parameters to GATT (1/3)
authorJakub Pawlowski <jpawlowski@google.com>
Tue, 31 May 2016 20:14:13 +0000 (13:14 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Mon, 20 Jun 2016 21:52:27 +0000 (14:52 -0700)
Bug: 29005882
Bug: 28485365
Change-Id: I0a5041073a39977c4fbc29879c383fa6720da641

18 files changed:
btif/include/btif_gatt_multi_adv_util.h
btif/src/btif_gatt_client.cc
btif/src/btif_gatt_multi_adv_util.cc
btif/src/btif_gatt_server.cc
service/gatt_server.cc
service/gatt_server.h
service/gatt_server_old.cc
service/hal/bluetooth_gatt_interface.cc
service/hal/bluetooth_gatt_interface.h
service/hal/fake_bluetooth_gatt_interface.cc
service/hal/fake_bluetooth_gatt_interface.h
service/low_energy_client.cc
service/low_energy_client.h
service/test/gatt_client_unittest.cc
service/test/gatt_server_unittest.cc
service/test/low_energy_client_unittest.cc
test/suite/gatt/gatt_test.cc
test/suite/gatt/gatt_test.h

index 23f0665..9917cdb 100644 (file)
@@ -84,8 +84,8 @@ extern BOOLEAN btif_gattc_copy_datacb(int arrindex, const btif_adv_data_t *p_adv
                                             BOOLEAN bInstData);
 extern void btif_gattc_adv_data_packager(int client_if, bool set_scan_rsp,
                 bool include_name, bool include_txpower, int min_interval, int max_interval,
-                int appearance, int manufacturer_len, char* manufacturer_data,
-                int service_data_len, char* service_data, int service_uuid_len,
-                char* service_uuid, btif_adv_data_t *p_multi_adv_inst);
+                int appearance, const vector<uint8_t> &manufacturer_data,
+                const vector<uint8_t> &service_data, const vector<uint8_t> &service_uuid,
+                btif_adv_data_t *p_multi_adv_inst);
 extern void btif_gattc_adv_data_cleanup(btif_adv_data_t* adv);
 void btif_multi_adv_timer_ctrl(int client_if, alarm_callback_t cb);
index 4499bd1..54f68a7 100644 (file)
@@ -470,8 +470,7 @@ void bta_batch_scan_setup_cb(tBTA_BLE_BATCH_SCAN_EVT evt,
     }
 
     case BTA_BLE_BATCH_SCAN_DATA_EVT: {
-      CLI_CBACK_IN_JNI(batchscan_reports_cb, ref_value, status, 0, 0, 0,
-                       nullptr);
+      CLI_CBACK_IN_JNI(batchscan_reports_cb, ref_value, status, 0, 0, vector<uint8_t>());
       return;
     }
 
@@ -497,31 +496,34 @@ void bta_batch_scan_reports_cb(tBTA_DM_BLE_REF_VALUE ref_value,
                    status, num_records, data_len);
 
   if (data_len > 0) {
-    uint8_t *data = new uint8_t[data_len];
-    memcpy(data, p_rep_data, data_len);
+
+    vector<uint8_t> data(p_rep_data, p_rep_data + data_len);
     osi_free(p_rep_data);
 
     CLI_CBACK_IN_JNI(batchscan_reports_cb, ref_value, status, report_format,
-                     num_records, data_len, Owned(data));
+                     num_records, std::move(data));
   } else {
     CLI_CBACK_IN_JNI(batchscan_reports_cb, ref_value, status, report_format,
-                     num_records, 0, nullptr);
+                     num_records, vector<uint8_t>());
   }
 }
 
 void bta_scan_results_cb_impl(bt_bdaddr_t bd_addr, tBT_DEVICE_TYPE device_type,
-                              int8_t rssi, uint8_t addr_type, uint8_t *value) {
+                              int8_t rssi, uint8_t addr_type,
+                              vector<uint8_t> value) {
   uint8_t remote_name_len;
-  uint8_t *p_eir_remote_name = NULL;
+  const uint8_t *p_eir_remote_name = NULL;
   bt_device_type_t dev_type;
   bt_property_t properties;
 
-  p_eir_remote_name = BTM_CheckEirData(value, BTM_EIR_COMPLETE_LOCAL_NAME_TYPE,
+  p_eir_remote_name = BTM_CheckEirData(value.data(),
+                                       BTM_EIR_COMPLETE_LOCAL_NAME_TYPE,
                                        &remote_name_len);
 
   if (p_eir_remote_name == NULL) {
-    p_eir_remote_name = BTM_CheckEirData(
-        value, BT_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
+    p_eir_remote_name = BTM_CheckEirData(value.data(),
+                                         BT_EIR_SHORTENED_LOCAL_NAME_TYPE,
+                                         &remote_name_len);
   }
 
   if ((addr_type != BLE_ADDR_RANDOM) || (p_eir_remote_name)) {
@@ -548,7 +550,7 @@ void bta_scan_results_cb_impl(bt_bdaddr_t bd_addr, tBT_DEVICE_TYPE device_type,
 
   btif_storage_set_remote_addr_type(&bd_addr, addr_type);
 
-  HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb, &bd_addr, rssi, value);
+  HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb, &bd_addr, rssi, std::move(value));
 }
 
 void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) {
@@ -565,9 +567,9 @@ void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) {
     return;
   }
 
-  uint8_t *value = new uint8_t[BTGATT_MAX_ATTR_LEN];
+  vector<uint8_t> value(BTGATT_MAX_ATTR_LEN);
   if (p_data->inq_res.p_eir) {
-    memcpy(value, p_data->inq_res.p_eir, 62);
+    value.insert(value.begin(), p_data->inq_res.p_eir, p_data->inq_res.p_eir + 62);
 
     if (BTM_CheckEirData(p_data->inq_res.p_eir,
                          BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &len)) {
@@ -579,7 +581,7 @@ void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) {
   bdcpy(bdaddr.address, p_data->inq_res.bd_addr);
   do_in_jni_thread(Bind(bta_scan_results_cb_impl, bdaddr,
                         p_data->inq_res.device_type, p_data->inq_res.rssi,
-                        p_data->inq_res.ble_addr_type, Owned(value)));
+                        p_data->inq_res.ble_addr_type, std::move(value)));
 }
 
 void bta_track_adv_event_cb(tBTA_DM_BLE_TRACK_ADV_DATA *p_track_adv_data) {
@@ -787,17 +789,16 @@ void btif_gattc_set_adv_data_impl(btif_adv_data_t *p_adv_data) {
 bt_status_t btif_gattc_set_adv_data(
     int client_if, bool set_scan_rsp, bool include_name, bool include_txpower,
     int min_interval, int max_interval, int appearance,
-    uint16_t manufacturer_len, char *manufacturer_data,
-    uint16_t service_data_len, char *service_data, uint16_t service_uuid_len,
-    char *service_uuid) {
+    vector<uint8_t> manufacturer_data, vector<uint8_t> service_data,
+    vector<uint8_t> service_uuid) {
   CHECK_BTGATT_INIT();
 
   btif_adv_data_t *adv_data = new btif_adv_data_t;
 
   btif_gattc_adv_data_packager(
       client_if, set_scan_rsp, include_name, include_txpower, min_interval,
-      max_interval, appearance, manufacturer_len, manufacturer_data,
-      service_data_len, service_data, service_uuid_len, service_uuid, adv_data);
+      max_interval, appearance, std::move(manufacturer_data), std::move(service_data),
+      std::move(service_uuid), adv_data);
 
   return do_in_jni_thread(
       Bind(&btif_gattc_set_adv_data_impl, base::Owned(adv_data)));
@@ -1011,45 +1012,45 @@ void btif_gattc_scan_filter_add_srvc_uuid(tBT_UUID uuid,
                               &bta_scan_filt_cfg_cb, client_if);
 }
 
-void btif_gattc_scan_filter_add_local_name(uint8_t *data, int data_len,
+void btif_gattc_scan_filter_add_local_name(vector<uint8_t> data,
                                            int action, int filt_type,
                                            int filt_index, int client_if) {
   tBTA_DM_BLE_PF_COND_PARAM cond;
   memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
 
-  cond.local_name.data_len = data_len;
-  cond.local_name.p_data = data;
+  cond.local_name.data_len = data.size();
+  cond.local_name.p_data = const_cast<uint8_t*>(data.data());
   BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
                               &bta_scan_filt_cfg_cb, client_if);
 }
 
 void btif_gattc_scan_filter_add_manu_data(int company_id, int company_id_mask,
-                                          uint8_t *pattern, int pattern_len,
-                                          uint8_t *pattern_mask, int action,
-                                          int filt_type, int filt_index,
-                                          int client_if) {
+                                          vector<uint8_t> pattern,
+                                          vector<uint8_t> pattern_mask,
+                                          int action, int filt_type,
+                                          int filt_index, int client_if) {
   tBTA_DM_BLE_PF_COND_PARAM cond;
   memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
 
   cond.manu_data.company_id = company_id;
   cond.manu_data.company_id_mask = company_id_mask ? company_id_mask : 0xFFFF;
-  cond.manu_data.data_len = pattern_len;
-  cond.manu_data.p_pattern = pattern;
-  cond.manu_data.p_pattern_mask = pattern_mask;
+  cond.manu_data.data_len = pattern.size();
+  cond.manu_data.p_pattern = const_cast<uint8_t*>(pattern.data());
+  cond.manu_data.p_pattern_mask = const_cast<uint8_t*>(pattern_mask.data());
   BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
                               &bta_scan_filt_cfg_cb, client_if);
 }
 
-void btif_gattc_scan_filter_add_data_pattern(uint8_t *pattern, int pattern_len,
-                                             uint8_t *pattern_mask, int action,
-                                             int filt_type, int filt_index,
-                                             int client_if) {
+void btif_gattc_scan_filter_add_data_pattern(vector<uint8_t> pattern,
+                                             vector<uint8_t> pattern_mask,
+                                             int action, int filt_type,
+                                             int filt_index, int client_if) {
   tBTA_DM_BLE_PF_COND_PARAM cond;
   memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
 
-  cond.srvc_data.data_len = pattern_len;
-  cond.srvc_data.p_pattern = pattern;
-  cond.srvc_data.p_pattern_mask = pattern_mask;
+  cond.srvc_data.data_len = pattern.size();
+  cond.srvc_data.p_pattern = const_cast<uint8_t*>(pattern.data());
+  cond.srvc_data.p_pattern_mask = const_cast<uint8_t*>(pattern_mask.data());
   BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
                               &bta_scan_filt_cfg_cb, client_if);
 }
@@ -1057,13 +1058,13 @@ void btif_gattc_scan_filter_add_data_pattern(uint8_t *pattern, int pattern_len,
 bt_status_t btif_gattc_scan_filter_add_remove(
     int client_if, int action, int filt_type, int filt_index, int company_id,
     int company_id_mask, const bt_uuid_t *p_uuid, const bt_uuid_t *p_uuid_mask,
-    const bt_bdaddr_t *bd_addr, char addr_type, int data_len, char *p_data,
-    int mask_len, char *p_mask) {
+    const bt_bdaddr_t *bd_addr, char addr_type, vector<uint8_t> data,
+    vector<uint8_t> mask) {
   CHECK_BTGATT_INIT();
   BTIF_TRACE_DEBUG("%s, %d, %d", __FUNCTION__, action, filt_type);
 
   /* If data is passed, both mask and data have to be the same length */
-  if (data_len != mask_len && NULL != p_data && NULL != p_mask)
+  if (data.size() != mask.size() && data.size() != 0 && mask.size() != 0)
     return BT_STATUS_PARM_INVALID;
 
   switch (filt_type) {
@@ -1118,37 +1119,24 @@ bt_status_t btif_gattc_scan_filter_add_remove(
 
     case BTA_DM_BLE_PF_LOCAL_NAME:  // 4
     {
-      uint8_t *data = new uint8_t[data_len];
-      memcpy(data, p_data, data_len);
       return do_in_jni_thread(Bind(&btif_gattc_scan_filter_add_local_name,
-                                   base::Owned(data), data_len, action,
-                                   filt_type, filt_index, client_if));
+                                   std::move(data), action, filt_type,
+                                   filt_index, client_if));
     }
 
     case BTA_DM_BLE_PF_MANU_DATA:  // 5
     {
-      uint8_t *data = new uint8_t[data_len];
-      memcpy(data, p_data, data_len);
-
-      uint8_t *mask = new uint8_t[data_len];
-      memcpy(mask, p_mask, data_len);
       return do_in_jni_thread(
           Bind(&btif_gattc_scan_filter_add_manu_data, company_id,
-               company_id_mask, base::Owned(data), data_len, base::Owned(mask),
-               action, filt_type, filt_index, client_if));
+               company_id_mask, std::move(data), std::move(mask), action,
+               filt_type, filt_index, client_if));
     }
 
     case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:  // 6
     {
-      uint8_t *data = new uint8_t[data_len];
-      memcpy(data, p_data, data_len);
-
-      uint8_t *mask = new uint8_t[data_len];
-      memcpy(mask, p_mask, data_len);
-
       return do_in_jni_thread(Bind(
-          &btif_gattc_scan_filter_add_data_pattern, base::Owned(data), data_len,
-          base::Owned(mask), action, filt_type, filt_index, client_if));
+          &btif_gattc_scan_filter_add_data_pattern, std::move(data),
+          std::move(mask), action, filt_type, filt_index, client_if));
     }
 
     default:
@@ -1298,9 +1286,8 @@ void btif_gattc_multi_adv_setdata_impl(btif_adv_data_t *p_adv_data) {
 
 bt_status_t btif_gattc_multi_adv_setdata(
     int client_if, bool set_scan_rsp, bool include_name, bool incl_txpower,
-    int appearance, int manufacturer_len, char *manufacturer_data,
-    int service_data_len, char *service_data, int service_uuid_len,
-    char *service_uuid) {
+    int appearance, vector<uint8_t> manufacturer_data,
+    vector<uint8_t> service_data, vector<uint8_t> service_uuid) {
   CHECK_BTGATT_INIT();
 
   btif_adv_data_t *multi_adv_data_inst = new btif_adv_data_t;
@@ -1310,9 +1297,9 @@ bt_status_t btif_gattc_multi_adv_setdata(
 
   btif_gattc_adv_data_packager(client_if, set_scan_rsp, include_name,
                                incl_txpower, min_interval, max_interval,
-                               appearance, manufacturer_len, manufacturer_data,
-                               service_data_len, service_data, service_uuid_len,
-                               service_uuid, multi_adv_data_inst);
+                               appearance, std::move(manufacturer_data),
+                               std::move(service_data), std::move(service_uuid),
+                               multi_adv_data_inst);
 
   return do_in_jni_thread(Bind(&btif_gattc_multi_adv_setdata_impl,
                                base::Owned(multi_adv_data_inst)));
index 134be38..e7f2296 100644 (file)
@@ -209,9 +209,9 @@ int btif_gattc_obtain_idx_for_datacb(int value, int clnt_inst_index)
 
 void btif_gattc_adv_data_packager(int client_if, bool set_scan_rsp,
                 bool include_name, bool include_txpower, int min_interval, int max_interval,
-                int appearance, int manufacturer_len, char* manufacturer_data,
-                int service_data_len, char* service_data, int service_uuid_len,
-                char* service_uuid, btif_adv_data_t *p_multi_adv_inst)
+                int appearance, const vector<uint8_t> &manufacturer_data,
+                const vector<uint8_t> &service_data, const vector<uint8_t> &service_uuid,
+                btif_adv_data_t *p_multi_adv_inst)
 {
     memset(p_multi_adv_inst, 0 , sizeof(btif_adv_data_t));
 
@@ -223,31 +223,34 @@ void btif_gattc_adv_data_packager(int client_if, bool set_scan_rsp,
     p_multi_adv_inst->max_interval = max_interval;
     p_multi_adv_inst->appearance = appearance;
 
-    if (manufacturer_len > 0)
+    if (manufacturer_data.size() > 0)
     {
+        size_t manufacturer_len = manufacturer_data.size();
         if (manufacturer_len > MAX_SIZE_MANUFACTURER_DATA)
             manufacturer_len = MAX_SIZE_MANUFACTURER_DATA;
 
         p_multi_adv_inst->manufacturer_len = manufacturer_len;
-        memcpy(p_multi_adv_inst->p_manufacturer_data, manufacturer_data, manufacturer_len);
+        memcpy(p_multi_adv_inst->p_manufacturer_data, manufacturer_data.data(), manufacturer_len);
     }
 
-    if (service_data_len > 0)
+    if (service_data.size() > 0)
     {
+        size_t service_data_len = service_data.size();
         if (service_data_len > MAX_SIZE_PROPRIETARY_ELEMENT)
             service_data_len = MAX_SIZE_PROPRIETARY_ELEMENT;
 
         p_multi_adv_inst->service_data_len = service_data_len;
-        memcpy(p_multi_adv_inst->p_service_data, service_data, service_data_len);
+        memcpy(p_multi_adv_inst->p_service_data, service_data.data(), service_data_len);
     }
 
-    if (service_uuid_len > 0)
+    if (service_uuid.size() > 0)
     {
+        size_t service_uuid_len = service_uuid.size();
         if (service_uuid_len > MAX_SIZE_SERVICE_DATA)
             service_uuid_len = MAX_SIZE_SERVICE_DATA;
 
         p_multi_adv_inst->service_uuid_len = service_uuid_len;
-        memcpy(p_multi_adv_inst->p_service_uuid, service_uuid, service_uuid_len);
+        memcpy(p_multi_adv_inst->p_service_uuid, service_uuid.data(), service_uuid_len);
     }
 }
 
index 5d08e07..a5623ed 100644 (file)
@@ -255,15 +255,11 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param)
         {
             bt_bdaddr_t bda;
             bdcpy(bda.address, p_data->req_data.remote_bda);
-
+            const auto &req = p_data->req_data.p_data->write_req;
+            vector<uint8_t> value(req.value, req.value + req.len);
             HAL_CBACK(bt_gatt_callbacks, server->request_write_cb,
                       p_data->req_data.conn_id,p_data->req_data.trans_id, &bda,
-                      p_data->req_data.p_data->write_req.handle,
-                      p_data->req_data.p_data->write_req.offset,
-                      p_data->req_data.p_data->write_req.len,
-                      p_data->req_data.p_data->write_req.need_rsp,
-                      p_data->req_data.p_data->write_req.is_prep,
-                      p_data->req_data.p_data->write_req.value);
+                      req.handle, req.offset, req.need_rsp, req.is_prep, value);
             break;
         }
 
index 41dd2f1..0180eb4 100644 (file)
@@ -689,15 +689,11 @@ void GattServer::RequestWriteCallback(
     hal::BluetoothGattInterface* /* gatt_iface */,
     int conn_id, int trans_id,
     const bt_bdaddr_t& bda,
-    int attr_handle, int offset, int length,
-    bool need_rsp, bool is_prep, uint8_t* value) {
+    int attr_handle, int offset,
+    bool need_rsp, bool is_prep,
+    vector<uint8_t> value) {
   lock_guard<mutex> lock(mutex_);
 
-  if (length < 0) {
-    LOG(WARNING) << "Negative length value received";
-    return;
-  }
-
   // Check to see if we know about this connection. Otherwise ignore the
   // request.
   auto conn = GetConnection(conn_id, bda, trans_id);
@@ -709,7 +705,7 @@ void GattServer::RequestWriteCallback(
   VLOG(1) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id
           << " BD_ADDR: " << device_address
           << " attr_handle: " << attr_handle << " offset: " << offset
-          << " length: " << length << " need_rsp: " << need_rsp
+          << " length: " << value.size() << " need_rsp: " << need_rsp
           << " is_prep: " << is_prep;
 
   // Make sure that the handle is valid.
@@ -736,16 +732,14 @@ void GattServer::RequestWriteCallback(
     return;
   }
 
-  std::vector<uint8_t> value_vec(value, value + length);
-
   if (iter->second.IsCharacteristic()) {
     delegate_->OnCharacteristicWriteRequest(
         this, device_address, trans_id, offset, is_prep, need_rsp,
-        value_vec, iter->second);
+        std::move(value), iter->second);
   } else if (iter->second.IsDescriptor()) {
     delegate_->OnDescriptorWriteRequest(
         this, device_address, trans_id, offset, is_prep, need_rsp,
-        value_vec, iter->second);
+        std::move(value), iter->second);
   } else {
     // Our API only delegates to applications those read requests for
     // characteristic value and descriptor attributes. Everything else should be
index 3775908..b3d0bbb 100644 (file)
@@ -294,8 +294,9 @@ class GattServer : public BluetoothInstance,
       hal::BluetoothGattInterface* gatt_iface,
       int conn_id, int trans_id,
       const bt_bdaddr_t& bda,
-      int attr_handle, int offset, int length,
-      bool need_rsp, bool is_prep, uint8_t* value) override;
+      int attr_handle, int offset,
+      bool need_rsp, bool is_prep,
+      vector<uint8_t> value) override;
   void RequestExecWriteCallback(
       hal::BluetoothGattInterface* gatt_iface,
       int conn_id, int trans_id,
index 52b1c61..7a66af9 100644 (file)
@@ -201,24 +201,25 @@ void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t *bda,
 }
 
 void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda,
-                          int attr_handle, int attribute_offset, int length,
-                          bool need_rsp, bool is_prep, uint8_t *value) {
+                          int attr_handle, int attribute_offset,
+                          bool need_rsp, bool is_prep,
+                          vector<uint8_t> value) {
   std::string addr(BtAddrString(bda));
   LOG_INFO(LOG_TAG,
       "%s: connection:%d (%s:trans:%d) write attr:%d attribute_offset:%d "
-      "length:%d "
+      "length:%zu "
       "need_resp:%u is_prep:%u",
       __func__, conn_id, addr.c_str(), trans_id, attr_handle, attribute_offset,
-      length, need_rsp, is_prep);
+      value.size(), need_rsp, is_prep);
 
   std::lock_guard<std::mutex> lock(g_internal->lock);
 
   bluetooth::gatt::Characteristic &ch =
       g_internal->characteristics[attr_handle];
 
-  ch.blob.resize(attribute_offset + length);
+  ch.blob.resize(attribute_offset + value.size());
 
-  std::copy(value, value + length, ch.blob.begin() + attribute_offset);
+  std::copy(value.begin(), value.end(), ch.blob.begin() + attribute_offset);
 
   auto target_blob = g_internal->controlled_blobs.find(attr_handle);
   // If this is a control attribute, adjust offset of the target blob.
@@ -248,11 +249,11 @@ void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda,
   btgatt_response_t response;
   response.attr_value.handle = attr_handle;
   response.attr_value.offset = attribute_offset;
-  response.attr_value.len = length;
+  response.attr_value.len = value.size();
   response.attr_value.auth_req = 0;
   // Provide written data back to sender for the response.
   // Remote stacks use this to validate the success of the write.
-  std::copy(value, value + length, response.attr_value.value);
+  std::copy(value.begin(), value.end(), response.attr_value.value);
   g_internal->gatt->server->send_response(conn_id, trans_id, 0, &response);
 }
 
@@ -347,9 +348,9 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t *app_uuid) {
       false,            /* no txpower */
       2, 2,             /* interval */
       0,                /* appearance */
-      0, nullptr,       /* no mfg data */
-      0, nullptr,       /* no service data */
-      0, nullptr /* no service id yet */);
+      {},       /* no mfg data */
+      {},       /* no service data */
+      {} /* no service id yet */);
   if (btstat != BT_STATUS_SUCCESS) {
     LOG_ERROR(LOG_TAG, "Failed to set advertising data");
     return;
@@ -379,7 +380,7 @@ void ServiceStoppedCallback(int status, int server_if, int srvc_handle) {
   g_internal->api_synchronize.notify_one();
 }
 
-void ScanResultCallback(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data) {
+void ScanResultCallback(bt_bdaddr_t *bda, int rssi, vector<uint8_t> adv_data) {
   std::string addr(BtAddrString(bda));
   (void)adv_data;
   std::lock_guard<std::mutex> lock(g_internal->lock);
@@ -595,11 +596,9 @@ bool Server::SetAdvertisement(const std::vector<UUID>& ids,
       false,                       /* no txpower */
       2, 2,                        /* interval */
       0,                           /* appearance */
-      mutable_manufacturer_data.size(),
-      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
-      mutable_service_data.size(),
-      reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
-      reinterpret_cast<char *>(id_data.data()));
+      mutable_manufacturer_data,
+      mutable_service_data,
+      id_data);
   if (btstat != BT_STATUS_SUCCESS) {
     LOG_ERROR(LOG_TAG, "Failed to set advertising data");
     return false;
@@ -629,11 +628,9 @@ bool Server::SetScanResponse(const std::vector<UUID>& ids,
       false,                      /* no txpower */
       2, 2,                       /* interval */
       0,                          /* appearance */
-      mutable_manufacturer_data.size(),
-      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
-      mutable_service_data.size(),
-      reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
-      reinterpret_cast<char *>(id_data.data()));
+      mutable_manufacturer_data,
+      mutable_service_data,
+      id_data);
   if (btstat != BT_STATUS_SUCCESS) {
     LOG_ERROR(LOG_TAG, "Failed to set scan response data");
     return false;
index 2f7cf53..e5ba655 100644 (file)
@@ -80,16 +80,15 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t* app_uuid) {
       RegisterClientCallback(g_interface, status, client_if, *app_uuid));
 }
 
-void ScanResultCallback(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data) {
+void ScanResultCallback(bt_bdaddr_t* bda, int rssi, vector<uint8_t> adv_data) {
   shared_lock<shared_timed_mutex> lock(g_instance_lock);
   VERIFY_INTERFACE_OR_RETURN();
   CHECK(bda);
-  CHECK(adv_data);
 
   VLOG(2) << __func__ << " - BD_ADDR: " << BtAddrString(bda)
           << " RSSI: " << rssi;
   FOR_EACH_CLIENT_OBSERVER(
-    ScanResultCallback(g_interface, *bda, rssi, adv_data));
+    ScanResultCallback(g_interface, *bda, rssi, std::move(adv_data)));
 }
 
 void ConnectCallback(int conn_id, int status, int client_if, bt_bdaddr_t* bda) {
@@ -376,19 +375,20 @@ void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t* bda,
 
 void RequestWriteCallback(int conn_id, int trans_id,
                           bt_bdaddr_t* bda,
-                          int attr_handle, int offset, int length,
-                          bool need_rsp, bool is_prep, uint8_t* value) {
+                          int attr_handle, int offset,
+                          bool need_rsp, bool is_prep,
+                          vector<uint8_t> value) {
   shared_lock<shared_timed_mutex> lock(g_instance_lock);
   VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id
           << " attr_handle: " << attr_handle << " offset: " << offset
-          << " length: " << length << " need_rsp: " << need_rsp
+          << " length: " << value.size() << " need_rsp: " << need_rsp
           << " is_prep: " << is_prep;
   VERIFY_INTERFACE_OR_RETURN();
   CHECK(bda);
 
   FOR_EACH_SERVER_OBSERVER(RequestWriteCallback(
-      g_interface, conn_id, trans_id, *bda, attr_handle, offset, length,
-      need_rsp, is_prep, value));
+      g_interface, conn_id, trans_id, *bda, attr_handle, offset,
+      need_rsp, is_prep, std::move(value)));
 }
 
 void RequestExecWriteCallback(int conn_id, int trans_id,
@@ -608,7 +608,7 @@ void BluetoothGattInterface::ClientObserver::ScanResultCallback(
     BluetoothGattInterface* /* gatt_iface */,
     const bt_bdaddr_t& /* bda */,
     int /* rssi */,
-    uint8_t* /* adv_data */) {
+    vector<uint8_t>  /* adv_data */) {
   // Do Nothing.
 }
 
@@ -821,10 +821,9 @@ void BluetoothGattInterface::ServerObserver::RequestWriteCallback(
     const bt_bdaddr_t& /* bda */,
     int /* attr_handle */,
     int /* offset */,
-    int /* length */,
     bool /* need_rsp */,
     bool /* is_prep */,
-    uint8_t* /* value */) {
+    vector<uint8_t> /* value */) {
   // Do nothing.
 }
 
index 462220c..a22e3c3 100644 (file)
@@ -59,7 +59,7 @@ class BluetoothGattInterface {
     virtual void ScanResultCallback(
         BluetoothGattInterface* gatt_iface,
         const bt_bdaddr_t& bda, int rssi,
-        uint8_t* adv_data);
+        vector<uint8_t> adv_data);
 
     virtual void ConnectCallback(
         BluetoothGattInterface* gatt_iface,
@@ -201,8 +201,9 @@ class BluetoothGattInterface {
         BluetoothGattInterface* gatt_iface,
         int conn_id, int trans_id,
         const bt_bdaddr_t& bda,
-        int attr_handle, int offset, int length,
-        bool need_rsp, bool is_prep, uint8_t* value);
+        int attr_handle, int offset,
+        bool need_rsp, bool is_prep,
+        vector<uint8_t> value);
 
     virtual void RequestExecWriteCallback(
         BluetoothGattInterface* gatt_iface,
index 9834359..2e601d0 100644 (file)
@@ -74,22 +74,19 @@ bt_status_t FakeMultiAdvEnable(
 }
 
 bt_status_t FakeMultiAdvSetInstData(
-    int client_if, bool set_scan_rsp, bool include_name,
-    bool incl_txpower, int appearance,
-    int manufacturer_len, char* manufacturer_data,
-    int service_data_len, char* service_data,
-    int service_uuid_len, char* service_uuid) {
+    int client_if, bool set_scan_rsp, bool include_name, bool incl_txpower,
+    int appearance, vector<uint8_t> manufacturer_data,
+    vector<uint8_t> service_data,
+    vector<uint8_t> service_uuid) {
   if (g_client_handler)
     return g_client_handler->MultiAdvSetInstData(
-        client_if, set_scan_rsp, include_name,
-        incl_txpower, appearance,
-        manufacturer_len, manufacturer_data,
-        service_data_len, service_data,
-        service_uuid_len, service_uuid);
+        client_if, set_scan_rsp, include_name, incl_txpower, appearance,
+        manufacturer_data, service_data, service_uuid);
 
   return BT_STATUS_FAIL;
 }
 
+
 bt_status_t FakeMultiAdvDisable(int client_if) {
   if (g_client_handler)
     return g_client_handler->MultiAdvDisable(client_if);
@@ -273,7 +270,7 @@ void FakeBluetoothGattInterface::NotifyDisconnectCallback(
 }
 
 void FakeBluetoothGattInterface::NotifyScanResultCallback(
-    const bt_bdaddr_t& bda, int rssi, uint8_t* adv_data) {
+    const bt_bdaddr_t& bda, int rssi, vector<uint8_t> adv_data) {
   FOR_EACH_OBSERVER(ClientObserver, client_observers_,
                     ScanResultCallback(this, bda, rssi, adv_data));
 }
@@ -358,12 +355,12 @@ void FakeBluetoothGattInterface::NotifyRequestReadCallback(
 void FakeBluetoothGattInterface::NotifyRequestWriteCallback(
     int conn_id, int trans_id,
     const bt_bdaddr_t& bda, int attr_handle,
-    int offset, int length,
-    bool need_rsp, bool is_prep, uint8_t* value) {
+    int offset, bool need_rsp, bool is_prep,
+    vector<uint8_t> value) {
   FOR_EACH_OBSERVER(
       ServerObserver, server_observers_,
       RequestWriteCallback(
-          this, conn_id, trans_id, bda, attr_handle, offset, length, need_rsp,
+          this, conn_id, trans_id, bda, attr_handle, offset, need_rsp,
           is_prep, value));
 }
 
index 798bc0d..8526107 100644 (file)
@@ -48,9 +48,9 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface {
     virtual bt_status_t MultiAdvSetInstData(
         int client_if, bool set_scan_rsp, bool include_name,
         bool incl_txpower, int appearance,
-        int manufacturer_len, char* manufacturer_data,
-        int service_data_len, char* service_data,
-        int service_uuid_len, char* service_uuid) = 0;
+        vector<uint8_t> manufacturer_data,
+        vector<uint8_t> service_data,
+        vector<uint8_t> service_uuid) = 0;
     virtual bt_status_t MultiAdvDisable(int client_if) = 0;
   };
 
@@ -99,7 +99,7 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface {
   void NotifyDisconnectCallback(int conn_id, int status, int client_if,
                                 const bt_bdaddr_t& bda);
   void NotifyScanResultCallback(const bt_bdaddr_t& bda, int rssi,
-                                uint8_t* adv_data);
+                                vector<uint8_t> adv_data);
   void NotifyMultiAdvEnableCallback(int client_if, int status);
   void NotifyMultiAdvDataCallback(int client_if, int status);
   void NotifyMultiAdvDisableCallback(int client_if, int status);
@@ -125,8 +125,8 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface {
                                  int offset, bool is_long);
   void NotifyRequestWriteCallback(int conn_id, int trans_id,
                                   const bt_bdaddr_t& bda, int attr_handle,
-                                  int offset, int length,
-                                  bool need_rsp, bool is_prep, uint8_t* value);
+                                  int offset, bool need_rsp, bool is_prep,
+                                  vector<uint8_t> value);
   void NotifyRequestExecWriteCallback(int conn_id, int trans_id,
                                       const bt_bdaddr_t& bda, int exec_write);
   void NotifyIndicationSentCallback(int conn_id, int status);
index aae554c..3e3107e 100644 (file)
@@ -47,7 +47,7 @@ BLEStatus GetBLEStatus(int status) {
 // Returns the length of the given scan record array. We have to calculate this
 // based on the maximum possible data length and the TLV data. See TODO above
 // |kScanRecordLength|.
-size_t GetScanRecordLength(uint8_t* bytes) {
+size_t GetScanRecordLength(vector<uint8_t> bytes) {
   for (size_t i = 0, field_len = 0; i < kScanRecordLength;
        i += (field_len + 1)) {
     field_len = bytes[i];
@@ -565,7 +565,7 @@ int LowEnergyClient::GetInstanceId() const {
 
 void LowEnergyClient::ScanResultCallback(
     hal::BluetoothGattInterface* gatt_iface,
-    const bt_bdaddr_t& bda, int rssi, uint8_t* adv_data) {
+    const bt_bdaddr_t& bda, int rssi, vector<uint8_t> adv_data) {
   // Ignore scan results if this client didn't start a scan.
   if (!scan_started_.load())
     return;
@@ -577,7 +577,7 @@ void LowEnergyClient::ScanResultCallback(
   // TODO(armansito): Apply software filters here.
 
   size_t record_len = GetScanRecordLength(adv_data);
-  std::vector<uint8_t> scan_record(adv_data, adv_data + record_len);
+  std::vector<uint8_t> scan_record(adv_data.begin(), adv_data.begin() + record_len);
 
   ScanResult result(BtAddrString(&bda), scan_record, rssi);
 
@@ -752,12 +752,9 @@ bt_status_t LowEnergyClient::SetAdvertiseData(
           data.include_device_name(),
           data.include_tx_power_level(),
           0,  // This is what Bluetooth.apk current hardcodes for "appearance".
-          hal_data.manufacturer_data.size(),
-          reinterpret_cast<char*>(hal_data.manufacturer_data.data()),
-          hal_data.service_data.size(),
-          reinterpret_cast<char*>(hal_data.service_data.data()),
-          hal_data.service_uuid.size(),
-          reinterpret_cast<char*>(hal_data.service_uuid.data()));
+          hal_data.manufacturer_data,
+          hal_data.service_data,
+          hal_data.service_uuid);
 
   if (status != BT_STATUS_SUCCESS) {
     LOG(ERROR) << "Failed to set instance advertising data.";
index 45ff662..3dda04f 100644 (file)
@@ -149,7 +149,8 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver,
   // BluetoothGattInterface::ClientObserver overrides:
   void ScanResultCallback(
       hal::BluetoothGattInterface* gatt_iface,
-      const bt_bdaddr_t& bda, int rssi, uint8_t* adv_data) override;
+      const bt_bdaddr_t& bda, int rssi,
+      vector<uint8_t> adv_data) override;
 
   void ConnectCallback(
       hal::BluetoothGattInterface* gatt_iface, int conn_id, int status,
index 67b0c1d..b99c08a 100644 (file)
@@ -44,8 +44,8 @@ class MockGattHandler
     return BT_STATUS_FAIL;
   }
 
-  bt_status_t MultiAdvSetInstData(int, bool, bool, bool, int,
-                                  int, char*, int, char*, int, char*) override {
+  bt_status_t MultiAdvSetInstData(int, bool, bool, bool, int, vector<uint8_t>,
+                                  vector<uint8_t>, vector<uint8_t> ) override {
     return BT_STATUS_FAIL;
   }
 
index 90a85b2..ca5da5d 100644 (file)
@@ -1095,28 +1095,28 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) {
   // Unknown connection ID shouldn't trigger anything.
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0 + 1, kReqId0, hal_addr0, char_handle_, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(0, test_delegate.char_write_req().count);
   EXPECT_EQ(0, test_delegate.desc_write_req().count);
 
   // Unknown device address shouldn't trigger anything.
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId0, hal_addr1, char_handle_, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(0, test_delegate.char_write_req().count);
   EXPECT_EQ(0, test_delegate.desc_write_req().count);
 
   // Unknown attribute handle shouldn't trigger anything.
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId0, hal_addr0, char_handle_ + 50, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(0, test_delegate.char_write_req().count);
   EXPECT_EQ(0, test_delegate.desc_write_req().count);
 
   // Characteristic and descriptor handles should trigger correct callbacks.
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId0, hal_addr0, char_handle_, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(1, test_delegate.char_write_req().count);
   EXPECT_EQ(kTestAddress0, test_delegate.char_write_req().device_address);
   EXPECT_EQ(kReqId0, test_delegate.char_write_req().id);
@@ -1129,7 +1129,7 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) {
 
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId1, hal_addr0, desc_handle_, 2,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(1, test_delegate.char_write_req().count);
   EXPECT_EQ(1, test_delegate.desc_write_req().count);
   EXPECT_EQ(kTestAddress0, test_delegate.desc_write_req().device_address);
@@ -1143,10 +1143,10 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) {
   // Callback with a pending request ID will be ignored.
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId0, hal_addr0, char_handle_, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId1, hal_addr0, char_handle_, 0,
-      kTestValue.size(), true, false, (uint8_t *)kTestValue.data());
+      true, false, kTestValue);
   EXPECT_EQ(1, test_delegate.char_write_req().count);
   EXPECT_EQ(1, test_delegate.desc_write_req().count);
 
@@ -1194,7 +1194,7 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) {
   // SendResponse should fail for a "Write Without Response".
   fake_hal_gatt_iface_->NotifyRequestWriteCallback(
       kConnId0, kReqId0, hal_addr0, char_handle_, 0,
-      kTestValue.size(), false, false, (uint8_t *)kTestValue.data());
+      false, false, kTestValue);
   EXPECT_EQ(false, test_delegate.char_write_req().need_rsp);
   EXPECT_FALSE(gatt_server_->SendResponse(
       kTestAddress0, kReqId0,
index cecdc8e..0251e99 100644 (file)
@@ -49,9 +49,10 @@ class MockGattHandler
   MOCK_METHOD4(Connect, bt_status_t(int , const bt_bdaddr_t *, bool, int));
   MOCK_METHOD3(Disconnect, bt_status_t(int , const bt_bdaddr_t *, int));
   MOCK_METHOD7(MultiAdvEnable, bt_status_t(int, int, int, int, int, int, int));
-  MOCK_METHOD10(
+  MOCK_METHOD7(
       MultiAdvSetInstDataMock,
-      bt_status_t(bool, bool, bool, int, int, char*, int, char*, int, char*));
+      bt_status_t(bool, bool, bool, int, vector<uint8_t>, vector<uint8_t>,
+                  vector<uint8_t>));
   MOCK_METHOD1(MultiAdvDisable, bt_status_t(int));
 
   // GMock has macros for up to 10 arguments (11 is really just too many...).
@@ -61,14 +62,12 @@ class MockGattHandler
       int /* client_if */,
       bool set_scan_rsp, bool include_name,
       bool incl_txpower, int appearance,
-      int manufacturer_len, char* manufacturer_data,
-      int service_data_len, char* service_data,
-      int service_uuid_len, char* service_uuid) override {
+      vector<uint8_t> manufacturer_data,
+      vector<uint8_t> service_data,
+      vector<uint8_t> service_uuid) override {
     return MultiAdvSetInstDataMock(
         set_scan_rsp, include_name, incl_txpower, appearance,
-        manufacturer_len, manufacturer_data,
-        service_data_len, service_data,
-        service_uuid_len, service_uuid);
+        manufacturer_data, service_data, service_uuid);
   }
 
  private:
@@ -130,16 +129,13 @@ class AdvertiseDataHandler : public MockGattHandler {
       int /* client_if */,
       bool set_scan_rsp, bool include_name,
       bool incl_txpower, int appearance,
-      int manufacturer_len, char* manufacturer_data,
-      int service_data_len, char* service_data,
-      int service_uuid_len, char* service_uuid) override {
+      vector<uint8_t> manufacturer_data,
+      vector<uint8_t> service_data,
+      vector<uint8_t> service_uuid) override {
     call_count_++;
-    service_data_.assign(
-        service_data, service_data+service_data_len);
-    manufacturer_data_.assign(
-        manufacturer_data, manufacturer_data+manufacturer_len);
-    uuid_data_.assign(
-        service_uuid, service_uuid+service_uuid_len);
+    service_data_ = std::move(service_data);
+    manufacturer_data_ = std::move(manufacturer_data);
+    uuid_data_ = std::move(service_uuid);
     return BT_STATUS_SUCCESS;
   }
 
@@ -250,7 +246,7 @@ class LowEnergyClientPostRegisterTest : public LowEnergyClientTest {
         .Times(1)
         .WillOnce(Return(BT_STATUS_SUCCESS));
     EXPECT_CALL(*mock_handler_,
-                MultiAdvSetInstDataMock(_, _, _, _, _, _, _, _, _, _))
+                MultiAdvSetInstDataMock(_, _, _, _, _, _, _))
         .Times(1)
         .WillOnce(Return(BT_STATUS_SUCCESS));
 
@@ -441,7 +437,7 @@ TEST_F(LowEnergyClientPostRegisterTest, StartAdvertisingBasic) {
                   false,  // set_scan_rsp
                   false,  // include_name
                   false,  // incl_txpower
-                  _, _, _, _, _, _, _))
+                  _, _, _, _))
       .Times(3)
       .WillOnce(Return(BT_STATUS_FAIL))
       .WillRepeatedly(Return(BT_STATUS_SUCCESS));
@@ -646,8 +642,9 @@ TEST_F(LowEnergyClientPostRegisterTest, ScanResponse) {
           false,  // include_name
           true,  // incl_txpower,
           _,
-          0,  // 0 bytes
-          _, _, _, _, _))
+          // 0,  // 0 bytes
+          _,
+          _, _))
       .Times(2)
       .WillRepeatedly(Return(BT_STATUS_SUCCESS));
   EXPECT_CALL(
@@ -657,8 +654,9 @@ TEST_F(LowEnergyClientPostRegisterTest, ScanResponse) {
           true,  // include_name
           false,  // incl_txpower,
           _,
-          data1.size() - 2,  // Mfc. Specific data field bytes.
-          _, _, _, _, _))
+          // data1.size() - 2,  // Mfc. Specific data field bytes.
+          _,
+          _, _))
       .Times(2)
       .WillRepeatedly(Return(BT_STATUS_SUCCESS));
 
@@ -902,16 +900,16 @@ TEST_F(LowEnergyClientPostRegisterTest, ScanRecord) {
 
   EXPECT_EQ(0, delegate.scan_result_count());
 
-  const uint8_t kTestRecord0[] = { 0x02, 0x01, 0x00, 0x00 };
-  const uint8_t kTestRecord1[] = { 0x00 };
-  const uint8_t kTestRecord2[] = {
+  vector<uint8_t> kTestRecord0({ 0x02, 0x01, 0x00, 0x00 });
+  vector<uint8_t> kTestRecord1({ 0x00 });
+  vector<uint8_t> kTestRecord2({
     0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
     0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
     0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
     0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
     0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
     0x01, 0x00
-  };
+  });
   const bt_bdaddr_t kTestAddress = {
     { 0x01, 0x02, 0x03, 0x0A, 0x0B, 0x0C }
   };
@@ -920,7 +918,7 @@ TEST_F(LowEnergyClientPostRegisterTest, ScanRecord) {
 
   // Scan wasn't started. Result should be ignored.
   fake_hal_gatt_iface_->NotifyScanResultCallback(
-      kTestAddress, kTestRssi, (uint8_t*) kTestRecord0);
+      kTestAddress, kTestRssi, kTestRecord0);
   EXPECT_EQ(0, delegate.scan_result_count());
 
   // Start a scan session for |le_client_|.
@@ -936,21 +934,21 @@ TEST_F(LowEnergyClientPostRegisterTest, ScanRecord) {
   ASSERT_TRUE(le_client_->StartScan(settings, filters));
 
   fake_hal_gatt_iface_->NotifyScanResultCallback(
-      kTestAddress, kTestRssi, (uint8_t*) kTestRecord0);
+      kTestAddress, kTestRssi, kTestRecord0);
   EXPECT_EQ(1, delegate.scan_result_count());
   EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address());
   EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi());
   EXPECT_EQ(3U, delegate.last_scan_result().scan_record().size());
 
   fake_hal_gatt_iface_->NotifyScanResultCallback(
-      kTestAddress, kTestRssi, (uint8_t*) kTestRecord1);
+      kTestAddress, kTestRssi, kTestRecord1);
   EXPECT_EQ(2, delegate.scan_result_count());
   EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address());
   EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi());
   EXPECT_TRUE(delegate.last_scan_result().scan_record().empty());
 
   fake_hal_gatt_iface_->NotifyScanResultCallback(
-      kTestAddress, kTestRssi, (uint8_t*) kTestRecord2);
+      kTestAddress, kTestRssi, kTestRecord2);
   EXPECT_EQ(3, delegate.scan_result_count());
   EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address());
   EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi());
index a7912bb..48f279e 100644 (file)
@@ -107,7 +107,7 @@ void GattTest::RegisterClientCallback(
 
 void GattTest::ScanResultCallback(
     bluetooth::hal::BluetoothGattInterface* /* unused */,
-    const bt_bdaddr_t& bda, int rssi, uint8_t* adv_data) {
+    const bt_bdaddr_t& bda, int rssi, vector<uint8_t> adv_data) {
   semaphore_post(scan_result_callback_sem_);
 }
 
index f3525fe..3c09d2e 100644 (file)
@@ -58,7 +58,7 @@ class GattTest : public BluetoothTest,
       int status, int clientIf, const bt_uuid_t& app_uuid) override;
   void ScanResultCallback(
       bluetooth::hal::BluetoothGattInterface* /* unused */,
-      const bt_bdaddr_t& bda, int rssi, uint8_t* adv_data) override;
+      const bt_bdaddr_t& bda, int rssi, vector<uint8_t> adv_data) override;
   void ListenCallback(
       bluetooth::hal::BluetoothGattInterface* /* unused */,
       int status, int client_if) override;