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 #pragma once
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/metric_id_api.h"
23 #include "types/raw_address.h"
24 
25 void log_a2dp_audio_underrun_event(const RawAddress& address,
26                                    uint64_t encoding_interval_millis,
27                                    int num_missing_pcm_bytes);
28 
29 void log_a2dp_audio_overrun_event(const RawAddress& address,
30                                   uint64_t encoding_interval_millis,
31                                   int num_dropped_buffers,
32                                   int num_dropped_encoded_frames,
33                                   int num_dropped_encoded_bytes);
34 
35 void log_a2dp_playback_event(const RawAddress& address, int playback_state,
36                              int audio_coding_mode);
37 
38 void log_a2dp_session_metrics_event(
39     const RawAddress& address, int64_t audio_duration_ms,
40     int media_timer_min_ms, int media_timer_max_ms, int media_timer_avg_ms,
41     int total_scheduling_count, int buffer_overruns_max_count,
42     int buffer_overruns_total, float buffer_underruns_average,
43     int buffer_underruns_count, int64_t codec_index, bool is_a2dp_offload);
44 
45 void log_read_rssi_result(const RawAddress& address, uint16_t handle,
46                           uint32_t cmd_status, int8_t rssi);
47 
48 void log_read_failed_contact_counter_result(const RawAddress& address,
49                                             uint16_t handle,
50                                             uint32_t cmd_status,
51                                             int32_t failed_contact_counter);
52 
53 void log_read_tx_power_level_result(const RawAddress& address, uint16_t handle,
54                                     uint32_t cmd_status,
55                                     int32_t transmit_power_level);
56 
57 void log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum key,
58                               int64_t value);
59 
60 void log_socket_connection_state(
61     const RawAddress& address, int port, int type,
62     android::bluetooth::SocketConnectionstateEnum connection_state,
63     int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
64     android::bluetooth::SocketRoleEnum socket_role);
65 
66 bool init_metric_id_allocator(
67     const std::unordered_map<RawAddress, int>& paired_device_map,
68     bluetooth::shim::CallbackLegacy save_id_callback,
69     bluetooth::shim::CallbackLegacy forget_device_callback);
70 
71 bool close_metric_id_allocator();
72 
73 int allocate_metric_id_from_metric_id_allocator(const RawAddress&);
74 
75 int save_metric_id_from_metric_id_allocator(const RawAddress&);
76 
77 void forget_device_from_metric_id_allocator(const RawAddress&);
78 
79 bool is_valid_id_from_metric_id_allocator(const int id);