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

Commit 83103288 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

gatt: Prepare GATTC_OPEN API for more than direct and background

Bug: 248340126
Test: atest BluetoothInstrumentationTests
Tag: #feature

Merged-In: Iea86534687dc5f0febc4a9c493e011750ebf1823
Change-Id: Iea86534687dc5f0febc4a9c493e011750ebf1823
(cherry picked from commit 3f67dac5)
parent 90feee59
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ class CsisClientImpl : public CsisClient {
      device->connecting_actively = true;
    }

    BTA_GATTC_Open(gatt_if_, address, true, false);
    BTA_GATTC_Open(gatt_if_, address, BTM_BLE_DIRECT_CONNECTION, false);
  }

  void Disconnect(const RawAddress& addr) override {
@@ -654,7 +654,7 @@ class CsisClientImpl : public CsisClient {
    }

    if (autoconnect) {
      BTA_GATTC_Open(gatt_if_, addr, false, false);
      BTA_GATTC_Open(gatt_if_, addr, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
    }
  }

+4 −2
Original line number Diff line number Diff line
@@ -426,7 +426,8 @@ class CsisClientTest : public ::testing::Test {
        .WillByDefault(
            DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true)));

    EXPECT_CALL(gatt_interface, Open(gatt_if, address, true, _));
    EXPECT_CALL(gatt_interface,
                Open(gatt_if, address, BTM_BLE_DIRECT_CONNECTION, _));
    CsisClient::Get()->Connect(address);
    Mock::VerifyAndClearExpectations(&gatt_interface);
    Mock::VerifyAndClearExpectations(&btm_interface);
@@ -449,7 +450,8 @@ class CsisClientTest : public ::testing::Test {
                OnConnectionState(address, ConnectionState::CONNECTED))
        .Times(1);
    EXPECT_CALL(*callbacks, OnDeviceAvailable(address, _, _, _, _)).Times(1);
    EXPECT_CALL(gatt_interface, Open(gatt_if, address, false, _))
    EXPECT_CALL(gatt_interface,
                Open(gatt_if, address, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
        .WillOnce(Invoke([this, conn_id](tGATT_IF client_if,
                                         const RawAddress& remote_bda,
                                         bool is_direct, bool opportunistic) {
+4 −2
Original line number Diff line number Diff line
@@ -4046,9 +4046,11 @@ void btm_dm_start_gatt_discovery(const RawAddress& bd_addr) {
    BTA_GATTC_ServiceSearchRequest(bta_dm_search_cb.conn_id, nullptr);
  } else {
    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, true);
      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr,
                     BTM_BLE_DIRECT_CONNECTION, true);
    } else {
      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, false);
      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr,
                     BTM_BLE_DIRECT_CONNECTION, false);
    }
  }
}
+6 −5
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ void bta_gattc_process_api_open(const tBTA_GATTC_DATA* p_msg) {
    return;
  }

  if (!p_msg->api_conn.is_direct) {
  if (p_msg->api_conn.connection_type != BTM_BLE_DIRECT_CONNECTION) {
    bta_gattc_init_bk_conn(&p_msg->api_conn, p_clreg);
    return;
  }
@@ -377,8 +377,9 @@ void bta_gattc_open(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
  tBTA_GATTC_DATA gattc_data;

  /* open/hold a connection */
  if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, true,
                    p_data->api_conn.transport, p_data->api_conn.opportunistic,
  if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda,
                    BTM_BLE_DIRECT_CONNECTION, p_data->api_conn.transport,
                    p_data->api_conn.opportunistic,
                    p_data->api_conn.initiating_phys)) {
    LOG(ERROR) << "Connection open failure";
    bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_OPEN_FAIL_EVT, p_data);
@@ -417,8 +418,8 @@ static void bta_gattc_init_bk_conn(const tBTA_GATTC_API_OPEN* p_data,
  }

  /* always call open to hold a connection */
  if (!GATT_Connect(p_data->client_if, p_data->remote_bda, false,
                    p_data->transport, false)) {
  if (!GATT_Connect(p_data->client_if, p_data->remote_bda,
                    p_data->connection_type, p_data->transport, false)) {
    LOG_ERROR("Unable to connect to remote bd_addr=%s",
              p_data->remote_bda.ToString().c_str());
    bta_gattc_send_open_cback(p_clreg, GATT_ERROR, p_data->remote_bda,
+6 −6
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ void BTA_GATTC_AppDeregister(tGATT_IF client_if) {
 *
 * Parameters       client_if: server interface.
 *                  remote_bda: remote device BD address.
 *                  is_direct: direct connection or background auto connection
 *                  connection_type: connection type used for the peer device
 *                  transport: Transport to be used for GATT connection
 *                             (BREDR/LE)
 *                  initiating_phys: LE PHY to use, optional
@@ -128,15 +128,15 @@ void BTA_GATTC_AppDeregister(tGATT_IF client_if) {
 *
 ******************************************************************************/
void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
                    bool is_direct, bool opportunistic) {
                    tBTM_BLE_CONN_TYPE connection_type, bool opportunistic) {
  uint8_t phy = controller_get_interface()->get_le_all_initiating_phys();
  BTA_GATTC_Open(client_if, remote_bda, is_direct, BT_TRANSPORT_LE,
  BTA_GATTC_Open(client_if, remote_bda, connection_type, BT_TRANSPORT_LE,
                 opportunistic, phy);
}

void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
                    bool is_direct, tBT_TRANSPORT transport, bool opportunistic,
                    uint8_t initiating_phys) {
                    tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
                    bool opportunistic, uint8_t initiating_phys) {
  tBTA_GATTC_DATA data = {
      .api_conn =
          {
@@ -146,7 +146,7 @@ void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
                  },
              .remote_bda = remote_bda,
              .client_if = client_if,
              .is_direct = is_direct,
              .connection_type = connection_type,
              .transport = transport,
              .initiating_phys = initiating_phys,
              .opportunistic = opportunistic,
Loading