OSDN Git Service

Flatten BTA_DM_ENABLE_EVT
authorZach Johnson <zachoverflow@google.com>
Sat, 15 Aug 2020 17:16:36 +0000 (10:16 -0700)
committerZach Johnson <zachoverflow@google.com>
Sat, 15 Aug 2020 17:19:00 +0000 (10:19 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I98dcd7785c64ccacec7c03b86898b6cd5860ba1e

bta/dm/bta_dm_act.cc
bta/include/bta_api.h
btif/src/btif_dm.cc
btif/src/btif_util.cc

index 4b86357..d4314e6 100644 (file)
@@ -63,6 +63,8 @@
 
 using bluetooth::Uuid;
 
+void BTIF_dm_enable();
+
 static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir,
                                   uint16_t eir_len);
 static void bta_dm_inq_cmpl_cb(void* p_result);
@@ -2439,10 +2441,7 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
  *
  ******************************************************************************/
 static void bta_dm_local_name_cback(UNUSED_ATTR void* p_name) {
-  tBTA_DM_SEC sec_event;
-
-  if (bta_dm_cb.p_sec_cback)
-    bta_dm_cb.p_sec_cback(BTA_DM_ENABLE_EVT, &sec_event);
+  BTIF_dm_enable();
 }
 
 static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
index 138d031..722ff33 100644 (file)
@@ -340,7 +340,6 @@ typedef uint8_t tBTA_DM_LINK_QUALITY_VALUE;
 typedef uint8_t tBTA_SIG_STRENGTH_MASK;
 
 /* Security Callback Events */
-#define BTA_DM_ENABLE_EVT 0    /* Enable Event */
 #define BTA_DM_DISABLE_EVT 1   /* Disable Event */
 #define BTA_DM_PIN_REQ_EVT 2   /* PIN request. */
 #define BTA_DM_AUTH_CMPL_EVT 3 /* Authentication complete indication. */
index 4c93ed0..b6e4ab2 100644 (file)
@@ -1505,6 +1505,48 @@ void BTIF_dm_on_hw_error() {
   kill(getpid(), SIGKILL);
 }
 
+void BTIF_dm_enable() {
+  BD_NAME bdname;
+  bt_status_t status;
+  bt_property_t prop;
+  prop.type = BT_PROPERTY_BDNAME;
+  prop.len = BD_NAME_LEN;
+  prop.val = (void*)bdname;
+
+  status = btif_storage_get_adapter_property(&prop);
+  if (status == BT_STATUS_SUCCESS) {
+    /* A name exists in the storage. Make this the device name */
+    BTA_DmSetDeviceName((char*)prop.val);
+  } else {
+    /* Storage does not have a name yet.
+     * Use the default name and write it to the chip
+     */
+    BTA_DmSetDeviceName(btif_get_default_local_name());
+  }
+
+  /* Enable local privacy */
+  BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
+
+  /* for each of the enabled services in the mask, trigger the profile
+   * enable */
+  tBTA_SERVICE_MASK service_mask = btif_get_enabled_services_mask();
+  for (uint32_t i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
+    if (service_mask & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
+      btif_in_execute_service_request(i, true);
+    }
+  }
+  /* clear control blocks */
+  memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
+  pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
+
+  /* This function will also trigger the adapter_properties_cb
+  ** and bonded_devices_info_cb
+  */
+  btif_storage_load_bonded_devices();
+  bluetooth::bqr::EnableBtQualityReport(true);
+  btif_enable_bluetooth_evt();
+}
+
 /*******************************************************************************
  *
  * Function         btif_dm_upstreams_cback
@@ -1523,49 +1565,6 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
   BTIF_TRACE_EVENT("%s: ev: %s", __func__, dump_dm_event(event));
 
   switch (event) {
-    case BTA_DM_ENABLE_EVT: {
-      BD_NAME bdname;
-      bt_status_t status;
-      bt_property_t prop;
-      prop.type = BT_PROPERTY_BDNAME;
-      prop.len = BD_NAME_LEN;
-      prop.val = (void*)bdname;
-
-      status = btif_storage_get_adapter_property(&prop);
-      if (status == BT_STATUS_SUCCESS) {
-        /* A name exists in the storage. Make this the device name */
-        BTA_DmSetDeviceName((char*)prop.val);
-      } else {
-        /* Storage does not have a name yet.
-         * Use the default name and write it to the chip
-         */
-        BTA_DmSetDeviceName(btif_get_default_local_name());
-      }
-
-      /* Enable local privacy */
-      BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
-
-      /* for each of the enabled services in the mask, trigger the profile
-       * enable */
-      service_mask = btif_get_enabled_services_mask();
-      for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
-        if (service_mask &
-            (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
-          btif_in_execute_service_request(i, true);
-        }
-      }
-      /* clear control blocks */
-      memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
-      pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
-
-      /* This function will also trigger the adapter_properties_cb
-      ** and bonded_devices_info_cb
-      */
-      btif_storage_load_bonded_devices();
-      bluetooth::bqr::EnableBtQualityReport(true);
-      btif_enable_bluetooth_evt();
-    } break;
-
     case BTA_DM_DISABLE_EVT:
       /* for each of the enabled services in the mask, trigger the profile
        * disable */
index 86775a4..5bbe529 100644 (file)
@@ -144,7 +144,6 @@ const char* dump_property_type(bt_property_type_t type) {
 
 const char* dump_dm_event(uint16_t event) {
   switch (event) {
-    CASE_RETURN_STR(BTA_DM_ENABLE_EVT)
     CASE_RETURN_STR(BTA_DM_DISABLE_EVT)
     CASE_RETURN_STR(BTA_DM_PIN_REQ_EVT)
     CASE_RETURN_STR(BTA_DM_AUTH_CMPL_EVT)