OSDN Git Service

Update btif/src/::ble_addr_type
authorChris Manton <cmanton@google.com>
Wed, 2 Sep 2020 04:38:44 +0000 (21:38 -0700)
committerChris Manton <cmanton@google.com>
Tue, 8 Sep 2020 20:21:37 +0000 (20:21 +0000)
Using strict types tBLE_ADDR_TYPE

Towards readable code

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ie2e3cda2fe0345f5f901c7037977c2a827bdcf3c

btif/include/btif_config.h
btif/include/btif_storage.h
btif/src/btif_ble_scanner.cc
btif/src/btif_config.cc
btif/src/btif_dm.cc
btif/src/btif_gatt_client.cc
btif/src/btif_gatt_server.cc
btif/src/btif_gatt_test.cc
btif/src/btif_sock.cc
btif/src/btif_storage.cc

index 3297725..8729ad1 100644 (file)
@@ -71,7 +71,8 @@ bool btif_config_clear(void);
 
 // TODO(zachoverflow): Eww...we need to move these out. These are peer specific,
 // not config general.
-bool btif_get_address_type(const RawAddress& bd_addr, int* p_addr_type);
+bool btif_get_address_type(const RawAddress& bd_addr,
+                           tBLE_ADDR_TYPE* p_addr_type);
 bool btif_get_device_type(const RawAddress& bd_addr, int* p_device_type);
 
 void btif_debug_config_dump(int fd);
index a1e52d9..c1ef5c2 100644 (file)
@@ -276,10 +276,10 @@ bt_status_t btif_storage_get_ble_local_key(uint8_t key_type,
                                            Octet16* key_value);
 
 bt_status_t btif_storage_get_remote_addr_type(const RawAddress* remote_bd_addr,
-                                              int* addr_type);
+                                              tBLE_ADDR_TYPE* addr_type);
 
 bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr,
-                                              uint8_t addr_type);
+                                              tBLE_ADDR_TYPE addr_type);
 
 /*******************************************************************************
  * Function         btif_storage_load_hidd
index e27e18c..1b76e62 100644 (file)
@@ -102,7 +102,7 @@ void bta_batch_scan_reports_cb(int client_id, tBTA_STATUS status,
 }
 
 void bta_scan_results_cb_impl(RawAddress bd_addr, tBT_DEVICE_TYPE device_type,
-                              int8_t rssi, uint8_t addr_type,
+                              int8_t rssi, tBLE_ADDR_TYPE addr_type,
                               uint16_t ble_evt_type, uint8_t ble_primary_phy,
                               uint8_t ble_secondary_phy,
                               uint8_t ble_advertising_sid, int8_t ble_tx_power,
@@ -310,7 +310,8 @@ class BleScannerInterfaceImpl : public BleScannerInterface {
                        int addr_type, int discard_rule, Callback cb) override {
     do_in_main_thread(
         FROM_HERE, base::Bind(&BTM_BleEnableBatchScan, scan_mode, scan_interval,
-                              scan_window, discard_rule, addr_type,
+                              scan_window, discard_rule,
+                              static_cast<tBLE_ADDR_TYPE>(addr_type),
                               jni_thread_wrapper(FROM_HERE, cb)));
   }
 
index a0cf8c0..cb89912 100644 (file)
@@ -140,13 +140,15 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type) {
   return true;
 }
 
-bool btif_get_address_type(const RawAddress& bda, int* p_addr_type) {
+bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type) {
   if (p_addr_type == NULL) return false;
 
   std::string addrstr = bda.ToString();
   const char* bd_addr_str = addrstr.c_str();
 
-  if (!btif_config_get_int(bd_addr_str, "AddrType", p_addr_type)) return false;
+  int val = 0;
+  if (!btif_config_get_int(bd_addr_str, "AddrType", &val)) return false;
+  *p_addr_type = static_cast<tBLE_ADDR_TYPE>(val);
 
   LOG_DEBUG("%s: Device [%s] address type %d", __func__, bd_addr_str,
             *p_addr_type);
index 06e904d..fbffb01 100644 (file)
@@ -647,7 +647,7 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
   bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
 
   int device_type = 0;
-  int addr_type;
+  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
   std::string addrstr = bd_addr.ToString();
   const char* bdstr = addrstr.c_str();
   if (transport == BT_TRANSPORT_LE) {
@@ -659,7 +659,7 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
       // Try to read address type. OOB pairing might have set it earlier, but
       // didn't store it, it defaults to BLE_ADDR_PUBLIC
       uint8_t tmp_dev_type;
-      uint8_t tmp_addr_type;
+      tBLE_ADDR_TYPE tmp_addr_type = BLE_ADDR_PUBLIC;
       BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &tmp_addr_type);
       addr_type = tmp_addr_type;
 
@@ -1179,7 +1179,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
         bt_device_type_t dev_type;
         uint32_t num_properties = 0;
         bt_status_t status;
-        int addr_type = 0;
+        tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
 
         memset(properties, 0, sizeof(properties));
         /* RawAddress */
