OSDN Git Service

Enable BLE background connection when stack is started
authorHansong Zhang <hsz@google.com>
Tue, 17 Jul 2018 23:24:24 +0000 (16:24 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 19 Dec 2018 20:51:12 +0000 (20:51 +0000)
Remove variable btm_cb.ble_ctr_cb.bg_conn_type. We can enable the
background mode when the Bluetooth stack is started and don't have
to wait until the first background connection request from HID
Device/Hearing Aid/GATT. As soon as we add the first device to white
list, the stack will send HCI Create Connection (White List) command.

Test: manual. Bond to a BLE mouse and turn off/on Bluetooth. Also test
with initiating another direct/white list connection while another white
list connection is pending
Bug: 111562702
Bug: 112827989
Change-Id: I82a476489d181d17aa1c1da8202df1be76928d77

12 files changed:
bta/dm/bta_dm_api.cc
bta/hearing_aid/hearing_aid.cc
bta/hh/bta_hh_le.cc
bta/include/bta_api.h
btif/src/btif_gatt_client.cc
btif/src/btif_gatt_server.cc
stack/btm/btm_ble_bgconn.cc
stack/btm/btm_ble_bgconn.h
stack/btm/btm_ble_gap.cc
stack/btm/btm_ble_int_types.h
stack/btm/btm_devctl.cc
stack/include/btm_ble_api_types.h

index 419dda1..979d2f6 100644 (file)
@@ -567,11 +567,6 @@ void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
                                           scan_interval, scan_window));
 }
 
-/** Set BLE connectable mode to auto connect */
-void BTA_DmBleStartAutoConn() {
-  do_in_main_thread(FROM_HERE, base::Bind(BTM_BleStartAutoConn));
-}
-
 /*******************************************************************************
  *
  * Function         bta_dm_discover_send_msg
index e6381e0..ff39055 100644 (file)
@@ -365,7 +365,6 @@ class HearingAidImpl : public HearingAid {
 
       /* add device into BG connection to accept remote initiated connection */
       BTA_GATTC_Open(gatt_if, address, false, GATT_TRANSPORT_LE, false);
-      BTA_DmBleStartAutoConn();
     }
 
     callbacks->OnDeviceAvailable(capabilities, hiSyncId, address);
@@ -814,7 +813,6 @@ class HearingAidImpl : public HearingAid {
     if (hearingDevice->first_connection) {
       /* add device into BG connection to accept remote initiated connection */
       BTA_GATTC_Open(gatt_if, address, false, GATT_TRANSPORT_LE, false);
-      BTA_DmBleStartAutoConn();
 
       btif_storage_add_hearing_aid(
           address, hearingDevice->psm, hearingDevice->capabilities,
index 79a566d..eb87cdf 100644 (file)
@@ -1995,8 +1995,6 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB* p_cb, bool check_bond) {
     BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, GATT_TRANSPORT_LE,
                    false);
     p_cb->in_bg_conn = true;
-
-    BTA_DmBleStartAutoConn();
   }
   return;
 }
index 85b50b6..d747b48 100644 (file)
@@ -1384,11 +1384,6 @@ extern void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
 extern void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
                                    tBTA_DM_BLE_SEC_GRANT res);
 
-/**
- * Set BLE connectable mode to auto connect
- */
-extern void BTA_DmBleStartAutoConn();
-
 /*******************************************************************************
  *
  * Function         BTA_DmBlePasskeyReply
index 9f66d7a..14433d3 100644 (file)
@@ -303,10 +303,6 @@ void btif_gattc_open_impl(int client_if, RawAddress address, bool is_direct,
     }
   }
 
-  if (transport == GATT_TRANSPORT_LE) {
-    BTA_DmBleStartAutoConn();
-  }
-
   // Connect!
   BTIF_TRACE_DEBUG("%s Transport=%d, device type=%d, phy=%d", __func__,
                    transport, device_type, initiating_phys);
index d994d2a..6dc5eb7 100644 (file)
@@ -291,9 +291,6 @@ static void btif_gatts_open_impl(int server_if, const RawAddress& address,
     BTA_DmAddBleDevice(address, addr_type, device_type);
   }
 
-  // Mark background connections
-  if (!is_direct) BTA_DmBleStartAutoConn();
-
   // Determine transport
   if (transport_param != GATT_TRANSPORT_AUTO) {
     transport = transport_param;
index 3f12158..45cbc46 100644 (file)
@@ -468,11 +468,7 @@ bool btm_ble_stop_auto_conn() {
  ******************************************************************************/
 bool btm_ble_suspend_bg_conn(void) {
   BTM_TRACE_EVENT("%s", __func__);
-
-  if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO)
-    return btm_ble_stop_auto_conn();
-
-  return false;
+  return btm_ble_stop_auto_conn();
 }
 
 /*******************************************************************************
@@ -487,14 +483,7 @@ bool btm_ble_suspend_bg_conn(void) {
  * Returns          none.
  *
  ******************************************************************************/
-bool btm_ble_resume_bg_conn(void) {
-  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
-  if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) {
-    return btm_ble_start_auto_conn();
-  }
-
-  return false;
-}
+bool btm_ble_resume_bg_conn(void) { return btm_ble_start_auto_conn(); }
 /*******************************************************************************
  *
  * Function         btm_ble_get_conn_st
index 2ae2285..45ab2ec 100644 (file)
@@ -18,9 +18,6 @@
 
 #include "types/raw_address.h"
 
-/** Set BLE connectable mode to auto connect */
-extern void BTM_BleStartAutoConn();
-
 /** Adds the device into white list. Returns false if white list is full and
  * device can't be added, true otherwise. */
 extern bool BTM_WhiteListAdd(const RawAddress& address);
index 9f9e8a3..f68ad58 100644 (file)
@@ -696,17 +696,6 @@ bool BTM_BleLocalPrivacyEnabled(void) {
 #endif
 }
 
-/** Set BLE connectable mode to auto connect */
-void BTM_BleStartAutoConn() {
-  BTM_TRACE_EVENT("%s", __func__);
-  if (!controller_get_interface()->supports_ble()) return;
-
-  if (btm_cb.ble_ctr_cb.bg_conn_type != BTM_BLE_CONN_AUTO) {
-    btm_ble_start_auto_conn();
-    btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_AUTO;
-  }
-}
-
 /*******************************************************************************
  *
  * Function         BTM_BleSetConnectableMode
index 68f46f2..3d4b8bb 100644 (file)
@@ -286,7 +286,6 @@ typedef struct {
   alarm_t* observer_timer;
 
   /* background connection procedure cb value */
-  tBTM_BLE_CONN_TYPE bg_conn_type;
   uint16_t scan_int;
   uint16_t scan_win;
 
index 4e0086e..d21e363 100644 (file)
@@ -189,7 +189,6 @@ static void reset_complete(void* result) {
   btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
 
   btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
-  btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE;
   gatt::connection_manager::reset(true);
 
   btm_pm_reset();
index d7b223f..50a85a9 100644 (file)
@@ -495,9 +495,6 @@ typedef uint8_t BTM_BLE_ADV_INFO_PRESENT;
 typedef uint8_t BTM_BLE_RSSI_VALUE;
 typedef uint16_t BTM_BLE_ADV_INFO_TIMESTAMP;
 
-enum { BTM_BLE_CONN_NONE, BTM_BLE_CONN_AUTO };
-typedef uint8_t tBTM_BLE_CONN_TYPE;
-
 #define ADV_INFO_PRESENT 0x00
 #define NO_ADV_INFO_PRESENT 0x01