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 "btif/include/btif_metrics_logging.h"
18
19 #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
20 #include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
21
22 #include "main/shim/metrics_api.h"
23 #include "types/raw_address.h"
24
log_a2dp_audio_underrun_event(const RawAddress & address,uint64_t encoding_interval_millis,int num_missing_pcm_bytes)25 void log_a2dp_audio_underrun_event(const RawAddress& address, uint64_t encoding_interval_millis,
26 int num_missing_pcm_bytes) {
27 bluetooth::shim::LogMetricA2dpAudioUnderrunEvent(address, encoding_interval_millis,
28 num_missing_pcm_bytes);
29 }
30
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)31 void log_a2dp_audio_overrun_event(const RawAddress& address, uint64_t encoding_interval_millis,
32 int num_dropped_buffers, int num_dropped_encoded_frames,
33 int num_dropped_encoded_bytes) {
34 bluetooth::shim::LogMetricA2dpAudioOverrunEvent(address, encoding_interval_millis,
35 num_dropped_buffers, num_dropped_encoded_frames,
36 num_dropped_encoded_bytes);
37 }
38
log_a2dp_playback_event(const RawAddress & address,int playback_state,int audio_coding_mode)39 void log_a2dp_playback_event(const RawAddress& address, int playback_state, int audio_coding_mode) {
40 bluetooth::shim::LogMetricA2dpPlaybackEvent(address, playback_state, audio_coding_mode);
41 }
42
log_a2dp_session_metrics_event(const RawAddress & address,int64_t audio_duration_ms,int media_timer_min_ms,int media_timer_max_ms,int media_timer_avg_ms,int total_scheduling_count,int buffer_overruns_max_count,int buffer_overruns_total,float buffer_underruns_average,int buffer_underruns_count,int64_t codec_index,bool is_a2dp_offload)43 void log_a2dp_session_metrics_event(const RawAddress& address, int64_t audio_duration_ms,
44 int media_timer_min_ms, int media_timer_max_ms,
45 int media_timer_avg_ms, int total_scheduling_count,
46 int buffer_overruns_max_count, int buffer_overruns_total,
47 float buffer_underruns_average, int buffer_underruns_count,
48 int64_t codec_index, bool is_a2dp_offload) {
49 bluetooth::shim::LogMetricA2dpSessionMetricsEvent(
50 address, audio_duration_ms, media_timer_min_ms, media_timer_max_ms, media_timer_avg_ms,
51 total_scheduling_count, buffer_overruns_max_count, buffer_overruns_total,
52 buffer_underruns_average, buffer_underruns_count, codec_index, is_a2dp_offload);
53 }
54
log_read_rssi_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int8_t rssi)55 void log_read_rssi_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
56 int8_t rssi) {
57 bluetooth::shim::LogMetricReadRssiResult(address, handle, cmd_status, rssi);
58 }
59
log_read_failed_contact_counter_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int32_t failed_contact_counter)60 void log_read_failed_contact_counter_result(const RawAddress& address, uint16_t handle,
61 uint32_t cmd_status, int32_t failed_contact_counter) {
62 bluetooth::shim::LogMetricReadFailedContactCounterResult(address, handle, cmd_status,
63 failed_contact_counter);
64 }
65
log_read_tx_power_level_result(const RawAddress & address,uint16_t handle,uint32_t cmd_status,int32_t transmit_power_level)66 void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
67 int32_t transmit_power_level) {
68 bluetooth::shim::LogMetricReadTxPowerLevelResult(address, handle, cmd_status,
69 transmit_power_level);
70 }
71
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)72 void log_socket_connection_state(const RawAddress& address, int port, int type,
73 android::bluetooth::SocketConnectionstateEnum connection_state,
74 int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
75 android::bluetooth::SocketRoleEnum socket_role) {
76 bluetooth::shim::LogMetricSocketConnectionState(address, port, type, connection_state, tx_bytes,
77 rx_bytes, uid, 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, int64_t value) {
81 bluetooth::shim::CountCounterMetrics(key, value);
82 }
83
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)84 bool init_metric_id_allocator(const std::unordered_map<RawAddress, int>& paired_device_map,
85 bluetooth::shim::CallbackLegacy save_device_callback,
86 bluetooth::shim::CallbackLegacy forget_device_callback) {
87 return bluetooth::shim::InitMetricIdAllocator(paired_device_map, std::move(save_device_callback),
88 std::move(forget_device_callback));
89 }
90
close_metric_id_allocator()91 bool close_metric_id_allocator() { return bluetooth::shim::CloseMetricIdAllocator(); }
92
allocate_metric_id_from_metric_id_allocator(const RawAddress & address)93 int allocate_metric_id_from_metric_id_allocator(const RawAddress& address) {
94 return bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
95 }
96
save_metric_id_from_metric_id_allocator(const RawAddress & address)97 int save_metric_id_from_metric_id_allocator(const RawAddress& address) {
98 return bluetooth::shim::SaveDeviceOnMetricIdAllocator(address);
99 }
100
forget_device_from_metric_id_allocator(const RawAddress & address)101 void forget_device_from_metric_id_allocator(const RawAddress& address) {
102 bluetooth::shim::ForgetDeviceFromMetricIdAllocator(address);
103 }
104
is_valid_id_from_metric_id_allocator(const int id)105 bool is_valid_id_from_metric_id_allocator(const int id) {
106 return bluetooth::shim::IsValidIdFromMetricIdAllocator(id);
107 }
108