@@ -1886,7 +1886,8 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, int transport,
   // value.
   if (memcmp(oob_data.le_bt_dev_addr, empty, 7) != 0) {
     /* byte no 7 is address type in LE Bluetooth Address OOB data */
-    uint8_t address_type = oob_data.le_bt_dev_addr[6];
+    tBLE_ADDR_TYPE address_type =
+        static_cast<tBLE_ADDR_TYPE>(oob_data.le_bt_dev_addr[6]);
     if (address_type == BLE_ADDR_PUBLIC || address_type == BLE_ADDR_RANDOM) {
       // bd_addr->address is already reversed, so use it instead of
       // oob_data->le_bt_dev_addr
@@ -1997,7 +1998,7 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept,
 
   if (bluetooth::shim::is_gd_shim_enabled()) {
     uint8_t tmp_dev_type = 0;
-    uint8_t tmp_addr_type = 0;
+    tBLE_ADDR_TYPE tmp_addr_type = BLE_ADDR_PUBLIC;
     BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &tmp_addr_type);
 
     bluetooth::shim::BTIF_DM_pin_reply(bd_addr, tmp_addr_type, accept, pin_len,
@@ -2032,8 +2033,8 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept,
 void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant,
                        uint8_t accept) {
   if (bluetooth::shim::is_gd_shim_enabled()) {
-    uint8_t tmp_dev_type = 0;
-    uint8_t tmp_addr_type = 0;
+    tBT_DEVICE_TYPE tmp_dev_type;
+    tBLE_ADDR_TYPE tmp_addr_type = BLE_ADDR_PUBLIC;
     BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &tmp_addr_type);
 
     bluetooth::shim::BTIF_DM_ssp_reply(bd_addr, tmp_addr_type, variant, accept);
@@ -2432,7 +2433,7 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
   if (p_auth_cmpl->success) {
     status = BT_STATUS_SUCCESS;
     state = BT_BOND_STATE_BONDED;
-    int addr_type;
+    tBLE_ADDR_TYPE addr_type;
     RawAddress bdaddr = p_auth_cmpl->bd_addr;
     if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) !=
         BT_STATUS_SUCCESS)
index 1cc6440..1072ead 100644 (file)
@@ -251,7 +251,7 @@ void btif_gattc_open_impl(int client_if, RawAddress address, bool is_direct,
                           int transport_p, bool opportunistic,
                           int initiating_phys) {
   // Ensure device is in inquiry database
-  int addr_type = 0;
+  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
   int device_type = 0;
   tBT_TRANSPORT transport = (tBT_TRANSPORT)BT_TRANSPORT_LE;
 
index 1f29659..e5ef7a2 100644 (file)
@@ -282,7 +282,7 @@ static bt_status_t btif_gatts_unregister_app(int server_if) {
 static void btif_gatts_open_impl(int server_if, const RawAddress& address,
                                  bool is_direct, int transport_param) {
   // Ensure device is in inquiry database
-  int addr_type = 0;
+  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
   int device_type = 0;
   tBT_TRANSPORT transport = BT_TRANSPORT_LE;
 
index 7fe5f11..6f10ca6 100644 (file)
@@ -194,7 +194,7 @@ bt_status_t btif_gattc_test_command_impl(int command,
 
       if (params->u1 == BT_DEVICE_TYPE_BLE)
         BTM_SecAddBleDevice(*params->bda1, NULL, BT_DEVICE_TYPE_BLE,
-                            params->u2);
+                            static_cast<tBLE_ADDR_TYPE>(params->u2));
 
       if (!GATT_Connect(test_cb.gatt_if, *params->bda1, true, BT_TRANSPORT_LE,
                         false)) {
index 312ea94..f41eb9d 100644 (file)
@@ -216,7 +216,7 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
       flags |= BTSOCK_FLAG_LE_COC;
 
       // Ensure device is in inquiry database
-      int addr_type = 0;
+      tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
       int device_type = 0;
 
       if (btif_get_address_type(*bd_addr, &addr_type) &&
index 8fbbaf7..12bd334 100644 (file)
@@ -488,7 +488,7 @@ static bt_status_t btif_in_fetch_bonded_devices(
 }
 
 static void btif_read_le_key(const uint8_t key_type, const size_t key_len,
-                             RawAddress bd_addr, const uint8_t addr_type,
+                             RawAddress bd_addr, const tBLE_ADDR_TYPE addr_type,
                              const bool add_key, bool* device_added,
                              bool* key_found) {
   CHECK(device_added);
@@ -1238,7 +1238,7 @@ static bt_status_t btif_in_fetch_bonded_ble_device(
     const std::string& remote_bd_addr, int add,
     btif_bonded_devices_t* p_bonded_devices) {
   int device_type;
-  int addr_type;
+  tBLE_ADDR_TYPE addr_type;
   bool device_added = false;
   bool key_found = false;
 
@@ -1289,7 +1289,7 @@ static bt_status_t btif_in_fetch_bonded_ble_device(
 }
 
 bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr,
-                                              uint8_t addr_type) {
+                                              tBLE_ADDR_TYPE addr_type) {
   int ret = btif_config_set_int(remote_bd_addr->ToString(), "AddrType",
                                 (int)addr_type);
   return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
@@ -1310,9 +1310,10 @@ bool btif_has_ble_keys(const std::string& bdstr) {
  *
  ******************************************************************************/
 bt_status_t btif_storage_get_remote_addr_type(const RawAddress* remote_bd_addr,
-                                              int* addr_type) {
-  int ret =
-      btif_config_get_int(remote_bd_addr->ToString(), "AddrType", addr_type);
+                                              tBLE_ADDR_TYPE* addr_type) {
+  int val;
+  int ret = btif_config_get_int(remote_bd_addr->ToString(), "AddrType", &val);
+  *addr_type = static_cast<tBLE_ADDR_TYPE>(val);
   return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
 }
 /*******************************************************************************