Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b185601b authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Fix issues during cleanup stage of the Bluetooth stack

 * Moved free-ing of bta_av_cb timers from the init function
   to the cleanup stage.
 * Changed the usage of btif_jni_disassociate() so it is called
   synchronously. Its previous usage was complicated -
   the function was called asynchronously on a different thread,
   and we had to wait on a future for its completion.
 * Renamed function btif_shutdown_bluetooth() to
   btif_cleanup_bluetooth() to represent better its purpose.
   Similarly, bte_main_shutdown() is renamed to bte_main_cleanup()

Also:
 * Removed function btif_init_fail(), because it is not used.
 * Updated an error log message inside function
   btif_in_execute_service_request() so the log information
   is accurate and more useful.
 * Updated the log messages related to the lifecycle of a module
   in btcore/src/module.c

Bug: 26982349
Change-Id: Icd6f159d993bdb9c8ef09bfb5b1386b3d6ea4ff2
parent b39ad5c7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1410,6 +1410,11 @@ void bta_av_disable(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
        hdr.layer_specific = xx + 1;
        bta_av_api_deregister((tBTA_AV_DATA *)&hdr);
    }

    alarm_free(p_cb->link_signalling_timer);
    p_cb->link_signalling_timer = NULL;
    alarm_free(p_cb->accept_signalling_timer);
    p_cb->accept_signalling_timer = NULL;
}

/*******************************************************************************
+2 −7
Original line number Diff line number Diff line
@@ -219,16 +219,10 @@ static char *bta_av_st_code(UINT8 state);
*******************************************************************************/
static void bta_av_api_enable(tBTA_AV_DATA *p_data)
{
    int i;
    tBTA_AV_ENABLE      enable;

    alarm_free(bta_av_cb.link_signalling_timer);
    alarm_free(bta_av_cb.accept_signalling_timer);

    /* initialize control block */
    memset(&bta_av_cb, 0, sizeof(tBTA_AV_CB));

    for(i=0; i<BTA_AV_NUM_RCB; i++)
    for (int i = 0; i < BTA_AV_NUM_RCB; i++)
        bta_av_cb.rcb[i].handle = BTA_AV_RC_HANDLE_NONE;

    bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE;
@@ -246,6 +240,7 @@ static void bta_av_api_enable(tBTA_AV_DATA *p_data)
    bta_av_cb.features = p_data->api_enable.features;
    bta_av_cb.sec_mask = p_data->api_enable.sec_mask;

    tBTA_AV_ENABLE enable;
    enable.features = bta_av_cb.features;

    /* Register for SCO change event */
+22 −13
Original line number Diff line number Diff line
@@ -78,12 +78,13 @@ bool module_init(const module_t *module) {
  assert(module != NULL);
  assert(get_module_state(module) == MODULE_STATE_NONE);

  LOG_WARN(LOG_TAG, "%s initializing the module \"%s\"", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Initializing module \"%s\"", __func__, module->name);
  if (!call_lifecycle_function(module->init)) {
    LOG_ERROR(LOG_TAG, "%s failed to initialize \"%s\"", __func__, module->name);
    LOG_ERROR(LOG_TAG, "%s Failed to initialize module \"%s\"",
              __func__, module->name);
    return false;
  }
  LOG_WARN(LOG_TAG, "%s initialized the module \"%s\"", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Initialized module \"%s\"", __func__, module->name);

  set_module_state(module, MODULE_STATE_INITIALIZED);
  return true;
@@ -97,12 +98,13 @@ bool module_start_up(const module_t *module) {
  // as we're converting the startup sequence.
  assert(get_module_state(module) == MODULE_STATE_INITIALIZED || module->init == NULL);

  LOG_WARN(LOG_TAG, "%s Starting the module \"%s\"", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Starting module \"%s\"", __func__, module->name);
  if (!call_lifecycle_function(module->start_up)) {
    LOG_ERROR(LOG_TAG, "%s failed to start up \"%s\"", __func__, module->name);
    LOG_ERROR(LOG_TAG, "%s Failed to start up module \"%s\"",
              __func__, module->name);
    return false;
  }
  LOG_WARN(LOG_TAG, "%s Started the module \"%s\"", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Started module \"%s\"", __func__, module->name);

  set_module_state(module, MODULE_STATE_STARTED);
  return true;
@@ -118,11 +120,13 @@ void module_shut_down(const module_t *module) {
  if (state < MODULE_STATE_STARTED)
    return;

  LOG_WARN(LOG_TAG, "%s Shutting the module \"%s\"", __func__, module->name);
  if (!call_lifecycle_function(module->shut_down))
    LOG_ERROR(LOG_TAG, "%s found \"%s\" reported failure during shutdown. Continuing anyway.", __func__, module->name);
  else
    LOG_WARN(LOG_TAG, "%s Shutdown the module \"%s\"", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Shutting down module \"%s\"", __func__, module->name);
  if (!call_lifecycle_function(module->shut_down)) {
    LOG_ERROR(LOG_TAG, "%s Failed to shutdown module \"%s\". Continuing anyway.",
              __func__, module->name);
  }
  LOG_INFO(LOG_TAG, "%s Shutdown of module \"%s\" completed",
           __func__, module->name);

  set_module_state(module, MODULE_STATE_INITIALIZED);
}
@@ -137,8 +141,13 @@ void module_clean_up(const module_t *module) {
  if (state < MODULE_STATE_INITIALIZED)
    return;

  if (!call_lifecycle_function(module->clean_up))
    LOG_ERROR(LOG_TAG, "%s found \"%s\" reported failure during cleanup. Continuing anyway.", __func__, module->name);
  LOG_INFO(LOG_TAG, "%s Cleaning up module \"%s\"", __func__, module->name);
  if (!call_lifecycle_function(module->clean_up)) {
    LOG_ERROR(LOG_TAG, "%s Failed to cleanup module \"%s\". Continuing anyway.",
              __func__, module->name);
  }
  LOG_INFO(LOG_TAG, "%s Cleanup of module \"%s\" completed",
           __func__, module->name);

  set_module_state(module, MODULE_STATE_NONE);
}
+3 −4
Original line number Diff line number Diff line
@@ -76,16 +76,15 @@ bt_status_t btif_disable_bluetooth(void);

/*******************************************************************************
**
** Function         btif_shutdown_bluetooth
** Function         btif_cleanup_bluetooth
**
** Description      Finalizes BT scheduler shutdown and terminates BTIF
**                  task.
** Description      Cleanup BTIF state.
**
**
** Returns          void
**
*******************************************************************************/
bt_status_t btif_shutdown_bluetooth(void);
bt_status_t btif_cleanup_bluetooth(void);

/*******************************************************************************
**
+0 −1
Original line number Diff line number Diff line
@@ -215,6 +215,5 @@ void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
                                   uint32_t num_props, bt_property_t *p_props);

void btif_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
void btif_init_fail(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);

#endif /* BTIF_COMMON_H */
Loading