1 /*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
18 #include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
19
20 #include "btif/include/btif_metrics_logging.h"
21 #include "common/metric_id_allocator.h"
22 #include "common/metrics.h"
23 #include "main/shim/metrics_api.h"
24 #include "main/shim/shim.h"
25 #include "types/raw_address.h"
26
log_a2dp_audio_underrun_event(const RawAddress & address,uint64_t encoding_interval_millis,int num_missing_pcm_bytes)27 void log_a2dp_audio_underrun_event(const RawAddress& address,
28 uint64_t encoding_interval_millis,
29 int num_missing_pcm_bytes) {
30 bluetooth::shim::LogMetricA2dpAudioUnderrunEvent(
31 address, encoding_interval_millis, num_missing_pcm_bytes);
32 }
33
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)34 void log_a2dp_audio_overrun_event(const RawAddress& address,
35 uint64_t encoding_interval_millis,
36 int num_dropped_buffers,
37 int num_dropped_encoded_frames,
38 int num_dropped_encoded_bytes) {
39 bluetooth::shim::LogMetricA2dpAudioOverrunEvent(
40 address, encoding_interval_millis, num_dropped_buffers,
41 num_dropped_encoded_frames, num_dropped_encoded_bytes);
42 }
43
log_a2dp_playback_event(const RawAddress & address,int playback_state,int audio_coding_mode)44 void log_a2dp_playback_event(const RawAddress& address, int playback_state,
45 int audio_coding_mode) {
46 bluetooth::shim::LogMetricA2dpPlaybackEvent(address, playback_state,
47 audio_coding_mode);
48 }
49
log_read_rssi_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int8_t rssi)50 void log_read_rssi_result(const RawAddress& address, uint16_t handle,
51 uint32_t cmd_status, int8_t rssi) {
52 bluetooth::shim::LogMetricReadRssiResult(address, handle, cmd_status, rssi);
53 }
54
log_read_failed_contact_counter_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int32_t failed_contact_counter)55 void log_read_failed_contact_counter_result(const RawAddress& address,
56 uint16_t handle,
57 uint32_t cmd_status,
58 int32_t failed_contact_counter) {
59 bluetooth::shim::LogMetricReadFailedContactCounterResult(
60 address, handle, cmd_status, failed_contact_counter);
61 }
62
log_read_tx_power_level_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int32_t transmit_power_level)63 void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle,
64 uint32_t cmd_status,
65 int32_t transmit_power_level) {
66 bluetooth::shim::LogMetricReadTxPowerLevelResult(address, handle, cmd_status,
67 transmit_power_level);
68 }
69
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)70 void log_socket_connection_state(
71 const RawAddress& address, int port, int type,
72 android::bluetooth::SocketConnectionstateEnum connection_state,
73 int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
74 android::bluetooth::SocketRoleEnum socket_role) {
75 bluetooth::shim::LogMetricSocketConnectionState(
76 address, port, type, connection_state, tx_bytes, rx_bytes, uid,
77 server_port, socket_role);
78 }
79
log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key,int64_t value)80 void log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key,
81 int64_t value) {
82 bluetooth::shim::CountCounterMetrics(key, value);
83 }
84
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)85 bool init_metric_id_allocator(
86 const std::unordered_map<RawAddress, int>& paired_device_map,
87 bluetooth::shim::CallbackLegacy save_device_callback,
88 bluetooth::shim::CallbackLegacy forget_device_callback) {
89 return bluetooth::shim::InitMetricIdAllocator(
90 paired_device_map, std::move(save_device_callback),
91 std::move(forget_device_callback));
92 }
93
close_metric_id_allocator()94 bool close_metric_id_allocator() {
95 return bluetooth::shim::CloseMetricIdAllocator();
96 }
97
allocate_metric_id_from_metric_id_allocator(const RawAddress & address)98 int allocate_metric_id_from_metric_id_allocator(const RawAddress& address) {
99 return bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
100 }
101
save_metric_id_from_metric_id_allocator(const RawAddress & address)102 int save_metric_id_from_metric_id_allocator(const RawAddress& address) {
103 return bluetooth::shim::SaveDeviceOnMetricIdAllocator(address);
104 }
105
forget_device_from_metric_id_allocator(const RawAddress & address)106 void forget_device_from_metric_id_allocator(const RawAddress& address) {
107 bluetooth::shim::ForgetDeviceFromMetricIdAllocator(address);
108 }
109
is_valid_id_from_metric_id_allocator(const int id)110 bool is_valid_id_from_metric_id_allocator(const int id) {
111 return bluetooth::shim::IsValidIdFromMetricIdAllocator(id);
112 }
113