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

Commit ae874fb7 authored by Rahul Arya's avatar Rahul Arya Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-L42400000957798874:N63400001321492074" into tm-qpr-dev

* changes:
  [RESTRICT AUTOMERGE] Reduce behavior change with LE ACL timeout on T
  Improve handling of GATT timeout
parents ebd52853 72689620
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -428,6 +428,8 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable);
 ******************************************************************************/
bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout);

bool L2CA_MarkLeLinkAsActive(const RawAddress& rem_bda);

bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, uint16_t min_int,
                              uint16_t max_int, uint16_t latency,
                              uint16_t timeout, uint16_t min_ce_len,
+13 −3
Original line number Diff line number Diff line
@@ -1037,26 +1037,36 @@ tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t cid) {
 *
 * Parameter        bd_addr:   target device bd address.
 *                  idle_tout: timeout value in seconds.
 *                  transport: transport option.
 *                  is_active: whether we should use this as a signal that an
 *                             active client now exists (which changes link
 *                             timeout logic, see
 *                             t_l2c_linkcb.with_active_local_clients for
 *                             details).
 *
 * Returns          void
 *
 ******************************************************************************/
void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
                         tBT_TRANSPORT transport) {
                         tBT_TRANSPORT transport, bool is_active) {
  bool status = false;

  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
  if (p_tcb != nullptr) {
    status = L2CA_SetLeGattTimeout(bd_addr, idle_tout);

    if (is_active) {
      status &= L2CA_MarkLeLinkAsActive(bd_addr);
    }

    if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) {
      L2CA_SetIdleTimeoutByBdAddr(
          p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, BT_TRANSPORT_LE);
    }
  }

  LOG_INFO("idle_timeout=%d, status=%d, (1-OK 0-not performed)", idle_tout,
           +status);
  LOG_INFO("idle_timeout=%d, is_active=%d, status=%d (1-OK 0-not performed)",
           idle_tout, is_active, +status);
}

/*******************************************************************************
+19 −11
Original line number Diff line number Diff line
@@ -114,10 +114,11 @@ void gatt_init(void) {
  fixed_reg.pL2CA_FixedConn_Cb = gatt_le_connect_cback;
  fixed_reg.pL2CA_FixedData_Cb = gatt_le_data_ind;
  fixed_reg.pL2CA_FixedCong_Cb = gatt_le_cong_cback; /* congestion callback */
  fixed_reg.default_idle_tout =
      bluetooth::common::init_flags::finite_att_timeout_is_enabled()
          ? 2 /* We allow 2s for GATT clients to connect once the link is up */
          : L2CAP_NO_IDLE_TIMEOUT;

  // the GATT timeout is updated after a connection
  // is established, when we know whether any
  // clients exist
  fixed_reg.default_idle_tout = L2CAP_NO_IDLE_TIMEOUT;

  L2CA_RegisterFixedChannel(L2CAP_ATT_CID, &fixed_reg);

@@ -376,7 +377,7 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
               p_tcb->peer_bda.ToString().c_str());
      /* acl link is connected disable the idle timeout */
      GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT,
                          p_tcb->transport);
                          p_tcb->transport, true /* is_active */);
    } else {
      LOG_INFO("invalid handle %d or dynamic CID %d", is_valid_handle,
               p_tcb->att_lcid);
@@ -395,7 +396,7 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
            "%d seconds",
            GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP);
        GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP,
                            p_tcb->transport);
                            p_tcb->transport, false /* is_active */);
      } else {
        // disconnect the dynamic channel
        LOG_INFO("disconnect GATT dynamic channel");
@@ -819,11 +820,18 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
  /* Remove the direct connection */
  connection_manager::on_connection_complete(p_tcb->peer_bda);

  if (!p_tcb->app_hold_link.empty() && p_tcb->att_lcid == L2CAP_ATT_CID) {
    /* disable idle timeout if one or more clients are holding the link disable
     * the idle timer */
  if (p_tcb->att_lcid == L2CAP_ATT_CID) {
    if (!p_tcb->app_hold_link.empty()) {
      /* disable idle timeout if one or more clients are holding the link
       * disable the idle timer */
      GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT,
                        p_tcb->transport);
                          p_tcb->transport, true /* is_active */);
    } else {
      if (bluetooth::common::init_flags::finite_att_timeout_is_enabled()) {
        GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP,
                            p_tcb->transport, false /* is_active */);
      }
    }
  }
}

+7 −2
Original line number Diff line number Diff line
@@ -999,13 +999,18 @@ extern tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id,
 *
 * Parameter        bd_addr:   target device bd address.
 *                  idle_tout: timeout value in seconds.
 *                  transport: trasnport option.
 *                  transport: transport option.
 *                  is_active: whether we should use this as a signal that an
 *                             active client now exists (which changes link
 *                             timeout logic, see
 *                             t_l2c_linkcb.with_active_local_clients for
 *                             details).
 *
 * Returns          void
 *
 ******************************************************************************/
extern void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
                                tBT_TRANSPORT transport);
                                tBT_TRANSPORT transport, bool is_active);

/*******************************************************************************
 *
+2 −0
Original line number Diff line number Diff line
@@ -842,6 +842,8 @@ extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda);
extern bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda,
                                  uint16_t idle_tout);

extern bool L2CA_MarkLeLinkAsActive(const RawAddress& rem_bda);

extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda,
                                     uint16_t min_int, uint16_t max_int,
                                     uint16_t latency, uint16_t timeout,
Loading