summaryrefslogtreecommitdiff
path: root/system/btif/src/btif_metrics_logging.cc
blob: 8af5033a03b0ee09c7a7fd66236584f9a97bc50a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * 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.
 */

#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>

#include "btif/include/btif_metrics_logging.h"
#include "common/metric_id_allocator.h"
#include "common/metrics.h"
#include "main/shim/metrics_api.h"
#include "main/shim/shim.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) {
  bluetooth::shim::LogMetricA2dpAudioUnderrunEvent(
      address, encoding_interval_millis, 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) {
  bluetooth::shim::LogMetricA2dpAudioOverrunEvent(
      address, encoding_interval_millis, num_dropped_buffers,
      num_dropped_encoded_frames, num_dropped_encoded_bytes);
}

void log_a2dp_playback_event(const RawAddress& address, int playback_state,
                             int audio_coding_mode) {
    bluetooth::shim::LogMetricA2dpPlaybackEvent(address, playback_state,
                                                audio_coding_mode);
}

void log_read_rssi_result(const RawAddress& address, uint16_t handle,
                          uint32_t cmd_status, int8_t rssi) {
  bluetooth::shim::LogMetricReadRssiResult(address, handle, cmd_status, rssi);
}

void log_read_failed_contact_counter_result(const RawAddress& address,
                                            uint16_t handle,
                                            uint32_t cmd_status,
                                            int32_t failed_contact_counter) {
  bluetooth::shim::LogMetricReadFailedContactCounterResult(
      address, handle, cmd_status, 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) {
  bluetooth::shim::LogMetricReadTxPowerLevelResult(address, handle, cmd_status,
                                                   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) {
  bluetooth::shim::LogMetricSocketConnectionState(
      address, port, type, connection_state, tx_bytes, rx_bytes, uid,
      server_port, socket_role);
}

void log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key,
                              int64_t value) {
  bluetooth::shim::CountCounterMetrics(key, value);
}

bool init_metric_id_allocator(
    const std::unordered_map<RawAddress, int>& paired_device_map,
    bluetooth::shim::CallbackLegacy save_device_callback,
    bluetooth::shim::CallbackLegacy forget_device_callback) {
  return bluetooth::shim::InitMetricIdAllocator(
      paired_device_map, std::move(save_device_callback),
      std::move(forget_device_callback));
}

bool close_metric_id_allocator() {
  return bluetooth::shim::CloseMetricIdAllocator();
}

int allocate_metric_id_from_metric_id_allocator(const RawAddress& address) {
  return bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
}

int save_metric_id_from_metric_id_allocator(const RawAddress& address) {
  return bluetooth::shim::SaveDeviceOnMetricIdAllocator(address);
}

void forget_device_from_metric_id_allocator(const RawAddress& address) {
  bluetooth::shim::ForgetDeviceFromMetricIdAllocator(address);
}

bool is_valid_id_from_metric_id_allocator(const int id) {
  return bluetooth::shim::IsValidIdFromMetricIdAllocator(id);
}