From: Hansong Zhang Date: Tue, 17 Jul 2018 23:24:24 +0000 (-0700) Subject: Enable BLE background connection when stack is started X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f91d55816cabcb421fa6ebd56865cbd434b762b9;p=android-x86%2Fsystem-bt.git Enable BLE background connection when stack is started 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 --- diff --git a/bta/dm/bta_dm_api.cc b/bta/dm/bta_dm_api.cc index 419dda163..979d2f619 100644 --- a/bta/dm/bta_dm_api.cc +++ b/bta/dm/bta_dm_api.cc @@ -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 diff --git a/bta/hearing_aid/hearing_aid.cc b/bta/hearing_aid/hearing_aid.cc index e6381e009..ff3905564 100644 --- a/bta/hearing_aid/hearing_aid.cc +++ b/bta/hearing_aid/hearing_aid.cc @@ -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, diff --git a/bta/hh/bta_hh_le.cc b/bta/hh/bta_hh_le.cc index 79a566d4f..eb87cdff0 100644 --- a/bta/hh/bta_hh_le.cc +++ b/bta/hh/bta_hh_le.cc @@ -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; } diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h index 85b50b69e..d747b48d5 100644 --- a/bta/include/bta_api.h +++ b/bta/include/bta_api.h @@ -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 diff --git a/btif/src/btif_gatt_client.cc b/btif/src/btif_gatt_client.cc index 9f66d7aa3..14433d397 100644 --- a/btif/src/btif_gatt_client.cc +++ b/btif/src/btif_gatt_client.cc @@ -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); diff --git a/btif/src/btif_gatt_server.cc b/btif/src/btif_gatt_server.cc index d994d2ab8..6dc5eb7ea 100644 --- a/btif/src/btif_gatt_server.cc +++ b/btif/src/btif_gatt_server.cc @@ -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; diff --git a/stack/btm/btm_ble_bgconn.cc b/stack/btm/btm_ble_bgconn.cc index 3f121585a..45cbc463c 100644 --- a/stack/btm/btm_ble_bgconn.cc +++ b/stack/btm/btm_ble_bgconn.cc @@ -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 diff --git a/stack/btm/btm_ble_bgconn.h b/stack/btm/btm_ble_bgconn.h index 2ae228507..45ab2ec6f 100644 --- a/stack/btm/btm_ble_bgconn.h +++ b/stack/btm/btm_ble_bgconn.h @@ -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); diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc index 9f9e8a3f8..f68ad5879 100644 --- a/stack/btm/btm_ble_gap.cc +++ b/stack/btm/btm_ble_gap.cc @@ -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 diff --git a/stack/btm/btm_ble_int_types.h b/stack/btm/btm_ble_int_types.h index 68f46f206..3d4b8bb67 100644 --- a/stack/btm/btm_ble_int_types.h +++ b/stack/btm/btm_ble_int_types.h @@ -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; diff --git a/stack/btm/btm_devctl.cc b/stack/btm/btm_devctl.cc index 4e0086e2d..d21e3631d 100644 --- a/stack/btm/btm_devctl.cc +++ b/stack/btm/btm_devctl.cc @@ -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(); diff --git a/stack/include/btm_ble_api_types.h b/stack/include/btm_ble_api_types.h index d7b223fda..50a85a90e 100644 --- a/stack/include/btm_ble_api_types.h +++ b/stack/include/btm_ble_api_types.h @@ -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