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

Commit 02b292f0 authored by Mingbo's avatar Mingbo Committed by Michał Narajowski
Browse files

device_iot_config: store iot device info

Store remote basic info (e.g. name, dev class, dev type, etc.)
and profile info (a2dp/hfp/avrcp/gap) to local conf file.

Snapshot as of:
43ab2ffdf6bdc48d0fb4a4d715da8863599f24e0
e080af8694d274d5db20204c48b9f6b714b17498
48b1654da46649a01ee9ab422f20aa60b8b31efd
964e674a41dbfdea612c66c684abc4d0e27500c1

Sponsor: narajn@
Bug: 261319328
Tag: #feature
Test: atest bluetooth_test_gd
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: If4c2632d3874fbec1e3477f40cd11b4b1db7a118
parent e8494449
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -295,6 +295,7 @@ cc_test {
    ],
    static_libs: [
        "libbluetooth-types",
        "libbtdevice",
        "libbt-common",
        "libbt-protos-lite",
        "libbtcore",
+21 −2
Original line number Diff line number Diff line
@@ -22,19 +22,20 @@
 *
 ******************************************************************************/

#include <base/logging.h>

#include <cstdint>
#include <cstring>

#include "bta/ag/bta_ag_int.h"
#include "bta/include/bta_dm_api.h"
#include "btif/include/btif_config.h"
#include "device/include/device_iot_config.h"
#include "osi/include/osi.h"  // UNUSED_ATTR
#include "stack/include/l2c_api.h"
#include "stack/include/port_api.h"
#include "types/raw_address.h"

#include <base/logging.h>

/*****************************************************************************
 *  Constants
 ****************************************************************************/
@@ -222,6 +223,10 @@ void bta_ag_disc_int_res(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {

      /* send ourselves sdp ok event */
      event = BTA_AG_DISC_OK_EVT;

      DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(
          p_scb->peer_addr, IOT_CONF_KEY_HFP_VERSION, p_scb->peer_version,
          IOT_CONF_BYTE_NUM_2);
    }
  }

@@ -269,6 +274,9 @@ void bta_ag_disc_acp_res(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
      data.disc_result.status == SDP_DB_FULL) {
    /* get attributes */
    bta_ag_sdp_find_attr(p_scb, bta_ag_svc_mask[p_scb->conn_service]);
    DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(
        p_scb->peer_addr, IOT_CONF_KEY_HFP_VERSION, p_scb->peer_version,
        IOT_CONF_BYTE_NUM_2);
  }

  /* free discovery db */
@@ -520,6 +528,7 @@ void bta_ag_rfc_acp_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {

  /* get bd addr of peer */
  uint16_t lcid = 0;
  uint16_t hfp_version = 0;
  RawAddress dev_addr = RawAddress::kEmpty;
  int status = PORT_CheckConnection(data.rfc.port_handle, &dev_addr, &lcid);
  if (status != PORT_SUCCESS) {
@@ -583,6 +592,16 @@ void bta_ag_rfc_acp_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
  bta_ag_close_servers(
      p_scb, (p_scb->reg_services & ~bta_ag_svc_mask[p_scb->conn_service]));

  size_t version_value_size = sizeof(hfp_version);
  bool get_version =
      btif_config_get_bin(p_scb->peer_addr.ToString(), HFP_VERSION_CONFIG_KEY,
                          (uint8_t*)&hfp_version, &version_value_size);

  if (p_scb->conn_service == BTA_AG_HFP && get_version) {
    DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(p_scb->peer_addr,
                                              IOT_CONF_KEY_HFP_VERSION,
                                              hfp_version, IOT_CONF_BYTE_NUM_2);
  }
  /* do service discovery to get features */
  bta_ag_do_disc(p_scb, bta_ag_svc_mask[p_scb->conn_service]);

+14 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "btif/include/btif_av_co.h"
#include "btif/include/btif_config.h"
#include "btif/include/btif_storage.h"
#include "device/include/device_iot_config.h"
#include "device/include/interop.h"
#include "main/shim/dumpsys.h"
#include "osi/include/allocator.h"
@@ -533,6 +534,10 @@ static void bta_av_a2dp_sdp_cback(bool found, tA2DP_Service* p_service,
  }
  if (found && (p_service != NULL)) {
    p_scb->SetAvdtpVersion(p_service->avdt_version);
    DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(
        p_scb->PeerAddress(), IOT_CONF_KEY_A2DP_VERSION,
        p_service->avdt_version, IOT_CONF_BYTE_NUM_2);

    if (p_service->avdt_version != 0) {
      if (btif_config_set_bin(p_scb->PeerAddress().ToString(),
                              AVDTP_VERSION_CONFIG_KEY,
@@ -970,10 +975,17 @@ void bta_av_config_ind(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
    p_info->seid = p_data->str_msg.msg.config_ind.int_seid;

    /* Sep type of Peer will be oppsite role to our local sep */
    if (local_sep == AVDT_TSEP_SRC)
    if (local_sep == AVDT_TSEP_SRC) {
      p_info->tsep = AVDT_TSEP_SNK;
    else if (local_sep == AVDT_TSEP_SNK)
      DEVICE_IOT_CONFIG_ADDR_SET_INT(p_scb->PeerAddress(),
                                     IOT_CONF_KEY_A2DP_ROLE,
                                     IOT_CONF_VAL_A2DP_ROLE_SINK);
    } else if (local_sep == AVDT_TSEP_SNK) {
      p_info->tsep = AVDT_TSEP_SRC;
      DEVICE_IOT_CONFIG_ADDR_SET_INT(p_scb->PeerAddress(),
                                     IOT_CONF_KEY_A2DP_ROLE,
                                     IOT_CONF_VAL_A2DP_ROLE_SOURCE);
    }

    p_scb->role |= BTA_AV_ROLE_AD_ACP;
    p_scb->cur_psc_mask = p_evt_cfg->psc_mask;
+51 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "bta/include/bta_ar_api.h"
#include "bta/include/utl.h"
#include "btif/avrcp/avrcp_service.h"
#include "device/include/device_iot_config.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"  // UNUSED_ATTR
@@ -323,6 +324,9 @@ uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl,
    tBTA_AV_SCB* p_scb = p_cb->p_scb[shdl - 1];
    bda = p_scb->PeerAddress();
    status = BTA_AV_RC_ROLE_INT;
    DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(p_scb->PeerAddress(),
                                       IOT_CONF_KEY_AVRCP_CONN_COUNT);

  } else {
    p_rcb = bta_av_get_rcb_by_shdl(shdl);
    if (p_rcb != NULL) {
@@ -341,8 +345,10 @@ uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl,
  ccb.control = p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_RCCT |
                                  BTA_AV_FEAT_METADATA | AVRC_CT_PASSIVE);

  if (AVRC_Open(&rc_handle, &ccb, bda) != AVRC_SUCCESS)
  if (AVRC_Open(&rc_handle, &ccb, bda) != AVRC_SUCCESS) {
    DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(bda, IOT_CONF_KEY_AVRCP_CONN_FAIL_COUNT);
    return BTA_AV_RC_HANDLE_NONE;
  }

  i = rc_handle;
  p_rcb = &p_cb->rcb[i];
@@ -1650,6 +1656,39 @@ static void bta_av_accept_signalling_timer_cback(void* data) {
  }
}

static void bta_av_store_peer_rc_version() {
  tBTA_AV_CB* p_cb = &bta_av_cb;
  tSDP_DISC_REC* p_rec = NULL;
  uint16_t peer_rc_version = 0; /*Assuming Default peer version as 1.3*/

  if ((p_rec = SDP_FindServiceInDb(
           p_cb->p_disc_db, UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL)) != NULL) {
    if ((SDP_FindAttributeInRec(p_rec, ATTR_ID_BT_PROFILE_DESC_LIST)) != NULL) {
      /* get profile version (if failure, version parameter is not updated) */
      SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_AV_REMOTE_CONTROL,
                                  &peer_rc_version);
    }
    if (peer_rc_version != 0)
      DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(
          p_rec->remote_bd_addr, IOT_CONF_KEY_AVRCP_CTRL_VERSION,
          peer_rc_version, IOT_CONF_BYTE_NUM_2);
  }

  peer_rc_version = 0;
  if ((p_rec = SDP_FindServiceInDb(
           p_cb->p_disc_db, UUID_SERVCLASS_AV_REM_CTRL_TARGET, NULL)) != NULL) {
    if ((SDP_FindAttributeInRec(p_rec, ATTR_ID_BT_PROFILE_DESC_LIST)) != NULL) {
      /* get profile version (if failure, version parameter is not updated) */
      SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_AV_REMOTE_CONTROL,
                                  &peer_rc_version);
    }
    if (peer_rc_version != 0)
      DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(
          p_rec->remote_bd_addr, IOT_CONF_KEY_AVRCP_TG_VERSION, peer_rc_version,
          IOT_CONF_BYTE_NUM_2);
  }
}

/*******************************************************************************
 *
 * Function         bta_av_check_peer_features
@@ -1986,6 +2025,8 @@ void bta_av_rc_disc_done(UNUSED_ATTR tBTA_AV_DATA* p_data) {
    }
  }

  bta_av_store_peer_rc_version();

  p_cb->disc = 0;
  osi_free_and_reset((void**)&p_cb->p_disc_db);

@@ -2036,6 +2077,10 @@ void bta_av_rc_disc_done(UNUSED_ATTR tBTA_AV_DATA* p_data) {
        bta_av_data.rc_open = rc_open;
        (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, &bta_av_data);
      }
      if (peer_features != 0)
        DEVICE_IOT_CONFIG_ADDR_SET_HEX(p_scb->PeerAddress(),
                                       IOT_CONF_KEY_AVRCP_FEATURES,
                                       peer_features, IOT_CONF_BYTE_NUM_2);
    }
  } else {
    tBTA_AV_RC_FEAT rc_feat;
@@ -2057,6 +2102,11 @@ void bta_av_rc_disc_done(UNUSED_ATTR tBTA_AV_DATA* p_data) {
    bta_av_feat.rc_feat = rc_feat;
    (*p_cb->p_cback)(BTA_AV_RC_FEAT_EVT, &bta_av_feat);

    if (peer_features != 0)
      DEVICE_IOT_CONFIG_ADDR_SET_HEX(rc_feat.peer_addr,
                                     IOT_CONF_KEY_AVRCP_FEATURES, peer_features,
                                     IOT_CONF_BYTE_NUM_2);

    // Send PSM data
    APPL_TRACE_DEBUG("%s: Send PSM data", __func__);
    tBTA_AV_RC_PSM rc_psm;
+3 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ cc_library_static {
        "src/btif_hf_client.cc",
        "src/btif_hh.cc",
        "src/btif_hd.cc",
        "src/btif_iot_config.cc",
        "src/btif_le_audio.cc",
        "src/btif_le_audio_broadcaster.cc",
        "src/btif_pan.cc",
@@ -186,6 +187,7 @@ cc_library_static {
        "src/btif_gatt_server.cc",
        "src/btif_gatt_test.cc",
        "src/btif_gatt_util.cc",
        "src/btif_iot_config.cc",
        "src/btif_metrics_logging.cc",
        "src/btif_profile_queue.cc",
        "src/btif_sdp.cc",
@@ -658,6 +660,7 @@ cc_test {
          "libbt-sbc-encoder",
          "libbtif",
          "libbtif-core",
          "libbt-stack-core",
          "libbtdevice",
          "lib-bt-packets",
          "lib-bt-packets-avrcp",
Loading