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

Commit 2ac5657a authored by Chris Manton's avatar Chris Manton
Browse files

bta_hf_client_add_record_test Use new sdp legacy api

Also update mock_stack_sdp_legacy_api

Bug: 267248792
Test: None
No-Typo-Check: legacy code

Change-Id: I86c351a8b8c74038d9c3f37a65c16a89061868ed
parent fa4981ee
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -371,6 +371,7 @@ cc_test {
        "sys/utl.cc",
        "test/bta_api_test.cc",
        "test/bta_av_test.cc",
        "test/bta_dm_cust_uuid_test.cc",
        "test/bta_dm_test.cc",
        "test/bta_gatt_test.cc",
        "test/bta_hf_client_add_record_test.cc",
+35 −25
Original line number Diff line number Diff line
@@ -35,10 +35,12 @@
#include "stack/btm/btm_sec.h"
#include "stack/include/btm_api.h"
#include "stack/include/port_api.h"
#include "stack/include/sdp_api.h"
#include "stack/include/sdpdefs.h"
#include "types/bluetooth/uuid.h"

using bluetooth::Uuid;
using namespace bluetooth::legacy::stack::sdp;

/* Number of protocol elements in protocol element list. */
#define BTA_HF_CLIENT_NUM_PROTO_ELEMS 2
@@ -84,7 +86,8 @@ static void bta_hf_client_sdp_cback(tSDP_STATUS status, const void* data) {
 * Description      This function is called by a server application to add
 *                  HFP Client information to an SDP record.  Prior to
 *                  calling this function the application must call
 *                  SDP_CreateRecord() to create an SDP record.
 *                  get_legacy_stack_sdp_api()->handle.SDP_CreateRecord() to
 *                  create an SDP record.
 *
 * Returns          true if function execution succeeded,
 *                  false if function execution failed.
@@ -113,24 +116,25 @@ bool bta_hf_client_add_record(const char* p_service_name, uint8_t scn,
  proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
  proto_elem_list[1].num_params = 1;
  proto_elem_list[1].params[0] = scn;
  result &= SDP_AddProtocolList(sdp_handle, BTA_HF_CLIENT_NUM_PROTO_ELEMS,
                                proto_elem_list);
  result &= get_legacy_stack_sdp_api()->handle.SDP_AddProtocolList(
      sdp_handle, BTA_HF_CLIENT_NUM_PROTO_ELEMS, proto_elem_list);

  /* add service class id list */
  svc_class_id_list[0] = UUID_SERVCLASS_HF_HANDSFREE;
  svc_class_id_list[1] = UUID_SERVCLASS_GENERIC_AUDIO;
  result &= SDP_AddServiceClassIdList(sdp_handle, BTA_HF_CLIENT_NUM_SVC_ELEMS,
                                      svc_class_id_list);
  result &= get_legacy_stack_sdp_api()->handle.SDP_AddServiceClassIdList(
      sdp_handle, BTA_HF_CLIENT_NUM_SVC_ELEMS, svc_class_id_list);

  /* add profile descriptor list */
  profile_uuid = UUID_SERVCLASS_HF_HANDSFREE;
  version = get_default_hfp_version();

  result &= SDP_AddProfileDescriptorList(sdp_handle, profile_uuid, version);
  result &= get_legacy_stack_sdp_api()->handle.SDP_AddProfileDescriptorList(
      sdp_handle, profile_uuid, version);

  /* add service name */
  if (p_service_name != NULL && p_service_name[0] != 0) {
    result &= SDP_AddAttribute(
    result &= get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
        sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
        (uint32_t)(strlen(p_service_name) + 1), (uint8_t*)p_service_name);
  }
@@ -153,12 +157,12 @@ bool bta_hf_client_add_record(const char* p_service_name, uint8_t scn,
  if (features & BTA_HF_CLIENT_FEAT_CODEC) sdp_features |= 0x0020;

  UINT16_TO_BE_FIELD(buf, sdp_features);
  result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES,
                             UINT_DESC_TYPE, 2, buf);
  result &= get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
      sdp_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE, 2, buf);

  /* add browse group list */
  result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1,
                                browse_list);
  result &= get_legacy_stack_sdp_api()->handle.SDP_AddUuidSequence(
      sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);

  return result;
}
@@ -177,7 +181,8 @@ void bta_hf_client_create_record(tBTA_HF_CLIENT_CB_ARR* client_cb_arr,
                                 const char* p_service_name) {
  /* add sdp record if not already registered */
  if (client_cb_arr->sdp_handle == 0) {
    client_cb_arr->sdp_handle = SDP_CreateRecord();
    client_cb_arr->sdp_handle =
        get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
    client_cb_arr->scn = BTM_AllocateSCN();
    bta_hf_client_add_record(p_service_name, client_cb_arr->scn,
                             client_cb_arr->features,
@@ -201,7 +206,7 @@ void bta_hf_client_del_record(tBTA_HF_CLIENT_CB_ARR* client_cb) {
  APPL_TRACE_DEBUG("%s", __func__);

  if (client_cb->sdp_handle != 0) {
    SDP_DeleteRecord(client_cb->sdp_handle);
    get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(client_cb->sdp_handle);
    client_cb->sdp_handle = 0;
    BTM_FreeSCN(client_cb->scn);
    bta_sys_remove_uuid(UUID_SERVCLASS_HF_HANDSFREE);
@@ -229,15 +234,16 @@ bool bta_hf_client_sdp_find_attr(tBTA_HF_CLIENT_CB* client_cb) {
  /* loop through all records we found */
  while (true) {
    /* get next record; if none found, we're done */
    p_rec = SDP_FindServiceInDb(client_cb->p_disc_db,
                                UUID_SERVCLASS_AG_HANDSFREE, p_rec);
    p_rec = get_legacy_stack_sdp_api()->db.SDP_FindServiceInDb(
        client_cb->p_disc_db, UUID_SERVCLASS_AG_HANDSFREE, p_rec);
    if (p_rec == NULL) {
      break;
    }

    /* get scn from proto desc list if initiator */
    if (client_cb->role == BTA_HF_CLIENT_INT) {
      if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
      if (get_legacy_stack_sdp_api()->record.SDP_FindProtocolListElemInRec(
              p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
        client_cb->peer_scn = (uint8_t)pe.params[0];
      } else {
        continue;
@@ -245,11 +251,12 @@ bool bta_hf_client_sdp_find_attr(tBTA_HF_CLIENT_CB* client_cb) {
    }

    /* get profile version (if failure, version parameter is not updated) */
    SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_HF_HANDSFREE,
                                &client_cb->peer_version);
    get_legacy_stack_sdp_api()->record.SDP_FindProfileVersionInRec(
        p_rec, UUID_SERVCLASS_HF_HANDSFREE, &client_cb->peer_version);

    /* get features */
    p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FEATURES);
    p_attr = get_legacy_stack_sdp_api()->record.SDP_FindAttributeInRec(
        p_rec, ATTR_ID_SUPPORTED_FEATURES);
    if (p_attr != NULL) {
      /* Found attribute. Get value. */
      /* There might be race condition between SDP and BRSF.  */
@@ -264,7 +271,8 @@ bool bta_hf_client_sdp_find_attr(tBTA_HF_CLIENT_CB* client_cb) {
        }

        /* get network for ability to reject calls */
        p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_NETWORK);
        p_attr = get_legacy_stack_sdp_api()->record.SDP_FindAttributeInRec(
            p_rec, ATTR_ID_NETWORK);
        if (p_attr != NULL) {
          if (p_attr->attr_value.v.u16 == 0x01) {
            client_cb->peer_features |= BTA_HF_CLIENT_PEER_REJECT;
@@ -323,12 +331,14 @@ void bta_hf_client_do_disc(tBTA_HF_CLIENT_CB* client_cb) {
  client_cb->p_disc_db = (tSDP_DISCOVERY_DB*)osi_malloc(BT_DEFAULT_BUFFER_SIZE);

  /* set up service discovery database; attr happens to be attr_list len */
  db_inited = SDP_InitDiscoveryDb(client_cb->p_disc_db, BT_DEFAULT_BUFFER_SIZE,
                                  num_uuid, uuid_list, num_attr, attr_list);
  db_inited = get_legacy_stack_sdp_api()->service.SDP_InitDiscoveryDb(
      client_cb->p_disc_db, BT_DEFAULT_BUFFER_SIZE, num_uuid, uuid_list,
      num_attr, attr_list);

  if (db_inited) {
    /*Service discovery not initiated */
    db_inited = SDP_ServiceSearchAttributeRequest2(
    db_inited =
        get_legacy_stack_sdp_api()->service.SDP_ServiceSearchAttributeRequest2(
            client_cb->peer_addr, client_cb->p_disc_db, bta_hf_client_sdp_cback,
            (void*)client_cb);
  }
+15 −1
Original line number Diff line number Diff line

/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cstdint>

+29 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "stack/include/sdp_api.h"

namespace test {
namespace mock {
namespace stack_sdp_legacy {

bluetooth::legacy::stack::sdp::tSdpApi api_;

}  // namespace stack_sdp_legacy
}  // namespace mock
}  // namespace test