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

Commit 32983d7d authored by Sam Chiu's avatar Sam Chiu
Browse files

Revert "Add tests for BQR Events"

Revert submission 3074206

Reason for revert: To verify the test failure b/339556159

Reverted changes: /q/submissionid:3074206

Change-Id: Ib1c3fb30d954afd2c5b2581a47af904ee85f6dde
parent 2fcf03e3
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -735,7 +735,6 @@ cc_test {
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_gd",
        "libbluetooth_hci_pdl",
        "libbluetooth_log",
        "libbt-audio-hal-interface",
        "libbt-btu-main-thread",
@@ -753,7 +752,6 @@ cc_test {
        "libchrome",
        "libcom.android.sysprop.bluetooth.wrapped",
        "libevent",
        "libflatbuffers-cpp",
        "libgmock",
        "libprotobuf-cpp-lite",
        "libstatslog_bt",
+5 −5
Original line number Diff line number Diff line
@@ -20,8 +20,7 @@
#include <bluetooth/log.h>

#include "btm_api_types.h"
#include "common/postable_context.h"
#include "hci/hci_packets.h"
#include "common/leaky_bonded_queue.h"
#include "include/hardware/bt_bqr.h"
#include "osi/include/osi.h"
#include "raw_address.h"
@@ -413,8 +412,9 @@ std::string PacketTypeToString(uint8_t packet_type);
// And the minimum time interval of quality event reporting depends on the
// setting of property "persist.bluetooth.bqr.min_interval_ms".
//
// @param to_bind gives the postable for the callback, or null if disabling.
void EnableBtQualityReport(common::PostableContext* to_bind);
// @param is_enable True/False to enable/disable Bluetooth Quality Report
//   mechanism in the Bluetooth controller.
void EnableBtQualityReport(bool is_enable);

// Configure Bluetooth Quality Report setting to the Bluetooth controller.
//
@@ -426,7 +426,7 @@ void ConfigureBqr(const BqrConfiguration& bqr_config);
//
// @param p_vsc_cmpl_params A pointer to the parameters contained in the vendor
//   specific command complete event.
void BqrVscCompleteCallback(hci::CommandCompleteView complete);
void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params);

// Invoked on completion of Bluetooth Quality Report configuration. Then it will
// Register/Unregister for receiving VSE - Bluetooth Quality Report sub-event.
+38 −92
Original line number Diff line number Diff line
@@ -22,28 +22,21 @@
#include <sys/stat.h>

#include <cerrno>
#include <cstdint>

#include "btif/include/stack_manager_t.h"
#include "btif_bqr.h"
#include "btif_common.h"
#include "btif_storage.h"
#include "btm_api.h"
#include "btm_ble_api.h"
#include "common/leaky_bonded_queue.h"
#include "common/postable_context.h"
#include "common/time_util.h"
#include "core_callbacks.h"
#include "hci/hci_interface.h"
#include "hci/hci_packets.h"
#include "hci/vendor_specific_event_manager_interface.h"
#include "internal_include/bt_trace.h"
#include "main/shim/entry.h"
#include "osi/include/properties.h"
#include "packet/raw_builder.h"
#include "raw_address.h"
#include "stack/btm/btm_dev.h"
#include "stack/include/bt_types.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_ble_api.h"

namespace bluetooth {
namespace bqr {
@@ -52,7 +45,8 @@ using bluetooth::common::LeakyBondedQueue;
using std::chrono::system_clock;

// The instance of BQR event queue
static std::unique_ptr<LeakyBondedQueue<BqrVseSubEvt>> kpBqrEventQueue;
static std::unique_ptr<LeakyBondedQueue<BqrVseSubEvt>> kpBqrEventQueue(
    new LeakyBondedQueue<BqrVseSubEvt>(kBqrEventQueueSize));

static uint16_t vendor_cap_supported_version;

@@ -72,10 +66,6 @@ static tBTM_BT_QUALITY_REPORT_RECEIVER* p_bqr_report_receiver_ = nullptr;
typedef void(tBTM_VS_EVT_CB)(uint8_t len, const uint8_t* p);
tBTM_VS_EVT_CB* p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS];

namespace {
common::PostableContext* to_bind_ = nullptr;
}

void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length,
                                          const uint8_t* p_param_buf) {
  if (length < kLinkQualityParamTotalLen) {
@@ -342,14 +332,8 @@ std::string PacketTypeToString(uint8_t packet_type) {
  }
}

void register_vse();
void unregister_vse();

void EnableBtQualityReport(common::PostableContext* to_bind) {
  log::info("is_enable: {}", to_bind != nullptr);
  if (to_bind != nullptr) {
    to_bind_ = to_bind;
  }
void EnableBtQualityReport(bool is_enable) {
  log::info("is_enable: {}", is_enable);

  char bqr_prop_evtmask[PROPERTY_VALUE_MAX] = {0};
  char bqr_prop_interval_ms[PROPERTY_VALUE_MAX] = {0};
@@ -372,7 +356,7 @@ void EnableBtQualityReport(common::PostableContext* to_bind) {

  BqrConfiguration bqr_config = {};

  if (to_bind) {
  if (is_enable) {
    bqr_config.report_action = REPORT_ACTION_ADD;
    bqr_config.quality_event_mask =
        static_cast<uint32_t>(atoi(bqr_prop_evtmask));
@@ -384,9 +368,6 @@ void EnableBtQualityReport(common::PostableContext* to_bind) {
        static_cast<uint32_t>(atoi(bqr_prop_vnd_trace_mask));
    bqr_config.report_interval_multiple =
        static_cast<uint32_t>(atoi(bqr_prop_interval_multiple));
    register_vse();
    kpBqrEventQueue =
        std::make_unique<LeakyBondedQueue<BqrVseSubEvt>>(kBqrEventQueueSize);
  } else {
    bqr_config.report_action = REPORT_ACTION_CLEAR;
    bqr_config.quality_event_mask = kQualityEventMaskAllOff;
@@ -394,7 +375,6 @@ void EnableBtQualityReport(common::PostableContext* to_bind) {
    bqr_config.vnd_quality_mask = 0;
    bqr_config.vnd_trace_mask = 0;
    bqr_config.report_interval_multiple = 0;
    unregister_vse();
  }

  tBTM_BLE_VSC_CB cmn_vsc_cb;
@@ -439,33 +419,24 @@ void ConfigureBqr(const BqrConfiguration& bqr_config) {
            bqr_config.minimum_report_interval_ms,
            bqr_config.report_interval_multiple);

  auto payload = std::make_unique<packet::RawBuilder>();
  payload->AddOctets1(bqr_config.report_action);
  payload->AddOctets4(bqr_config.quality_event_mask);
  payload->AddOctets2(bqr_config.minimum_report_interval_ms);
  uint8_t param[sizeof(BqrConfiguration)];
  uint8_t* p_param = param;
  UINT8_TO_STREAM(p_param, bqr_config.report_action);
  UINT32_TO_STREAM(p_param, bqr_config.quality_event_mask);
  UINT16_TO_STREAM(p_param, bqr_config.minimum_report_interval_ms);
  if (vendor_cap_supported_version >= kBqrVndLogVersion) {
    payload->AddOctets4(bqr_config.vnd_quality_mask);
    payload->AddOctets4(bqr_config.vnd_trace_mask);
    UINT32_TO_STREAM(p_param, bqr_config.vnd_quality_mask);
    UINT32_TO_STREAM(p_param, bqr_config.vnd_trace_mask);
  }
  if (vendor_cap_supported_version >= kBqrVersion6_0) {
    payload->AddOctets4(bqr_config.report_interval_multiple);
    UINT32_TO_STREAM(p_param, bqr_config.report_interval_multiple);
  }

  shim::GetHciLayer()->EnqueueCommand(
      hci::CommandBuilder::Create(hci::OpCode::CONTROLLER_BQR,
                                  std::move(payload)),
      to_bind_->BindOnce(BqrVscCompleteCallback));
  BTM_VendorSpecificCommand(HCI_CONTROLLER_BQR, p_param - param, param,
                            BqrVscCompleteCallback);
}

void BqrVscCompleteCallback(bluetooth::hci::CommandCompleteView complete) {
  std::vector<uint8_t> payload_vector{complete.GetPayload().begin(),
                                      complete.GetPayload().end()};
  tBTM_VSC_CMPL vsc_cmpl_params = {
      .opcode = static_cast<uint16_t>(complete.GetCommandOpCode()),
      .param_len = static_cast<uint16_t>(payload_vector.size()),
      .p_param_buf = payload_vector.data()};
  tBTM_VSC_CMPL* p_vsc_cmpl_params = &vsc_cmpl_params;

void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) {
  if (p_vsc_cmpl_params->param_len < 1) {
    log::error("The length of returned parameters is less than 1");
    return;
@@ -526,7 +497,9 @@ void BqrVscCompleteCallback(bluetooth::hci::CommandCompleteView complete) {
}

void ConfigBqrA2dpScoThreshold() {
  uint8_t param[20] = {0};
  uint8_t sub_opcode = 0x16;
  uint8_t* p_param = param;
  uint16_t a2dp_choppy_threshold = 0;
  uint16_t sco_choppy_threshold = 0;

@@ -539,28 +512,26 @@ void ConfigBqrA2dpScoThreshold() {
  log::warn("a2dp_choppy_threshold: {}, sco_choppy_threshold: {}",
            a2dp_choppy_threshold, sco_choppy_threshold);

  auto payload = std::make_unique<packet::RawBuilder>();
  payload->AddOctets1(sub_opcode);
  UINT8_TO_STREAM(p_param, sub_opcode);

  // A2dp glitch ID
  payload->AddOctets1(QUALITY_REPORT_ID_A2DP_AUDIO_CHOPPY);
  UINT8_TO_STREAM(p_param, QUALITY_REPORT_ID_A2DP_AUDIO_CHOPPY);
  // A2dp glitch config data length
  payload->AddOctets1(2);
  UINT8_TO_STREAM(p_param, 2);
  // A2dp glitch threshold
  payload->AddOctets2(a2dp_choppy_threshold == 0 ? 1 : a2dp_choppy_threshold);
  UINT16_TO_STREAM(p_param,
                   a2dp_choppy_threshold == 0 ? 1 : a2dp_choppy_threshold);

  // Sco glitch ID
  payload->AddOctets1(QUALITY_REPORT_ID_SCO_VOICE_CHOPPY);
  UINT8_TO_STREAM(p_param, QUALITY_REPORT_ID_SCO_VOICE_CHOPPY);
  // Sco glitch config data length
  payload->AddOctets1(2);
  UINT8_TO_STREAM(p_param, 2);
  // Sco glitch threshold
  payload->AddOctets2(sco_choppy_threshold == 0 ? 1 : sco_choppy_threshold);
  UINT16_TO_STREAM(p_param,
                   sco_choppy_threshold == 0 ? 1 : sco_choppy_threshold);

  shim::GetHciLayer()->EnqueueCommand(
      hci::CommandBuilder::Create(
          static_cast<bluetooth::hci::OpCode>(HCI_VS_HOST_LOG_OPCODE),
          std::move(payload)),
      to_bind_->BindOnce([](hci::CommandCompleteView) {}));
  BTM_VendorSpecificCommand(HCI_VS_HOST_LOG_OPCODE, p_param - param, param,
                            NULL);
}

static tBTM_STATUS BTM_BT_Quality_Report_VSE_Register(
@@ -1031,14 +1002,14 @@ tBTM_STATUS BTM_BT_Quality_Report_VSE_Register(
 *
 ******************************************************************************/
void btm_vendor_specific_evt(const uint8_t* p, uint8_t evt_len) {
  uint8_t quality_report_id = *p;
  uint8_t sub_event_code = HCI_VSE_SUBCODE_BQR_SUB_EVT;
  uint8_t bqr_parameter_length = evt_len;
  const uint8_t* p_bqr_event = p;

  log::verbose("BTM Event: Vendor Specific event from controller");

  // The stream currently points to the BQR sub-event parameters
  switch (quality_report_id) {
  switch (sub_event_code) {
    case bluetooth::bqr::QUALITY_REPORT_ID_LMP_LL_MESSAGE_TRACE:
      if (bqr_parameter_length >= bluetooth::bqr::kLogDumpParamTotalLen) {
        bluetooth::bqr::DumpLmpLlMessage(bqr_parameter_length, p_bqr_event);
@@ -1057,15 +1028,17 @@ void btm_vendor_specific_evt(const uint8_t* p, uint8_t evt_len) {
      break;

    default:
      log::info("Unhandled BQR subevent 0x{:02x}", quality_report_id);
      log::info("Unhandled BQR subevent 0x{:02x}", sub_event_code);
  }

  uint8_t i;
  std::vector<uint8_t> reconstructed_event;
  reconstructed_event.reserve(4 + bqr_parameter_length);
  reconstructed_event.push_back(HCI_VSE_SUBCODE_BQR_SUB_EVT);
  reconstructed_event[0] = HCI_VENDOR_SPECIFIC_EVT;
  reconstructed_event[1] = 3 + bqr_parameter_length;  // event size
  reconstructed_event[2] = HCI_VSE_SUBCODE_BQR_SUB_EVT;
  for (i = 0; i < bqr_parameter_length; i++) {
    reconstructed_event.push_back(p_bqr_event[i]);
    reconstructed_event.push_back(p[i]);
  }

  for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
@@ -1075,32 +1048,5 @@ void btm_vendor_specific_evt(const uint8_t* p, uint8_t evt_len) {
  }
}

static void vendor_specific_event_callback(
    bluetooth::hci::VendorSpecificEventView vendor_specific_event_view) {
  auto bqr =
      bluetooth::hci::BqrEventView::CreateOptional(vendor_specific_event_view);
  if (!bqr) {
    return;
  }
  auto payload = vendor_specific_event_view.GetPayload();
  std::vector<uint8_t> bytes{payload.begin(), payload.end()};
  btm_vendor_specific_evt(bytes.data(), bytes.size());
}

void register_vse() {
  bluetooth::shim::GetVendorSpecificEventManager()->RegisterEventHandler(
      bluetooth::hci::VseSubeventCode::BQR_EVENT,
      to_bind_->Bind(vendor_specific_event_callback));
}

void unregister_vse() {
  bluetooth::shim::GetVendorSpecificEventManager()->UnregisterEventHandler(
      hci::VseSubeventCode::BQR_EVENT);
}

namespace testing {
void set_lmp_trace_log_fd(int fd) { LmpLlMessageTraceLogFd = fd; }
}  // namespace testing

}  // namespace bqr
}  // namespace bluetooth
+2 −2
Original line number Diff line number Diff line
@@ -2167,7 +2167,7 @@ void BTIF_dm_enable() {
  ** and bonded_devices_info_cb
  */
  btif_storage_load_bonded_devices();
  bluetooth::bqr::EnableBtQualityReport(get_main());
  bluetooth::bqr::EnableBtQualityReport(true);
  btif_enable_bluetooth_evt();
}

@@ -2184,7 +2184,7 @@ void BTIF_dm_disable() {
      btif_in_execute_service_request(i, false);
    }
  }
  bluetooth::bqr::EnableBtQualityReport(nullptr);
  bluetooth::bqr::EnableBtQualityReport(false);
  log::info("Stack device manager shutdown finished");
  future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
}
+1 −367

File changed.

Preview size limit exceeded, changes collapsed.