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

Commit 9013866c authored by Zach Johnson's avatar Zach Johnson
Browse files

Flatten BTM_DeviceReset (and address a todo from 2014)

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ibb0e21c0b005f823ffbb5fb044fe12fe614cecf1
parent edb1bd07
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@
#endif
#include "bta/sys/bta_sys_int.h"
#include "bta_dm_int.h"
#include "main/shim/controller.h"

using bluetooth::common::MessageLoopThread;

@@ -227,7 +228,14 @@ static void event_start_up_stack(UNUSED_ATTR void* context) {
  bta_dm_enable(bte_dm_evt);

  bta_sys_set_state(BTA_SYS_HW_STARTING);
  BTM_DeviceReset();
  btm_acl_device_down();
  BTM_db_reset();
  if (bluetooth::shim::is_gd_controller_enabled()) {
    CHECK(module_start_up(get_module(GD_CONTROLLER_MODULE)));
  } else {
    CHECK(module_start_up(get_module(CONTROLLER_MODULE)));
  }
  BTM_reset_complete();

  if (future_await(local_hack_future) != FUTURE_SUCCESS) {
    LOG_ERROR("%s failed to start up the stack", __func__);
+3 −12
Original line number Diff line number Diff line
@@ -895,18 +895,9 @@ void BTM_BleEnableDisableFilterFeature(uint8_t enable,
 ******************************************************************************/
uint8_t BTM_BleMaxMultiAdvInstanceCount();

/*******************************************************************************
 *
 * Function         BTM_DeviceReset
 *
 * Description      This function is called to reset the controller.  The
 *                  Callback function if provided is called when startup of the
 *                  device has completed.
 *
 * Returns          void
 *
 ******************************************************************************/
void BTM_DeviceReset();
void BTM_db_reset(void);

void BTM_reset_complete();

/*******************************************************************************
 *
+2 −24
Original line number Diff line number Diff line
@@ -111,14 +111,10 @@ void btm_dev_init() {
 *
 * Function         btm_db_reset
 *
 * Description      This function is called by BTM_DeviceReset and clears out
 *                  any pending callbacks for inquiries, discoveries, other
 *                  pending functions that may be in progress.
 *
 * Returns          void
 *
 ******************************************************************************/
static void btm_db_reset(void) {
void BTM_db_reset(void) {
  tBTM_CMPL_CB* p_cb;

  btm_inq_db_reset();
@@ -170,8 +166,7 @@ bool set_sec_state_idle(void* data, void* context) {
  return true;
}

static void reset_complete(void* result) {
  CHECK(result == FUTURE_SUCCESS);
void BTM_reset_complete() {
  const controller_t* controller = controller_get_interface();

  /* Tell L2CAP that all connections are gone */
@@ -223,23 +218,6 @@ static void reset_complete(void* result) {
  send_bta_sys_hw_event(BTA_SYS_EVT_STACK_ENABLED_EVT);
}

// TODO(zachoverflow): remove this function
void BTM_DeviceReset() {
  /* Flush all ACL connections */
  btm_acl_device_down();

  /* Clear the callback, so application would not hang on reset */
  btm_db_reset();

  if (bluetooth::shim::is_gd_controller_enabled()) {
    module_start_up_callbacked_wrapper(get_module(GD_CONTROLLER_MODULE),
                                       &bt_startup_thread, reset_complete);
  } else {
    module_start_up_callbacked_wrapper(get_module(CONTROLLER_MODULE),
                                       &bt_startup_thread, reset_complete);
  }
}

/*******************************************************************************
 *
 * Function         BTM_IsDeviceUp
+3 −12
Original line number Diff line number Diff line
@@ -44,18 +44,9 @@
 *  DEVICE CONTROL and COMMON FUNCTIONS
 ****************************************************************************/

/*******************************************************************************
 *
 * Function         BTM_DeviceReset
 *
 * Description      This function is called to reset the controller.  The
 *                  Callback function if provided is called when startup of the
 *                  device has completed.
 *
 * Returns          void
 *
 ******************************************************************************/
void BTM_DeviceReset();
void BTM_db_reset(void);

void BTM_reset_complete();

/*******************************************************************************
 *