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

Commit 534bf24c authored by Chen Chen's avatar Chen Chen
Browse files

GD metrics: Add shim layers for metrics in GD

1) Add shim layer for MetricIdManager
2) Add shim layer for metric logging functions who take metric id
3) reference the 2 shim layers at btif/, main/shim and stack/

Bug: 181819141
Test: atest bluetooth_test_gd
Manual test by printing log at legacy stack and gd stack to make sure
function calls, parameters and callbacks are fowarded correctly

Change-Id: Ic5ee1ef95a7e4d7683de328ac78894986ba5011e
parent 2aebbb14
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ cc_library_static {
        "src/btif_hh.cc",
        "src/btif_hd.cc",
        "src/btif_le_audio.cc",
        "src/btif_metrics_logging.cc",
        "src/btif_pan.cc",
        "src/btif_profile_queue.cc",
        "src/btif_rc.cc",
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ static_library("btif") {
    "src/btif_hh.cc",
    "src/btif_keystore.cc",
    "src/btif_le_audio.cc",
    "src/btif_metrics_logging.cc",
    "src/btif_pan.cc",
    "src/btif_profile_queue.cc",
    "src/btif_rc.cc",
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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 <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>

#include "main/shim/metric_id_api.h"
#include "types/raw_address.h"

void log_a2dp_audio_underrun_event(const RawAddress& address,
                                   uint64_t encoding_interval_millis,
                                   int num_missing_pcm_bytes);

void log_a2dp_audio_overrun_event(const RawAddress& address,
                                  uint64_t encoding_interval_millis,
                                  int num_dropped_buffers,
                                  int num_dropped_encoded_frames,
                                  int num_dropped_encoded_bytes);

void log_read_rssi_result(const RawAddress& address, uint16_t handle,
                          uint32_t cmd_status, int8_t rssi);

void log_read_failed_contact_counter_result(const RawAddress& address,
                                            uint16_t handle,
                                            uint32_t cmd_status,
                                            int32_t failed_contact_counter);

void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle,
                                    uint32_t cmd_status,
                                    int32_t transmit_power_level);

void log_socket_connection_state(
    const RawAddress& address, int port, int type,
    android::bluetooth::SocketConnectionstateEnum connection_state,
    int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
    android::bluetooth::SocketRoleEnum socket_role);

bool init_metric_id_allocator(
    const std::unordered_map<RawAddress, int>& paired_device_map,
    bluetooth::shim::CallbackLegacy save_id_callback,
    bluetooth::shim::CallbackLegacy forget_device_callback);

bool close_metric_id_allocator();

int allocate_metric_id_from_metric_id_allocator(const RawAddress&);

int save_metric_id_from_metric_id_allocator(const RawAddress&);

void forget_device_from_metric_id_allocator(const RawAddress&);

bool is_valid_id_from_metric_id_allocator(const int id);
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@
#include "btif_debug_conn.h"
#include "btif_hf.h"
#include "btif_keystore.h"
#include "btif_metrics_logging.h"
#include "btif_storage.h"
#include "btsnoop.h"
#include "btsnoop_mem.h"
@@ -547,8 +548,7 @@ static std::string obfuscate_address(const RawAddress& address) {
}

static int get_metric_id(const RawAddress& address) {
  return bluetooth::common::MetricIdAllocator::GetInstance().AllocateId(
      address);
  return allocate_metric_id_from_metric_id_allocator(address);
}

static int set_dynamic_audio_buffer_size(int codec, int size) {
+16 −14
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "btif_a2dp_source.h"
#include "btif_av.h"
#include "btif_av_co.h"
#include "btif_metrics_logging.h"
#include "btif_util.h"
#include "common/message_loop_thread.h"
#include "common/metrics.h"
@@ -917,8 +918,8 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
    btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
    btif_a2dp_source_cb.stats.media_read_last_underflow_us =
        bluetooth::common::time_get_os_boottime_us();
    bluetooth::common::LogA2dpAudioUnderrunEvent(
        btif_av_source_active_peer(), btif_a2dp_source_cb.encoder_interval_ms,
    log_a2dp_audio_underrun_event(btif_av_source_active_peer(),
                                  btif_a2dp_source_cb.encoder_interval_ms,
                                  len - bytes_read);
  }

@@ -977,9 +978,9 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
        osi_free(p_data);
      }
    }
    bluetooth::common::LogA2dpAudioOverrunEvent(
        btif_av_source_active_peer(), drop_n,
        btif_a2dp_source_cb.encoder_interval_ms, num_dropped_encoded_frames,
    log_a2dp_audio_overrun_event(btif_av_source_active_peer(), drop_n,
                                 btif_a2dp_source_cb.encoder_interval_ms,
                                 num_dropped_encoded_frames,
                                 num_dropped_encoded_bytes);

    // Request additional debug info if we had to flush buffers
@@ -1333,8 +1334,9 @@ static void btm_read_rssi_cb(void* data) {
              result->status);
    return;
  }
  bluetooth::common::LogReadRssiResult(
      result->rem_bda, bluetooth::common::kUnknownConnectionHandle,

  log_read_rssi_result(result->rem_bda,
                       bluetooth::common::kUnknownConnectionHandle,
                       result->hci_status, result->rssi);

  LOG_WARN("%s: device: %s, rssi: %d", __func__,
@@ -1354,7 +1356,7 @@ static void btm_read_failed_contact_counter_cb(void* data) {
              result->status);
    return;
  }
  bluetooth::common::LogReadFailedContactCounterResult(
  log_read_failed_contact_counter_result(
      result->rem_bda, bluetooth::common::kUnknownConnectionHandle,
      result->hci_status, result->failed_contact_counter);

@@ -1374,8 +1376,8 @@ static void btm_read_tx_power_cb(void* data) {
              result->status);
    return;
  }
  bluetooth::common::LogReadTxPowerLevelResult(
      result->rem_bda, bluetooth::common::kUnknownConnectionHandle,
  log_read_tx_power_level_result(result->rem_bda,
                                 bluetooth::common::kUnknownConnectionHandle,
                                 result->hci_status, result->tx_power);

  LOG_WARN("%s: device: %s, Tx Power: %d", __func__,
Loading