1 /******************************************************************************
2  *
3  *  Copyright 2021 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #define LOG_TAG "BluetoothMetrics"
20 
21 #include "os/metrics.h"
22 
23 #include <bluetooth/log.h>
24 #include <statslog_bt.h>
25 
26 #include "common/audit_log.h"
27 #include "common/metric_id_manager.h"
28 #include "common/strings.h"
29 #include "hci/hci_packets.h"
30 #include "metrics/metrics_state.h"
31 #include "os/log.h"
32 
33 namespace fmt {
34 template <>
35 struct formatter<android::bluetooth::DirectionEnum>
36     : enum_formatter<android::bluetooth::DirectionEnum> {};
37 template <>
38 struct formatter<android::bluetooth::SocketConnectionstateEnum>
39     : enum_formatter<android::bluetooth::SocketConnectionstateEnum> {};
40 template <>
41 struct formatter<android::bluetooth::SocketRoleEnum>
42     : enum_formatter<android::bluetooth::SocketRoleEnum> {};
43 template <>
44 struct formatter<android::bluetooth::DeviceInfoSrcEnum>
45     : enum_formatter<android::bluetooth::DeviceInfoSrcEnum> {};
46 template <>
47 struct formatter<android::bluetooth::AddressTypeEnum>
48     : enum_formatter<android::bluetooth::AddressTypeEnum> {};
49 }  // namespace fmt
50 
51 namespace bluetooth {
52 namespace os {
53 
54 using bluetooth::common::MetricIdManager;
55 using bluetooth::hci::Address;
56 using bluetooth::hci::ErrorCode;
57 using bluetooth::hci::EventCode;
58 
59 /**
60  * nullptr and size 0 represent missing value for obfuscated_id
61  */
62 static const BytesField byteField(nullptr, 0);
63 
LogMetricLinkLayerConnectionEvent(const Address * address,uint32_t connection_handle,android::bluetooth::DirectionEnum direction,uint16_t link_type,uint32_t hci_cmd,uint16_t hci_event,uint16_t hci_ble_event,uint16_t cmd_status,uint16_t reason_code)64 void LogMetricLinkLayerConnectionEvent(
65     const Address* address,
66     uint32_t connection_handle,
67     android::bluetooth::DirectionEnum direction,
68     uint16_t link_type,
69     uint32_t hci_cmd,
70     uint16_t hci_event,
71     uint16_t hci_ble_event,
72     uint16_t cmd_status,
73     uint16_t reason_code) {
74   int metric_id = 0;
75   if (address != nullptr) {
76     metric_id = MetricIdManager::GetInstance().AllocateId(*address);
77   }
78   int ret = stats_write(
79       BLUETOOTH_LINK_LAYER_CONNECTION_EVENT,
80       byteField,
81       connection_handle,
82       direction,
83       link_type,
84       hci_cmd,
85       hci_event,
86       hci_ble_event,
87       cmd_status,
88       reason_code,
89       metric_id);
90   if (ret < 0) {
91     log::warn(
92         "Failed to log status {} , reason {}, from cmd {}, event {},  ble_event {}, for {}, handle "
93         "{}, type {}, error {}",
94         common::ToHexString(cmd_status),
95         common::ToHexString(reason_code),
96         common::ToHexString(hci_cmd),
97         common::ToHexString(hci_event),
98         common::ToHexString(hci_ble_event),
99         address ? ADDRESS_TO_LOGGABLE_CSTR(*address) : "(NULL)",
100         connection_handle,
101         common::ToHexString(link_type),
102         ret);
103   }
104 }
105 
LogMetricHciTimeoutEvent(uint32_t hci_cmd)106 void LogMetricHciTimeoutEvent(uint32_t hci_cmd) {
107   int ret = stats_write(BLUETOOTH_HCI_TIMEOUT_REPORTED, static_cast<int64_t>(hci_cmd));
108   if (ret < 0) {
109     log::warn("Failed for opcode {}, error {}", common::ToHexString(hci_cmd), ret);
110   }
111 }
112 
LogMetricRemoteVersionInfo(uint16_t handle,uint8_t status,uint8_t version,uint16_t manufacturer_name,uint16_t subversion)113 void LogMetricRemoteVersionInfo(
114     uint16_t handle, uint8_t status, uint8_t version, uint16_t manufacturer_name, uint16_t subversion) {
115   int ret = stats_write(BLUETOOTH_REMOTE_VERSION_INFO_REPORTED, handle, status, version, manufacturer_name, subversion);
116   if (ret < 0) {
117     log::warn(
118         "Failed for handle {}, status {}, version {}, manufacturer_name {}, subversion {}, error "
119         "{}",
120         handle,
121         common::ToHexString(status),
122         common::ToHexString(version),
123         common::ToHexString(manufacturer_name),
124         common::ToHexString(subversion),
125         ret);
126   }
127 }
128 
LogMetricA2dpAudioUnderrunEvent(const Address & address,uint64_t encoding_interval_millis,int num_missing_pcm_bytes)129 void LogMetricA2dpAudioUnderrunEvent(
130     const Address& address, uint64_t encoding_interval_millis, int num_missing_pcm_bytes) {
131   int metric_id = 0;
132   if (!address.IsEmpty()) {
133     metric_id = MetricIdManager::GetInstance().AllocateId(address);
134   }
135   int64_t encoding_interval_nanos = encoding_interval_millis * 1000000;
136   int ret = stats_write(
137       BLUETOOTH_A2DP_AUDIO_UNDERRUN_REPORTED, byteField, encoding_interval_nanos, num_missing_pcm_bytes, metric_id);
138   if (ret < 0) {
139     log::warn(
140         "Failed for {}, encoding_interval_nanos {}, num_missing_pcm_bytes {}, error {}",
141         address,
142         encoding_interval_nanos,
143         num_missing_pcm_bytes,
144         ret);
145   }
146 }
147 
LogMetricA2dpAudioOverrunEvent(const Address & address,uint64_t encoding_interval_millis,int num_dropped_buffers,int num_dropped_encoded_frames,int num_dropped_encoded_bytes)148 void LogMetricA2dpAudioOverrunEvent(
149     const Address& address,
150     uint64_t encoding_interval_millis,
151     int num_dropped_buffers,
152     int num_dropped_encoded_frames,
153     int num_dropped_encoded_bytes) {
154   int metric_id = 0;
155   if (!address.IsEmpty()) {
156     metric_id = MetricIdManager::GetInstance().AllocateId(address);
157   }
158 
159   int64_t encoding_interval_nanos = encoding_interval_millis * 1000000;
160   int ret = stats_write(
161       BLUETOOTH_A2DP_AUDIO_OVERRUN_REPORTED,
162       byteField,
163       encoding_interval_nanos,
164       num_dropped_buffers,
165       num_dropped_encoded_frames,
166       num_dropped_encoded_bytes,
167       metric_id);
168   if (ret < 0) {
169     log::warn(
170         "Failed to log for {}, encoding_interval_nanos {}, num_dropped_buffers {}, "
171         "num_dropped_encoded_frames {}, num_dropped_encoded_bytes {}, error {}",
172         address,
173         encoding_interval_nanos,
174         num_dropped_buffers,
175         num_dropped_encoded_frames,
176         num_dropped_encoded_bytes,
177         ret);
178   }
179 }
180 
LogMetricA2dpPlaybackEvent(const Address & address,int playback_state,int audio_coding_mode)181 void LogMetricA2dpPlaybackEvent(const Address& address, int playback_state, int audio_coding_mode) {
182   int metric_id = 0;
183   if (!address.IsEmpty()) {
184     metric_id = MetricIdManager::GetInstance().AllocateId(address);
185   }
186 
187   int ret = stats_write(BLUETOOTH_A2DP_PLAYBACK_STATE_CHANGED, byteField, playback_state, audio_coding_mode, metric_id);
188   if (ret < 0) {
189     log::warn(
190         "Failed to log for {}, playback_state {}, audio_coding_mode {},error {}",
191         address,
192         playback_state,
193         audio_coding_mode,
194         ret);
195   }
196 }
197 
LogMetricA2dpSessionMetricsEvent(const hci::Address &,int64_t,int,int,int,int,int,int,float,int,int64_t,bool)198 void LogMetricA2dpSessionMetricsEvent(
199     const hci::Address& /* address */,
200     int64_t /* audio_duration_ms */,
201     int /* media_timer_min_ms */,
202     int /* media_timer_max_ms */,
203     int /* media_timer_avg_ms */,
204     int /* total_scheduling_count */,
205     int /* buffer_overruns_max_count */,
206     int /* buffer_overruns_total */,
207     float /* buffer_underruns_average */,
208     int /* buffer_underruns_count */,
209     int64_t /* codec_index */,
210     bool /* is_a2dp_offload */) {}
211 
LogMetricHfpPacketLossStats(const Address &,int,double,uint16_t)212 void LogMetricHfpPacketLossStats(
213     const Address& /* address */,
214     int /* num_decoded_frames */,
215     double /* packet_loss_ratio */,
216     uint16_t /* codec_type */) {}
217 
LogMetricMmcTranscodeRttStats(int,double,int,int)218 void LogMetricMmcTranscodeRttStats(
219     int /*maximum_rtt*/,
220     double /*mean_rtt*/,
221     int /*num_requests*/,
222     int /*codec_type*/) {}
223 
LogMetricReadRssiResult(const Address & address,uint16_t handle,uint32_t cmd_status,int8_t rssi)224 void LogMetricReadRssiResult(const Address& address, uint16_t handle, uint32_t cmd_status, int8_t rssi) {
225   int metric_id = 0;
226   if (!address.IsEmpty()) {
227     metric_id = MetricIdManager::GetInstance().AllocateId(address);
228   }
229   int ret = stats_write(BLUETOOTH_DEVICE_RSSI_REPORTED, byteField, handle, cmd_status, rssi, metric_id);
230   if (ret < 0) {
231     log::warn(
232         "Failed for {}, handle {}, status {}, rssi {} dBm, error {}",
233         address,
234         handle,
235         common::ToHexString(cmd_status),
236         rssi,
237         ret);
238   }
239 }
240 
LogMetricReadFailedContactCounterResult(const Address & address,uint16_t handle,uint32_t cmd_status,int32_t failed_contact_counter)241 void LogMetricReadFailedContactCounterResult(
242     const Address& address, uint16_t handle, uint32_t cmd_status, int32_t failed_contact_counter) {
243   int metric_id = 0;
244   if (!address.IsEmpty()) {
245     metric_id = MetricIdManager::GetInstance().AllocateId(address);
246   }
247   int ret = stats_write(
248       BLUETOOTH_DEVICE_FAILED_CONTACT_COUNTER_REPORTED,
249       byteField,
250       handle,
251       cmd_status,
252       failed_contact_counter,
253       metric_id);
254   if (ret < 0) {
255     log::warn(
256         "Failed for {}, handle {}, status {}, failed_contact_counter {} packets, error {}",
257         address,
258         handle,
259         common::ToHexString(cmd_status),
260         failed_contact_counter,
261         ret);
262   }
263 }
264 
LogMetricReadTxPowerLevelResult(const Address & address,uint16_t handle,uint32_t cmd_status,int32_t transmit_power_level)265 void LogMetricReadTxPowerLevelResult(
266     const Address& address, uint16_t handle, uint32_t cmd_status, int32_t transmit_power_level) {
267   int metric_id = 0;
268   if (!address.IsEmpty()) {
269     metric_id = MetricIdManager::GetInstance().AllocateId(address);
270   }
271   int ret = stats_write(
272       BLUETOOTH_DEVICE_TX_POWER_LEVEL_REPORTED, byteField, handle, cmd_status, transmit_power_level, metric_id);
273   if (ret < 0) {
274     log::warn(
275         "Failed for {}, handle {}, status {}, transmit_power_level {} packets, error {}",
276         address,
277         handle,
278         common::ToHexString(cmd_status),
279         transmit_power_level,
280         ret);
281   }
282 }
283 
LogMetricSmpPairingEvent(const Address & address,uint16_t smp_cmd,android::bluetooth::DirectionEnum direction,uint16_t smp_fail_reason)284 void LogMetricSmpPairingEvent(
285     const Address& address, uint16_t smp_cmd, android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason) {
286   int metric_id = 0;
287   if (!address.IsEmpty()) {
288     metric_id = MetricIdManager::GetInstance().AllocateId(address);
289   }
290   int ret =
291       stats_write(BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, byteField, smp_cmd, direction, smp_fail_reason, metric_id);
292   if (ret < 0) {
293     log::warn(
294         "Failed for {}, smp_cmd {}, direction {}, smp_fail_reason {}, error {}",
295         address,
296         common::ToHexString(smp_cmd),
297         direction,
298         common::ToHexString(smp_fail_reason),
299         ret);
300   }
301 }
302 
LogMetricClassicPairingEvent(const Address & address,uint16_t handle,uint32_t hci_cmd,uint16_t hci_event,uint16_t cmd_status,uint16_t reason_code,int64_t event_value)303 void LogMetricClassicPairingEvent(
304     const Address& address,
305     uint16_t handle,
306     uint32_t hci_cmd,
307     uint16_t hci_event,
308     uint16_t cmd_status,
309     uint16_t reason_code,
310     int64_t event_value) {
311   int metric_id = 0;
312   if (!address.IsEmpty()) {
313     metric_id = MetricIdManager::GetInstance().AllocateId(address);
314   }
315   int ret = stats_write(
316       BLUETOOTH_CLASSIC_PAIRING_EVENT_REPORTED,
317       byteField,
318       handle,
319       hci_cmd,
320       hci_event,
321       cmd_status,
322       reason_code,
323       event_value,
324       metric_id);
325   if (ret < 0) {
326     log::warn(
327         "Failed for {}, handle {}, hci_cmd {}, hci_event {}, cmd_status {}, reason {}, event_value "
328         "{}, error {}",
329         address,
330         handle,
331         common::ToHexString(hci_cmd),
332         common::ToHexString(hci_event),
333         common::ToHexString(cmd_status),
334         common::ToHexString(reason_code),
335         event_value,
336         ret);
337   }
338 
339   if (static_cast<EventCode>(hci_event) == EventCode::SIMPLE_PAIRING_COMPLETE) {
340     common::LogConnectionAdminAuditEvent("Pairing", address, static_cast<ErrorCode>(cmd_status));
341   }
342 }
343 
LogMetricSdpAttribute(const Address & address,uint16_t protocol_uuid,uint16_t attribute_id,size_t attribute_size,const char * attribute_value)344 void LogMetricSdpAttribute(
345     const Address& address,
346     uint16_t protocol_uuid,
347     uint16_t attribute_id,
348     size_t attribute_size,
349     const char* attribute_value) {
350   int metric_id = 0;
351   if (!address.IsEmpty()) {
352     metric_id = MetricIdManager::GetInstance().AllocateId(address);
353   }
354   BytesField attribute_field(attribute_value, attribute_size);
355   int ret =
356       stats_write(BLUETOOTH_SDP_ATTRIBUTE_REPORTED, byteField, protocol_uuid, attribute_id, attribute_field, metric_id);
357   if (ret < 0) {
358     log::warn(
359         "Failed for {}, protocol_uuid {}, attribute_id {}, error {}",
360         address,
361         common::ToHexString(protocol_uuid),
362         common::ToHexString(attribute_id),
363         ret);
364   }
365 }
366 
LogMetricSocketConnectionState(const Address & 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)367 void LogMetricSocketConnectionState(
368     const Address& address,
369     int port,
370     int type,
371     android::bluetooth::SocketConnectionstateEnum connection_state,
372     int64_t tx_bytes,
373     int64_t rx_bytes,
374     int uid,
375     int server_port,
376     android::bluetooth::SocketRoleEnum socket_role) {
377   int metric_id = 0;
378   if (!address.IsEmpty()) {
379     metric_id = MetricIdManager::GetInstance().AllocateId(address);
380   }
381   int ret = stats_write(
382       BLUETOOTH_SOCKET_CONNECTION_STATE_CHANGED,
383       byteField,
384       port,
385       type,
386       connection_state,
387       tx_bytes,
388       rx_bytes,
389       uid,
390       server_port,
391       socket_role,
392       metric_id);
393   if (ret < 0) {
394     log::warn(
395         "Failed for {}, port {}, type {}, state {}, tx_bytes {}, rx_bytes {}, uid {}, server_port "
396         "{}, socket_role {}, error {}",
397         address,
398         port,
399         type,
400         connection_state,
401         tx_bytes,
402         rx_bytes,
403         uid,
404         server_port,
405         socket_role,
406         ret);
407   }
408 }
409 
LogMetricManufacturerInfo(const Address & address,android::bluetooth::AddressTypeEnum address_type,android::bluetooth::DeviceInfoSrcEnum source_type,const std::string & source_name,const std::string & manufacturer,const std::string & model,const std::string & hardware_version,const std::string & software_version)410 void LogMetricManufacturerInfo(
411     const Address& address,
412     android::bluetooth::AddressTypeEnum address_type,
413     android::bluetooth::DeviceInfoSrcEnum source_type,
414     const std::string& source_name,
415     const std::string& manufacturer,
416     const std::string& model,
417     const std::string& hardware_version,
418     const std::string& software_version) {
419   int metric_id = 0;
420   if (!address.IsEmpty()) {
421     metric_id = MetricIdManager::GetInstance().AllocateId(address);
422   }
423   int ret = stats_write(
424       BLUETOOTH_DEVICE_INFO_REPORTED,
425       byteField,
426       source_type,
427       source_name.c_str(),
428       manufacturer.c_str(),
429       model.c_str(),
430       hardware_version.c_str(),
431       software_version.c_str(),
432       metric_id,
433       address_type,
434       address.address[5],
435       address.address[4],
436       address.address[3]);
437   if (ret < 0) {
438     log::warn(
439         "Failed for {}, source_type {}, source_name {}, manufacturer {}, model {}, "
440         "hardware_version {}, software_version {}, MAC address type {} MAC address prefix {} {} "
441         "{}, error {}",
442         address,
443         source_type,
444         source_name,
445         manufacturer,
446         model,
447         hardware_version,
448         software_version,
449         address_type,
450         address.address[5],
451         address.address[4],
452         address.address[3],
453         ret);
454   }
455 }
456 
LogMetricBluetoothHalCrashReason(const Address & address,uint32_t error_code,uint32_t vendor_error_code)457 void LogMetricBluetoothHalCrashReason(
458     const Address& address,
459     uint32_t error_code,
460     uint32_t vendor_error_code) {
461   int ret =
462       stats_write(BLUETOOTH_HAL_CRASH_REASON_REPORTED, 0 /* metric_id */, byteField, error_code, vendor_error_code);
463   if (ret < 0) {
464     log::warn(
465         "Failed for {}, error_code {}, vendor_error_code {}, error {}",
466         address,
467         common::ToHexString(error_code),
468         common::ToHexString(vendor_error_code),
469         ret);
470   }
471 }
472 
LogMetricBluetoothLocalSupportedFeatures(uint32_t page_num,uint64_t features)473 void LogMetricBluetoothLocalSupportedFeatures(uint32_t page_num, uint64_t features) {
474   int ret = stats_write(
475       BLUETOOTH_LOCAL_SUPPORTED_FEATURES_REPORTED, page_num, static_cast<int64_t>(features));
476   if (ret < 0) {
477     log::warn(
478         "Failed for LogMetricBluetoothLocalSupportedFeatures, page_num {}, features {}, error {}",
479         page_num,
480         features,
481         ret);
482   }
483 }
484 
LogMetricBluetoothLocalVersions(uint32_t lmp_manufacturer_name,uint8_t lmp_version,uint32_t lmp_subversion,uint8_t hci_version,uint32_t hci_revision)485 void LogMetricBluetoothLocalVersions(
486     uint32_t lmp_manufacturer_name,
487     uint8_t lmp_version,
488     uint32_t lmp_subversion,
489     uint8_t hci_version,
490     uint32_t hci_revision) {
491   int ret = stats_write(
492       BLUETOOTH_LOCAL_VERSIONS_REPORTED,
493       static_cast<int32_t>(lmp_manufacturer_name),
494       static_cast<int32_t>(lmp_version),
495       static_cast<int32_t>(lmp_subversion),
496       static_cast<int32_t>(hci_version),
497       static_cast<int32_t>(hci_revision));
498   if (ret < 0) {
499     log::warn(
500         "Failed for LogMetricBluetoothLocalVersions, lmp_manufacturer_name {}, lmp_version {}, "
501         "lmp_subversion {}, hci_version {}, hci_revision {}, error {}",
502         lmp_manufacturer_name,
503         lmp_version,
504         lmp_subversion,
505         hci_version,
506         hci_revision,
507         ret);
508   }
509 }
510 
LogMetricBluetoothDisconnectionReasonReported(uint32_t reason,const Address & address,uint32_t connection_handle)511 void LogMetricBluetoothDisconnectionReasonReported(
512     uint32_t reason, const Address& address, uint32_t connection_handle) {
513   int metric_id = 0;
514   if (!address.IsEmpty()) {
515     metric_id = MetricIdManager::GetInstance().AllocateId(address);
516   }
517   int ret = stats_write(BLUETOOTH_DISCONNECTION_REASON_REPORTED, reason, metric_id, connection_handle);
518   if (ret < 0) {
519     log::warn(
520         "Failed for LogMetricBluetoothDisconnectionReasonReported, reason {}, metric_id {}, "
521         "connection_handle {}, error {}",
522         reason,
523         metric_id,
524         connection_handle,
525         ret);
526   }
527 }
528 
LogMetricBluetoothRemoteSupportedFeatures(const Address & address,uint32_t page,uint64_t features,uint32_t connection_handle)529 void LogMetricBluetoothRemoteSupportedFeatures(
530     const Address& address, uint32_t page, uint64_t features, uint32_t connection_handle) {
531   int metric_id = 0;
532   if (!address.IsEmpty()) {
533     metric_id = MetricIdManager::GetInstance().AllocateId(address);
534   }
535   int ret = stats_write(
536       BLUETOOTH_REMOTE_SUPPORTED_FEATURES_REPORTED,
537       metric_id,
538       page,
539       static_cast<int64_t>(features),
540       connection_handle);
541   if (ret < 0) {
542     log::warn(
543         "Failed for LogMetricBluetoothRemoteSupportedFeatures, metric_id {}, page {}, features {}, "
544         "connection_handle {}, error {}",
545         metric_id,
546         page,
547         features,
548         connection_handle,
549         ret);
550   }
551 }
552 
LogMetricBluetoothCodePathCounterMetrics(int32_t key,int64_t count)553 void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {
554   int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
555   if (ret < 0) {
556     log::warn("Failed counter metrics for {}, count {}, error {}", key, count, ret);
557   }
558 }
559 
LogMetricBluetoothLEConnectionMetricEvent(const Address & address,android::bluetooth::le::LeConnectionOriginType origin_type,android::bluetooth::le::LeConnectionType connection_type,android::bluetooth::le::LeConnectionState transaction_state,std::vector<std::pair<os::ArgumentType,int>> & argument_list)560 void LogMetricBluetoothLEConnectionMetricEvent(
561     const Address& address,
562     android::bluetooth::le::LeConnectionOriginType origin_type,
563     android::bluetooth::le::LeConnectionType connection_type,
564     android::bluetooth::le::LeConnectionState transaction_state,
565     std::vector<std::pair<os::ArgumentType, int>>& argument_list) {
566   bluetooth::metrics::MetricsCollector::GetLEConnectionMetricsCollector()->AddStateChangedEvent(
567       address, origin_type, connection_type, transaction_state, argument_list);
568 }
569 
LogMetricBluetoothLEConnection(os::LEConnectionSessionOptions session_options)570 void LogMetricBluetoothLEConnection(os::LEConnectionSessionOptions session_options) {
571   int metric_id = 0;
572   if (!session_options.remote_address.IsEmpty()) {
573     metric_id = MetricIdManager::GetInstance().AllocateId(session_options.remote_address);
574   }
575   int ret = stats_write(
576       BLUETOOTH_LE_SESSION_CONNECTED,
577       session_options.acl_connection_state,
578       session_options.origin_type,
579       session_options.transaction_type,
580       session_options.transaction_state,
581       session_options.latency,
582       metric_id,
583       session_options.app_uid,
584       session_options.acl_latency,
585       session_options.status,
586       session_options.is_cancelled);
587 
588   if (ret < 0) {
589     log::warn(
590         "Failed BluetoothLeSessionConnected - Address: {}, ACL Connection State: {}, Origin Type:  "
591         "{}",
592         session_options.remote_address,
593         common::ToHexString(session_options.acl_connection_state),
594         common::ToHexString(session_options.origin_type));
595   }
596 }
597 
598 }  // namespace os
599 }  // namespace bluetooth
600