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

Commit ae1ade5f authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Merge changes Ib1ab0749,I3da1c525,Iea88fe7a,I2deeb024,I97ca9cff, ... into tm-qpr-dev

* changes:
  SDP: Add feature flag for serialization
  SDP: split the sdpu_process_pend_ccb
  SDP Use reference instead of int / pointer
  SDP code cleanup duplication
  SDP: TEST Handle race condition in HID SDP
  SDP: Handle race condition in HID SDP
  SDP: TEST Serialize sdp connections from profiles
  SDP: Serialize sdp connections from profiles/BT APP
  Prepare SDP for convergence
parents b1a8262a 40fab4b6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5164,6 +5164,7 @@ public class AdapterService extends Service {
    }

    // Boolean flags
    private static final String SDP_SERIALIZATION_FLAG = "INIT_sdp_serialization";
    private static final String GD_CORE_FLAG = "INIT_gd_core";
    private static final String GD_ADVERTISING_FLAG = "INIT_gd_advertising";
    private static final String GD_SCANNING_FLAG = "INIT_gd_scanning";
@@ -5206,6 +5207,10 @@ public class AdapterService extends Service {
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CORE_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_CORE_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                    SDP_SERIALIZATION_FLAG, true)) {
            initFlags.add(String.format("%s=%s", SDP_SERIALIZATION_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ADVERTISING_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_ADVERTISING_FLAG, "true"));
        }
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ macro_rules! init_flags {

init_flags!(
    flags: {
        sdp_serialization,
        gd_core,
        gd_security,
        gd_l2cap,
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ mod ffi {
        fn load(flags: Vec<String>);
        fn set_all_for_testing();

        fn sdp_serialization_is_enabled() -> bool;
        fn gd_core_is_enabled() -> bool;
        fn gd_security_is_enabled() -> bool;
        fn gd_l2cap_is_enabled() -> bool;
+16 −3
Original line number Diff line number Diff line
@@ -1380,7 +1380,12 @@ cc_test {
// Bluetooth stack connection multiplexing
cc_test {
    name: "net_test_stack_sdp",
    defaults: ["fluoride_defaults"],
    test_suites: ["device-tests"],
    host_supported: true,
    defaults: [
        "fluoride_defaults",
        "mts_defaults",
    ],
    local_include_dirs: [
        "include",
        "test/common",
@@ -1394,10 +1399,18 @@ cc_test {
    ],
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockBtif",
        ":TestMockOsi",
        ":TestMockStackL2cap",
        ":TestMockStackMetrics",
        "sdp/sdp_api.cc",
        "sdp/sdp_discovery.cc",
        "sdp/sdp_server.cc",
        "sdp/sdp_db.cc",
        "sdp/sdp_main.cc",
        "sdp/sdp_utils.cc",
        "test/common/mock_btif_config.cc",
        "test/stack_sdp_utils_test.cc",
        "test/sdp/stack_sdp_test.cc",
        "test/sdp/stack_sdp_utils_test.cc",
    ],
    shared_libs: [
        "libcutils",
+59 −49
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@
 *
 ******************************************************************************/

#include <base/logging.h>
#include <string.h>  // memset

#include "gd/common/init_flags.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"  // UNUSED_ATTR
#include "stack/include/bt_hdr.h"
@@ -34,8 +36,6 @@
#include "stack/sdp/sdpint.h"
#include "types/raw_address.h"

#include <base/logging.h>

/******************************************************************************/
/*                     G L O B A L      S D P       D A T A                   */
/******************************************************************************/
@@ -256,20 +256,23 @@ static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
    return;
  }
  tCONN_CB& ccb = *p_ccb;

  SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(((p_ccb->con_state == SDP_STATE_CONNECTED)
                        ? SDP_SUCCESS
                        : SDP_CONN_FAILED));
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(
        ((p_ccb->con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS
                                                   : SDP_CONN_FAILED),
        p_ccb->user_data);
  const tSDP_REASON reason =
      (ccb.con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS : SDP_CONN_FAILED;
  sdpu_callback(ccb, reason);

  if (ack_needed) {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, process pend sdp ccb: 0x%x",
                      l2cap_cid);
    sdpu_process_pend_ccb_new_cid(ccb);
  } else {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, clear pend sdp ccb: 0x%x",
                      l2cap_cid);
    sdpu_clear_pend_ccb(ccb);
  }

  sdpu_release_ccb(p_ccb);
  sdpu_release_ccb(ccb);
}

/*******************************************************************************
@@ -345,13 +348,24 @@ tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr) {
   */
  p_ccb->con_state = SDP_STATE_CONN_SETUP;

  // Look for any active sdp connection on the remote device
  cid = sdpu_get_active_ccb_cid(p_bd_addr);

  if (!bluetooth::common::init_flags::sdp_serialization_is_enabled() ||
      cid == 0) {
    p_ccb->con_state = SDP_STATE_CONN_SETUP;
    cid = L2CA_ConnectReq2(BT_PSM_SDP, p_bd_addr, BTM_SEC_NONE);
  } else {
    p_ccb->con_state = SDP_STATE_CONN_PEND;
    SDP_TRACE_WARNING("SDP already active for peer %s. cid=%#0x",
                      p_bd_addr.ToString().c_str(), cid);
  }

  /* Check if L2CAP started the connection process */
  if (cid == 0) {
    SDP_TRACE_WARNING("%s: SDP - Originate failed for peer %s", __func__,
                      p_bd_addr.ToString().c_str());
    sdpu_release_ccb(p_ccb);
    sdpu_release_ccb(*p_ccb);
    return (NULL);
  }
  p_ccb->connection_id = cid;
@@ -368,24 +382,26 @@ tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr) {
 *
 ******************************************************************************/
void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason) {
  SDP_TRACE_EVENT("SDP - disconnect  CID: 0x%x", p_ccb->connection_id);
  tCONN_CB& ccb = *p_ccb;
  SDP_TRACE_EVENT("SDP - disconnect  CID: 0x%x", ccb.connection_id);

  /* Check if we have a connection ID */
  if (p_ccb->connection_id != 0) {
    L2CA_DisconnectReq(p_ccb->connection_id);
    p_ccb->disconnect_reason = reason;
  if (ccb.connection_id != 0) {
    ccb.disconnect_reason = reason;
    if (SDP_SUCCESS == reason && sdpu_process_pend_ccb_same_cid(*p_ccb)) {
      sdpu_callback(ccb, reason);
      sdpu_release_ccb(ccb);
      return;
    } else {
      L2CA_DisconnectReq(ccb.connection_id);
    }
  }

  /* If at setup state, we may not get callback ind from L2CAP */
  /* Call user callback immediately */
  if (p_ccb->con_state == SDP_STATE_CONN_SETUP) {
    /* Tell the user if there is a callback */
    if (p_ccb->p_cb)
      (*p_ccb->p_cb)(reason);
    else if (p_ccb->p_cb2)
      (*p_ccb->p_cb2)(reason, p_ccb->user_data);

    sdpu_release_ccb(p_ccb);
  if (ccb.con_state == SDP_STATE_CONN_SETUP) {
    sdpu_callback(ccb, reason);
    sdpu_release_ccb(ccb);
  }
}

@@ -409,17 +425,13 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid,
                      l2cap_cid);
    return;
  }
  tCONN_CB& ccb = *p_ccb;

  SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);

  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason));
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason),
                    p_ccb->user_data);

  sdpu_release_ccb(p_ccb);
  sdpu_callback(ccb, static_cast<tSDP_STATUS>(ccb.disconnect_reason));
  sdpu_process_pend_ccb_new_cid(ccb);
  sdpu_release_ccb(ccb);
}

/*******************************************************************************
@@ -433,16 +445,14 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid,
 *
 ******************************************************************************/
void sdp_conn_timer_timeout(void* data) {
  tCONN_CB* p_ccb = (tCONN_CB*)data;

  SDP_TRACE_EVENT("SDP - CCB timeout in state: %d  CID: 0x%x", p_ccb->con_state,
                  p_ccb->connection_id);

  L2CA_DisconnectReq(p_ccb->connection_id);
  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(SDP_CONN_FAILED);
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(SDP_CONN_FAILED, p_ccb->user_data);
  sdpu_release_ccb(p_ccb);
  tCONN_CB& ccb = *(tCONN_CB*)data;

  SDP_TRACE_EVENT("SDP - CCB timeout in state: %d  CID: 0x%x", ccb.con_state,
                  ccb.connection_id);

  L2CA_DisconnectReq(ccb.connection_id);

  sdpu_callback(ccb, SDP_CONN_FAILED);
  sdpu_clear_pend_ccb(ccb);
  sdpu_release_ccb(ccb);
}
Loading