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

Commit efc79c85 authored by Chris Manton's avatar Chris Manton
Browse files

BTMLogHistory: Add HID device open/close

Toward loggable code

Bug: 163134718
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I2201febbce720a2534800e7e9c69d31b0f8b0ced
parent ca04d3d1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ cc_test {
        "test/common/mock_stack_btm_sec.cc",
        "test/common/mock_stack_crypto_toolbox_aes_cmac.cc",
        "test/common/mock_stack_gap_ble.cc",
        "test/common/mock_stack_btm_main.cc",
        "test/common/mock_stack_gatt.cc",
        "test/common/mock_stack_gatt_attr.cc",
        "test/common/mock_stack_gatt_connection_manager.cc",
+29 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "main/shim/dumpsys.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"  // UNUSED_ATTR
#include "stack/include/hiddefs.h"
#include "stack/include/hidh_api.h"
#include "types/raw_address.h"

@@ -45,6 +46,12 @@
 *  Constants
 ****************************************************************************/

namespace {

constexpr char kBtmLogTag[] = "HIDH";

}

/*****************************************************************************
 *  Local Function prototypes
 ****************************************************************************/
@@ -153,6 +160,8 @@ void bta_hh_api_disable(void) {
 *
 ******************************************************************************/
void bta_hh_disc_cmpl(void) {
  LOG_DEBUG("Disconnect complete");

  HID_HostDeregister();
  bta_hh_le_deregister();
  tBTA_HH_STATUS status = BTA_HH_OK;
@@ -484,7 +493,11 @@ void bta_hh_api_disc_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  if (p_cb->is_le_device) {
    LOG_DEBUG("Host initiating close to le device:%s",
              PRIVATE_ADDRESS(p_cb->addr));

    bta_hh_le_api_disc_act(p_cb);
    BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                   base::StringPrintf("le local initiated"));

  } else {
    /* found an active connection */
    const uint8_t hid_handle =
@@ -501,6 +514,9 @@ void bta_hh_api_disc_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
      };
      (*bta_hh_cb.p_cback)(BTA_HH_CLOSE_EVT, &bta_hh);
    }
    BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                   base::StringPrintf("classic local reason %s",
                                      hid_status_text(status).c_str()));
  }
}

@@ -534,6 +550,11 @@ void bta_hh_open_cmpl_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  conn.le_hid = p_cb->is_le_device;
  conn.scps_supported = p_cb->scps_supported;

  BTM_LogHistory(kBtmLogTag, p_cb->addr, "Opened",
                 base::StringPrintf(
                     "%s initiator:%s", (p_cb->is_le_device) ? "le" : "classic",
                     (p_cb->incoming_conn) ? "local" : "remote"));

  if (!p_cb->is_le_device)
  {
    /* inform role manager */
@@ -826,6 +847,9 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  tBTA_HH_CBDATA disc_dat = {BTA_HH_OK, 0};
  uint32_t reason = p_data->hid_cback.data; /* Reason for closing (32-bit) */

  // TODO Fix use proper types
  tHID_STATUS hid_status = static_cast<tHID_STATUS>(reason);

  /* if HID_HDEV_EVT_VC_UNPLUG was received, report BTA_HH_VC_UNPLUG_EVT */
  uint16_t event = p_cb->vp ? BTA_HH_VC_UNPLUG_EVT : BTA_HH_CLOSE_EVT;

@@ -857,6 +881,11 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  }
  /* otherwise report CLOSE/VC_UNPLUG event */
  else {
    BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                   base::StringPrintf("%s reason %s",
                                      (p_cb->is_le_device) ? "le" : "classic",
                                      hid_status_text(hid_status).c_str()));

    /* finaliza device driver */
    bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
    /* inform role manager */
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

/*
 * Generated mock file from original source file
 *   Functions generated:7
 */

#include <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;

#include <memory>
#include <string>
#include "bt_target.h"
#include "bt_types.h"
#include "main/shim/dumpsys.h"
#include "stack/btm/btm_int_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack_config.h"

#ifndef UNUSED_ATTR
#define UNUSED_ATTR
#endif

void BTM_LogHistory(const std::string& tag, const RawAddress& bd_addr,
                    const std::string& msg) {
  mock_function_count_map[__func__]++;
}
void BTM_LogHistory(const std::string& tag, const RawAddress& bd_addr,
                    const std::string& msg, const std::string& extra) {
  mock_function_count_map[__func__]++;
}
void BTM_LogHistory(const std::string& tag, const tBLE_BD_ADDR& ble_bd_addr,
                    const std::string& msg) {
  mock_function_count_map[__func__]++;
}
void BTM_LogHistory(const std::string& tag, const tBLE_BD_ADDR& ble_bd_addr,
                    const std::string& msg, const std::string& extra) {
  mock_function_count_map[__func__]++;
}
void btm_free(void) { mock_function_count_map[__func__]++; }
void btm_init(void) { mock_function_count_map[__func__]++; }