From ee02f4df3b9bf59167dd86b3f75ad71310b22861 Mon Sep 17 00:00:00 2001 From: Henri Chataing <henrichataing@google.com> Date: Tue, 27 Feb 2024 00:27:57 +0000 Subject: [PATCH] system/btif/src: Migrate to libbluetooth_log Test: m com.android.btservices Bug: 305066880 Flag: EXEMPT, mechanical refactor Change-Id: I9168fdc9c2b5ce47686336e8e1673df62586974b --- .../hearing_aid/hearing_aid_audio_source.cc | 2 - system/bta/include/bta_api.h | 2 + system/bta/include/bta_api_data_types.h | 6 + system/bta/include/bta_sec_api.h | 6 + system/btif/Android.bp | 10 +- system/btif/include/btif_a2dp_sink.h | 8 + system/btif/include/btif_bqr.h | 10 + system/btif/include/btif_hd.h | 6 + system/btif/include/btif_hh.h | 6 + system/btif/src/bluetooth.cc | 67 +- system/btif/src/btif_a2dp.cc | 53 +- system/btif/src/btif_a2dp_control.cc | 83 +- system/btif/src/btif_a2dp_sink.cc | 151 ++- system/btif/src/btif_a2dp_source.cc | 221 ++-- system/btif/src/btif_av.cc | 1003 ++++++++--------- system/btif/src/btif_avrcp_audio_track.cc | 38 +- system/btif/src/btif_bqr.cc | 161 ++- system/btif/src/btif_config.cc | 22 +- system/btif/src/btif_config_cache.cc | 28 +- system/btif/src/btif_core.cc | 56 +- system/btif/src/btif_csis_client.cc | 32 +- system/btif/src/btif_dm.cc | 558 ++++----- system/btif/src/btif_gatt_client.cc | 49 +- system/btif/src/btif_gatt_server.cc | 26 +- system/btif/src/btif_gatt_test.cc | 89 +- system/btif/src/btif_gatt_util.cc | 14 +- system/btif/src/btif_hd.cc | 90 +- system/btif/src/btif_hf.cc | 317 +++--- system/btif/src/btif_hf_client.cc | 106 +- system/btif/src/btif_hh.cc | 429 ++++--- system/btif/src/btif_iot_config.cc | 10 +- system/btif/src/btif_jni_task.cc | 6 +- system/btif/src/btif_keystore.cc | 19 +- system/btif/src/btif_le_audio.cc | 76 +- system/btif/src/btif_pan.cc | 108 +- system/btif/src/btif_profile_queue.cc | 27 +- system/btif/src/btif_profile_storage.cc | 56 +- system/btif/src/btif_rc.cc | 884 +++++++-------- system/btif/src/btif_sdp.cc | 12 +- system/btif/src/btif_sdp_server.cc | 86 +- system/btif/src/btif_sock.cc | 43 +- system/btif/src/btif_sock_l2cap.cc | 90 +- system/btif/src/btif_sock_rfc.cc | 175 ++- system/btif/src/btif_sock_sco.cc | 33 +- system/btif/src/btif_sock_sdp.cc | 103 +- system/btif/src/btif_sock_thread.cc | 75 +- system/btif/src/btif_sock_util.cc | 21 +- system/btif/src/btif_storage.cc | 101 +- system/btif/src/btif_vc.cc | 80 +- system/btif/src/stack_manager.cc | 43 +- system/include/hardware/bluetooth.h | 16 + system/include/hardware/bt_av.h | 5 + system/include/hardware/bt_hd.h | 10 + system/include/hardware/bt_hf.h | 13 +- system/include/hardware/bt_hh.h | 10 +- system/include/hardware/bt_rc.h | 18 + system/include/hardware/bt_sdp.h | 10 + system/include/hardware/bt_sock.h | 10 + system/stack/include/btm_sec_api_types.h | 2 + 59 files changed, 2888 insertions(+), 2903 deletions(-) diff --git a/system/bta/hearing_aid/hearing_aid_audio_source.cc b/system/bta/hearing_aid/hearing_aid_audio_source.cc index e8818e83c35..3c1b038934c 100644 --- a/system/bta/hearing_aid/hearing_aid_audio_source.cc +++ b/system/bta/hearing_aid/hearing_aid_audio_source.cc @@ -40,8 +40,6 @@ using namespace bluetooth; namespace fmt { template <> -struct formatter<bt_status_t> : enum_formatter<bt_status_t> {}; -template <> struct formatter<tUIPC_EVENT> : enum_formatter<tUIPC_EVENT> {}; template <> struct formatter<tHEARING_AID_CTRL_ACK> diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h index 6601f95de9b..7abc86d780d 100644 --- a/system/bta/include/bta_api.h +++ b/system/bta/include/bta_api.h @@ -974,6 +974,8 @@ void DumpsysBtaDm(int fd); namespace fmt { template <> struct formatter<tBTA_DM_SEARCH_EVT> : enum_formatter<tBTA_DM_SEARCH_EVT> {}; +template <> +struct formatter<tBTA_DM_ACL_EVT> : enum_formatter<tBTA_DM_ACL_EVT> {}; } // namespace fmt #endif /* BTA_API_H */ diff --git a/system/bta/include/bta_api_data_types.h b/system/bta/include/bta_api_data_types.h index daa502608ca..aa41dd397fa 100644 --- a/system/bta/include/bta_api_data_types.h +++ b/system/bta/include/bta_api_data_types.h @@ -19,6 +19,7 @@ #pragma once #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <cstdint> #include <string> @@ -61,3 +62,8 @@ typedef struct { typedef struct { RawAddress bd_addr; } tBTA_DM_KEY_MISSING; + +namespace fmt { +template <> +struct formatter<tBTA_STATUS> : enum_formatter<tBTA_STATUS> {}; +} // namespace fmt diff --git a/system/bta/include/bta_sec_api.h b/system/bta/include/bta_sec_api.h index 109fa94e86a..9b3ae1f8ae5 100644 --- a/system/bta/include/bta_sec_api.h +++ b/system/bta/include/bta_sec_api.h @@ -20,6 +20,7 @@ #include <base/functional/callback.h> #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <cstdint> @@ -495,3 +496,8 @@ void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback); * ******************************************************************************/ void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept); + +namespace fmt { +template <> +struct formatter<tBTA_DM_SEC_EVT> : enum_formatter<tBTA_DM_SEC_EVT> {}; +} // namespace fmt diff --git a/system/btif/Android.bp b/system/btif/Android.bp index 497cb5fe69f..263ca2048ae 100644 --- a/system/btif/Android.bp +++ b/system/btif/Android.bp @@ -287,6 +287,7 @@ cc_test { ], header_libs: ["libbluetooth_headers"], shared_libs: [ + "libbase", "libcrypto", "libcutils", "libhidlbase", @@ -396,7 +397,10 @@ cc_test { cflags: [ "-Wno-unused-parameter", ], - shared_libs: ["liblog"], + shared_libs: [ + "libbase", + "liblog", + ], } // btif avrcp audio track unit tests @@ -430,6 +434,7 @@ cc_test { "libosi", ], shared_libs: [ + "libbase", "liblog", ], cflags: [ @@ -460,6 +465,7 @@ cc_test { ], header_libs: ["libbluetooth_headers"], shared_libs: [ + "libbase", "libcrypto", "libcutils", "liblog", @@ -510,6 +516,7 @@ cc_test { ], header_libs: ["libbluetooth_headers"], shared_libs: [ + "libbase", "libbinder_ndk", "libcrypto", "libcutils", @@ -551,6 +558,7 @@ cc_test { ], header_libs: ["libbluetooth_headers"], shared_libs: [ + "libbase", "libcutils", "liblog", ], diff --git a/system/btif/include/btif_a2dp_sink.h b/system/btif/include/btif_a2dp_sink.h index 8875eed850d..72eca766548 100644 --- a/system/btif/include/btif_a2dp_sink.h +++ b/system/btif/include/btif_a2dp_sink.h @@ -20,6 +20,8 @@ #ifndef BTIF_A2DP_SINK_H #define BTIF_A2DP_SINK_H +#include <bluetooth/log.h> + #include <cstdint> #include <future> @@ -141,4 +143,10 @@ void btif_a2dp_sink_set_audio_track_gain(float gain); // Get audio track handle void * btif_a2dp_sink_get_audio_track(void); +namespace fmt { +template <> +struct formatter<btif_a2dp_sink_focus_state_t> + : enum_formatter<btif_a2dp_sink_focus_state_t> {}; +} // namespace fmt + #endif /* BTIF_A2DP_SINK_H */ diff --git a/system/btif/include/btif_bqr.h b/system/btif/include/btif_bqr.h index 374a387782e..dd850c62418 100644 --- a/system/btif/include/btif_bqr.h +++ b/system/btif/include/btif_bqr.h @@ -17,6 +17,8 @@ #ifndef BTIF_BQR_H_ #define BTIF_BQR_H_ +#include <bluetooth/log.h> + #include "btm_api_types.h" #include "common/leaky_bonded_queue.h" #include "include/hardware/bt_bqr.h" @@ -457,4 +459,12 @@ void DebugDump(int fd); } // namespace bqr } // namespace bluetooth +namespace fmt { +template <> +struct formatter<bluetooth::bqr::BqrReportAction> + : enum_formatter<bluetooth::bqr::BqrReportAction> {}; +template <> +struct formatter<bluetooth::bqr::BqrVseSubEvt> : ostream_formatter {}; +} // namespace fmt + #endif // BTIF_BQR_H_ diff --git a/system/btif/include/btif_hd.h b/system/btif/include/btif_hd.h index 337deefc7af..ac29552cfb1 100644 --- a/system/btif/include/btif_hd.h +++ b/system/btif/include/btif_hd.h @@ -20,6 +20,7 @@ #ifndef BTIF_HD_H #define BTIF_HD_H +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_hd.h> #include <stdint.h> @@ -46,4 +47,9 @@ extern btif_hd_cb_t btif_hd_cb; void btif_hd_remove_device(RawAddress bd_addr); void btif_hd_service_registration(); +namespace fmt { +template <> +struct formatter<BTIF_HD_STATUS> : enum_formatter<BTIF_HD_STATUS> {}; +} // namespace fmt + #endif diff --git a/system/btif/include/btif_hh.h b/system/btif/include/btif_hh.h index dbe37492760..7dd5aa1cdcf 100644 --- a/system/btif/include/btif_hh.h +++ b/system/btif/include/btif_hh.h @@ -20,6 +20,7 @@ #define BTIF_HH_H #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_hh.h> #include <pthread.h> @@ -144,4 +145,9 @@ void btif_hh_service_registration(bool enable); void DumpsysHid(int fd); +namespace fmt { +template <> +struct formatter<BTIF_HH_STATUS> : enum_formatter<BTIF_HH_STATUS> {}; +} // namespace fmt + #endif diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc index d6ba5759299..1bdc3de9a5c 100644 --- a/system/btif/src/bluetooth.cc +++ b/system/btif/src/bluetooth.cc @@ -29,6 +29,7 @@ #include <android_bluetooth_flags.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bluetooth_headset_interface.h> #include <hardware/bt_av.h> @@ -120,6 +121,7 @@ using bluetooth::hearing_aid::HearingAidInterface; using bluetooth::le_audio::LeAudioBroadcasterInterface; using bluetooth::le_audio::LeAudioClientInterface; using bluetooth::vc::VolumeControlInterface; +using namespace bluetooth; /******************************************************************************* * Static variables @@ -199,7 +201,7 @@ struct ConfigInterfaceImpl : bluetooth::core::ConfigInterface { "false"); auto a2dp_offload_enabled = (strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0); - LOG_VERBOSE("a2dp_offload.enable = %d", a2dp_offload_enabled); + log::verbose("a2dp_offload.enable = {}", a2dp_offload_enabled); return a2dp_offload_enabled; } @@ -297,8 +299,8 @@ struct CoreInterfaceImpl : bluetooth::core::CoreInterface { */ } break; default: - LOG_ERROR("%s: Unknown service %d being %s", __func__, service_id, - (enable) ? "enabled" : "disabled"); + log::error("Unknown service {} being {}", service_id, + (enable) ? "enabled" : "disabled"); return BT_STATUS_FAIL; } return BT_STATUS_SUCCESS; @@ -409,11 +411,10 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted, const char** init_flags, bool is_atv, const char* user_data_directory) { (void)user_data_directory; - LOG_INFO( - "%s: start restricted = %d ; common criteria mode = %d, config compare " - "result = %d", - __func__, start_restricted, is_common_criteria_mode, - config_compare_result); + log::info( + "start restricted = {} ; common criteria mode = {}, config compare " + "result = {}", + start_restricted, is_common_criteria_mode, config_compare_result); bluetooth::common::InitFlags::Load(init_flags); @@ -630,7 +631,7 @@ static int create_bond_out_of_band(const RawAddress* bd_addr, int transport, } static int generate_local_oob_data(tBT_TRANSPORT transport) { - LOG_INFO("%s", __func__); + log::info(""); if (!interface_ready()) return BT_STATUS_NOT_READY; return do_in_main_thread( @@ -646,8 +647,8 @@ static int cancel_bond(const RawAddress* bd_addr) { static int remove_bond(const RawAddress* bd_addr) { if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) { - LOG_INFO("%s cannot be removed in restricted mode", - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::info("{} cannot be removed in restricted mode", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_SUCCESS; } @@ -706,7 +707,7 @@ static int read_energy_info() { } static int clear_event_filter() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_clear_event_filter)); @@ -714,7 +715,7 @@ static int clear_event_filter() { } static int clear_event_mask() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_clear_event_mask)); @@ -722,7 +723,7 @@ static int clear_event_mask() { } static int clear_filter_accept_list() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread(FROM_HERE, @@ -731,7 +732,7 @@ static int clear_filter_accept_list() { } static int disconnect_all_acls() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_disconnect_all_acls)); @@ -739,7 +740,7 @@ static int disconnect_all_acls() { } static void le_rand_btif_cb(uint64_t random_number) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); do_in_jni_thread( FROM_HERE, base::BindOnce( @@ -748,7 +749,7 @@ static void le_rand_btif_cb(uint64_t random_number) { } static int le_rand() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread( @@ -848,8 +849,8 @@ static int get_remote_pbap_pce_version(const RawAddress* bd_addr) { if (!btif_config_get_bin(bd_addr->ToString(), BTIF_STORAGE_KEY_PBAP_PCE_VERSION, (uint8_t*)&pce_version, &version_value_size)) { - LOG_WARN("Failed to read cached peer PCE version for %s", - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::warn("Failed to read cached peer PCE version for {}", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); } return pce_version; } @@ -859,12 +860,12 @@ static bool pbap_pse_dynamic_version_upgrade_is_enabled() { pbap_pse_dynamic_version_upgrade_is_enabled()) { return true; } - LOG_WARN("PBAP PSE dynamic version upgrade is not enabled"); + log::warn("PBAP PSE dynamic version upgrade is not enabled"); return false; } static const void* get_profile_interface(const char* profile_id) { - LOG_INFO("%s: id = %s", __func__, profile_id); + log::info("id = {}", profile_id); /* sanity check */ if (!interface_ready()) return NULL; @@ -1017,15 +1018,15 @@ static int set_os_callouts(bt_os_callouts_t* callouts) { } static int config_clear(void) { - LOG_INFO("%s", __func__); + log::info(""); int ret = BT_STATUS_SUCCESS; if (!btif_config_clear()) { - LOG_ERROR("Failed to clear btif config"); + log::error("Failed to clear btif config"); ret = BT_STATUS_FAIL; } if (!device_iot_config_clear()) { - LOG_ERROR("Failed to clear device iot config"); + log::error("Failed to clear device iot config"); ret = BT_STATUS_FAIL; } @@ -1051,7 +1052,7 @@ static int set_dynamic_audio_buffer_size(int codec, int size) { static bool allow_low_latency_audio(bool allowed, const RawAddress& /* address */) { - LOG_INFO("%s %s", __func__, allowed ? "true" : "false"); + log::info("{}", allowed); bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed(allowed); return true; } @@ -1059,7 +1060,7 @@ static bool allow_low_latency_audio(bool allowed, static void metadata_changed(const RawAddress& remote_bd_addr, int key, std::vector<uint8_t> value) { if (!interface_ready()) { - LOG_ERROR("Interface not ready!"); + log::error("Interface not ready!"); return; } @@ -1076,7 +1077,7 @@ static bool interop_match_addr(const char* feature_name, int feature = interop_feature_name_to_feature_id(feature_name); if (feature == -1) { - LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name); + log::error("feature doesn't exist: {}", feature_name); return false; } @@ -1090,7 +1091,7 @@ static bool interop_match_name(const char* feature_name, const char* name) { int feature = interop_feature_name_to_feature_id(feature_name); if (feature == -1) { - LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name); + log::error("feature doesn't exist: {}", feature_name); return false; } @@ -1105,7 +1106,7 @@ static bool interop_match_addr_or_name(const char* feature_name, int feature = interop_feature_name_to_feature_id(feature_name); if (feature == -1) { - LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name); + log::error("feature doesn't exist: {}", feature_name); return false; } @@ -1123,7 +1124,7 @@ static void interop_database_add_remove_addr(bool do_add, int feature = interop_feature_name_to_feature_id(feature_name); if (feature == -1) { - LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name); + log::error("feature doesn't exist: {}", feature_name); return; } @@ -1143,7 +1144,7 @@ static void interop_database_add_remove_name(bool do_add, int feature = interop_feature_name_to_feature_id(feature_name); if (feature == -1) { - LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name); + log::error("feature doesn't exist: {}", feature_name); return; } @@ -1350,7 +1351,7 @@ void invoke_ssp_request_cb(RawAddress bd_addr, bt_bdname_t bd_name, void invoke_oob_data_request_cb(tBT_TRANSPORT t, bool valid, Octet16 c, Octet16 r, RawAddress raw_address, uint8_t address_type) { - LOG_INFO("%s", __func__); + log::info(""); bt_oob_data_t oob_data = {}; const char* local_name; BTM_ReadLocalDeviceName(&local_name); @@ -1388,7 +1389,7 @@ void invoke_oob_data_request_cb(tBT_TRANSPORT t, bool valid, Octet16 c, }, t, oob_data)); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s: Failed to call callback!", __func__); + log::error("Failed to call callback!"); } } diff --git a/system/btif/src/btif_a2dp.cc b/system/btif/src/btif_a2dp.cc index 0e6f217e490..c11281a236d 100644 --- a/system/btif/src/btif_a2dp.cc +++ b/system/btif/src/btif_a2dp.cc @@ -22,6 +22,7 @@ #include "btif_a2dp.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <stdbool.h> #include "audio_a2dp_hw/include/audio_a2dp_hw.h" @@ -38,13 +39,15 @@ #include "os/log.h" #include "types/raw_address.h" +using namespace bluetooth; + void btif_a2dp_on_idle(const RawAddress& peer_addr) { - LOG_VERBOSE("Peer stream endpoint type:%s", - peer_stream_endpoint_text(btif_av_get_peer_sep()).c_str()); + log::verbose("Peer stream endpoint type:{}", + peer_stream_endpoint_text(btif_av_get_peer_sep())); if (btif_av_src_sink_coexist_enabled()) { bool is_sink = btif_av_peer_is_sink(peer_addr); bool is_source = btif_av_peer_is_source(peer_addr); - LOG_INFO("## ON A2DP IDLE ## is_sink:%d is_source:%d", is_sink, is_source); + log::info("## ON A2DP IDLE ## is_sink:{} is_source:{}", is_sink, is_source); if (is_sink) { btif_a2dp_source_on_idle(); } else if (is_source) { @@ -61,15 +64,14 @@ void btif_a2dp_on_idle(const RawAddress& peer_addr) { } bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start) { - LOG(INFO) << __func__ << ": ## ON A2DP STARTED ## peer " - << ADDRESS_TO_LOGGABLE_STR(peer_addr) << " p_av_start:" - << p_av_start; + log::info("## ON A2DP STARTED ## peer {} p_av_start:{}", + ADDRESS_TO_LOGGABLE_STR(peer_addr), fmt::ptr(p_av_start)); if (p_av_start == NULL) { tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_SUCCESS; if (!bluetooth::headset::IsCallIdle()) { - LOG(ERROR) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr) - << " call in progress, do not start A2DP stream"; + log::error("peer {} call in progress, do not start A2DP stream", + ADDRESS_TO_LOGGABLE_STR(peer_addr)); status = A2DP_CTRL_ACK_INCALL_FAILURE; } /* just ack back a local start request, do not start the media encoder since @@ -82,15 +84,14 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start return true; } - LOG(INFO) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr) - << " status:" << +p_av_start->status - << " suspending:" << logbool(p_av_start->suspending) << " initiator:" << logbool(p_av_start->initiator); + log::info("peer {} status:{} suspending:{} initiator:{}", + ADDRESS_TO_LOGGABLE_STR(peer_addr), p_av_start->status, + logbool(p_av_start->suspending), logbool(p_av_start->initiator)); if (p_av_start->status == BTA_AV_SUCCESS) { if (p_av_start->suspending) { - LOG(WARNING) << __func__ << ": peer " - << ADDRESS_TO_LOGGABLE_STR(peer_addr) - << " A2DP is suspending and ignores the started event"; + log::warn("peer {} A2DP is suspending and ignores the started event", + ADDRESS_TO_LOGGABLE_STR(peer_addr)); return false; } if (btif_av_is_a2dp_offload_running()) { @@ -112,8 +113,8 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start /* media task is auto-started upon UIPC connection of a2dp audiopath */ } } else if (p_av_start->initiator) { - LOG(ERROR) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr) - << " A2DP start request failed: status = " << +p_av_start->status; + log::error("peer {} A2DP start request failed: status = {}", + ADDRESS_TO_LOGGABLE_STR(peer_addr), p_av_start->status); if (bluetooth::audio::a2dp::is_hal_enabled()) { bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_FAILURE); } else { @@ -125,7 +126,7 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start } void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) { - LOG_INFO("%s: ## ON A2DP STOPPED ## p_av_suspend=%p", __func__, p_av_suspend); + log::info("## ON A2DP STOPPED ## p_av_suspend={}", fmt::ptr(p_av_suspend)); if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) { btif_a2dp_sink_on_stopped(p_av_suspend); @@ -138,8 +139,7 @@ void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) { } void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { - LOG_INFO("%s: ## ON A2DP SUSPENDED ## p_av_suspend=%p", __func__, - p_av_suspend); + log::info("## ON A2DP SUSPENDED ## p_av_suspend={}", fmt::ptr(p_av_suspend)); if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) { btif_a2dp_sink_on_suspended(p_av_suspend); return; @@ -153,21 +153,20 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { void btif_a2dp_on_offload_started(const RawAddress& peer_addr, tBTA_AV_STATUS status) { tA2DP_CTRL_ACK ack; - LOG_INFO("%s: peer %s status %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status); + log::info("peer {} status {}", ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status); switch (status) { case BTA_AV_SUCCESS: ack = A2DP_CTRL_ACK_SUCCESS; break; case BTA_AV_FAIL_RESOURCES: - LOG_ERROR("%s: peer %s FAILED UNSUPPORTED", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_addr)); + log::error("peer {} FAILED UNSUPPORTED", + ADDRESS_TO_LOGGABLE_CSTR(peer_addr)); ack = A2DP_CTRL_ACK_UNSUPPORTED; break; default: - LOG_ERROR("%s: peer %s FAILED: status = %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status); + log::error("peer {} FAILED: status = {}", + ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status); ack = A2DP_CTRL_ACK_FAILURE; break; } @@ -176,8 +175,8 @@ void btif_a2dp_on_offload_started(const RawAddress& peer_addr, // Offload request will return with failure from btif_av sm if // suspend is triggered for remote start. Disconnect only if SoC // returned failure for offload VSC - LOG_ERROR("%s: peer %s offload start failed", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_addr)); + log::error("peer {} offload start failed", + ADDRESS_TO_LOGGABLE_CSTR(peer_addr)); btif_av_src_disconnect_sink(peer_addr); } } diff --git a/system/btif/src/btif_a2dp_control.cc b/system/btif/src/btif_a2dp_control.cc index 8ed0ee5b1fe..d6834a95001 100644 --- a/system/btif/src/btif_a2dp_control.cc +++ b/system/btif/src/btif_a2dp_control.cc @@ -22,6 +22,7 @@ #include "btif_a2dp_control.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <stdbool.h> #include <stdint.h> @@ -36,6 +37,17 @@ #define A2DP_DATA_READ_POLL_MS 10 +using namespace bluetooth; + +namespace fmt { +template <> +struct formatter<tA2DP_CTRL_CMD> : enum_formatter<tA2DP_CTRL_CMD> {}; +template <> +struct formatter<tA2DP_CTRL_ACK> : enum_formatter<tA2DP_CTRL_ACK> {}; +template <> +struct formatter<tUIPC_EVENT> : enum_formatter<tUIPC_EVENT> {}; +} // namespace fmt + struct { uint64_t total_bytes_read = 0; uint16_t audio_delay = 0; @@ -63,8 +75,7 @@ void btif_a2dp_control_cleanup(void) { static tA2DP_CTRL_ACK btif_a2dp_control_on_check_ready() { if (btif_a2dp_source_media_task_is_shutting_down()) { - LOG_WARN("%s: A2DP command check ready while media task shutting down", - __func__); + log::warn("A2DP command check ready while media task shutting down"); return A2DP_CTRL_ACK_FAILURE; } @@ -72,8 +83,7 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_check_ready() { if (btif_av_stream_ready() || btif_av_stream_started_ready()) { return A2DP_CTRL_ACK_SUCCESS; } else { - LOG_WARN("%s: A2DP command check ready while AV stream is not ready", - __func__); + log::warn("A2DP command check ready while AV stream is not ready"); return A2DP_CTRL_ACK_FAILURE; } } @@ -85,7 +95,7 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_start() { * while in a call, and respond with BAD_STATE. */ if (!bluetooth::headset::IsCallIdle()) { - LOG_WARN("%s: A2DP command start while call state is busy", __func__); + log::warn("A2DP command start while call state is busy"); return A2DP_CTRL_ACK_INCALL_FAILURE; } @@ -112,7 +122,7 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_start() { A2DP_DATA_PATH); return A2DP_CTRL_ACK_SUCCESS; } - LOG_WARN("%s: A2DP command start while AV stream is not ready", __func__); + log::warn("A2DP command start while AV stream is not ready"); return A2DP_CTRL_ACK_FAILURE; } @@ -198,28 +208,27 @@ static void btif_a2dp_control_on_set_output_audio_config() { reinterpret_cast<uint8_t*>(&codec_config.sample_rate), sizeof(btav_a2dp_codec_sample_rate_t)) != sizeof(btav_a2dp_codec_sample_rate_t)) { - LOG_ERROR("%s: Error reading sample rate from audio HAL", __func__); + log::error("Error reading sample rate from audio HAL"); return; } if (UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_CTRL, reinterpret_cast<uint8_t*>(&codec_config.bits_per_sample), sizeof(btav_a2dp_codec_bits_per_sample_t)) != sizeof(btav_a2dp_codec_bits_per_sample_t)) { - LOG_ERROR("%s: Error reading bits per sample from audio HAL", __func__); + log::error("Error reading bits per sample from audio HAL"); return; } if (UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_CTRL, reinterpret_cast<uint8_t*>(&codec_config.channel_mode), sizeof(btav_a2dp_codec_channel_mode_t)) != sizeof(btav_a2dp_codec_channel_mode_t)) { - LOG_ERROR("%s: Error reading channel mode from audio HAL", __func__); + log::error("Error reading channel mode from audio HAL"); return; } - LOG_VERBOSE( - "%s: A2DP_CTRL_SET_OUTPUT_AUDIO_CONFIG: " - "sample_rate=0x%x bits_per_sample=0x%x " - "channel_mode=0x%x", - __func__, codec_config.sample_rate, codec_config.bits_per_sample, + log::verbose( + "A2DP_CTRL_SET_OUTPUT_AUDIO_CONFIG: sample_rate=0x{:x} " + "bits_per_sample=0x{:x} channel_mode=0x{:x}", + codec_config.sample_rate, codec_config.bits_per_sample, codec_config.channel_mode); btif_a2dp_source_feeding_update_req(codec_config); } @@ -250,7 +259,7 @@ static void btif_a2dp_recv_ctrl_data(void) { /* detach on ctrl channel means audioflinger process was terminated */ if (n == 0) { - LOG_WARN("%s: CTRL CH DETACHED", __func__); + log::warn("CTRL CH DETACHED"); UIPC_Close(*a2dp_uipc, UIPC_CH_ID_AV_CTRL); return; } @@ -258,11 +267,9 @@ static void btif_a2dp_recv_ctrl_data(void) { // Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it // could be very chatty when audio is streaming. if (cmd == A2DP_CTRL_GET_PRESENTATION_POSITION) { - LOG_VERBOSE("%s: a2dp-ctrl-cmd : %s", __func__, - audio_a2dp_hw_dump_ctrl_event(cmd)); + log::verbose("a2dp-ctrl-cmd : {}", audio_a2dp_hw_dump_ctrl_event(cmd)); } else { - LOG_WARN("%s: a2dp-ctrl-cmd : %s", __func__, - audio_a2dp_hw_dump_ctrl_event(cmd)); + log::warn("a2dp-ctrl-cmd : {}", audio_a2dp_hw_dump_ctrl_event(cmd)); } a2dp_cmd_pending = cmd; @@ -300,7 +307,7 @@ static void btif_a2dp_recv_ctrl_data(void) { break; default: - LOG_ERROR("%s: UNSUPPORTED CMD (%d)", __func__, cmd); + log::error("UNSUPPORTED CMD ({})", cmd); btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE); break; } @@ -308,11 +315,9 @@ static void btif_a2dp_recv_ctrl_data(void) { // Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it // could be very chatty when audio is streaming. if (cmd == A2DP_CTRL_GET_PRESENTATION_POSITION) { - LOG_VERBOSE("%s: a2dp-ctrl-cmd : %s DONE", __func__, - audio_a2dp_hw_dump_ctrl_event(cmd)); + log::verbose("a2dp-ctrl-cmd : {} DONE", audio_a2dp_hw_dump_ctrl_event(cmd)); } else { - LOG_WARN("%s: a2dp-ctrl-cmd : %s DONE", __func__, - audio_a2dp_hw_dump_ctrl_event(cmd)); + log::warn("a2dp-ctrl-cmd : {} DONE", audio_a2dp_hw_dump_ctrl_event(cmd)); } } @@ -320,11 +325,9 @@ static void btif_a2dp_ctrl_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) { // Don't log UIPC_RX_DATA_READY_EVT by default, because it // could be very chatty when audio is streaming. if (event == UIPC_RX_DATA_READY_EVT) { - LOG_VERBOSE("%s: A2DP-CTRL-CHANNEL EVENT %s", __func__, - dump_uipc_event(event)); + log::verbose("A2DP-CTRL-CHANNEL EVENT {}", dump_uipc_event(event)); } else { - LOG_WARN("%s: A2DP-CTRL-CHANNEL EVENT %s", __func__, - dump_uipc_event(event)); + log::warn("A2DP-CTRL-CHANNEL EVENT {}", dump_uipc_event(event)); } switch (event) { @@ -343,15 +346,13 @@ static void btif_a2dp_ctrl_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) { break; default: - LOG_ERROR("%s: ### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###", __func__, - event); + log::error("### A2DP-CTRL-CHANNEL EVENT {} NOT HANDLED ###", event); break; } } static void btif_a2dp_data_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) { - LOG_WARN("%s: BTIF MEDIA (A2DP-DATA) EVENT %s", __func__, - dump_uipc_event(event)); + log::warn("BTIF MEDIA (A2DP-DATA) EVENT {}", dump_uipc_event(event)); switch (event) { case UIPC_OPEN_EVT: @@ -373,14 +374,14 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) { break; case UIPC_CLOSE_EVT: - LOG_VERBOSE("%s: ## AUDIO PATH DETACHED ##", __func__); + log::verbose("## AUDIO PATH DETACHED ##"); btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS); /* Post stop event and wait for audio path to stop */ btif_av_stream_stop(RawAddress::kEmpty); break; default: - LOG_ERROR("%s: ### A2DP-DATA EVENT %d NOT HANDLED ###", __func__, event); + log::error("### A2DP-DATA EVENT {} NOT HANDLED ###", event); break; } } @@ -391,16 +392,16 @@ void btif_a2dp_command_ack(tA2DP_CTRL_ACK status) { // Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it // could be very chatty when audio is streaming. if (a2dp_cmd_pending == A2DP_CTRL_GET_PRESENTATION_POSITION) { - LOG_VERBOSE("%s: ## a2dp ack : %s, status %d ##", __func__, - audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status); + log::verbose("## a2dp ack : {}, status {} ##", + audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status); } else { - LOG_WARN("%s: ## a2dp ack : %s, status %d ##", __func__, - audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status); + log::warn("## a2dp ack : {}, status {} ##", + audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status); } /* Sanity check */ if (a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) { - LOG_ERROR("%s: warning : no command pending, ignore ack", __func__); + log::error("warning : no command pending, ignore ack"); return; } @@ -419,12 +420,12 @@ void btif_a2dp_control_log_bytes_read(uint32_t bytes_read) { } void btif_a2dp_control_set_audio_delay(uint16_t delay) { - LOG_VERBOSE("%s: DELAY: %.1f ms", __func__, (float)delay / 10); + log::verbose("DELAY: {:.1f} ms", (float)delay / 10); delay_report_stats.audio_delay = delay; } void btif_a2dp_control_reset_audio_delay(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); delay_report_stats.audio_delay = 0; delay_report_stats.total_bytes_read = 0; delay_report_stats.timestamp = {}; diff --git a/system/btif/src/btif_a2dp_sink.cc b/system/btif/src/btif_a2dp_sink.cc index e89b01f95ad..8e0083b014a 100644 --- a/system/btif/src/btif_a2dp_sink.cc +++ b/system/btif/src/btif_a2dp_sink.cc @@ -23,6 +23,7 @@ #include <base/functional/bind.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <atomic> #include <mutex> @@ -43,6 +44,7 @@ using bluetooth::common::MessageLoopThread; using LockGuard = std::lock_guard<std::mutex>; +using namespace bluetooth; /** * The receiving queue buffer size. @@ -171,11 +173,11 @@ static const char* dump_media_event(uint16_t event) { } bool btif_a2dp_sink_init() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); if (btif_a2dp_sink_state != BTIF_A2DP_SINK_STATE_OFF) { - LOG_ERROR("%s: A2DP Sink media task already running", __func__); + log::error("A2DP Sink media task already running"); return false; } @@ -185,7 +187,7 @@ bool btif_a2dp_sink_init() { /* Start A2DP Sink media task */ btif_a2dp_sink_cb.worker_thread.StartUp(); if (!btif_a2dp_sink_cb.worker_thread.IsRunning()) { - LOG_ERROR("%s: unable to start up media thread", __func__); + log::error("unable to start up media thread"); btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF; return false; } @@ -195,8 +197,7 @@ bool btif_a2dp_sink_init() { /* Schedule the rest of the operations */ if (!btif_a2dp_sink_cb.worker_thread.EnableRealTimeScheduling()) { #if defined(__ANDROID__) - LOG(FATAL) << __func__ - << ": Failed to increase A2DP decoder thread priority"; + log::fatal("Failed to increase A2DP decoder thread priority"); #endif } btif_a2dp_sink_cb.worker_thread.DoInThread( @@ -205,43 +206,41 @@ bool btif_a2dp_sink_init() { } static void btif_a2dp_sink_init_delayed() { - LOG_INFO("%s", __func__); + log::info(""); btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_RUNNING; } bool btif_a2dp_sink_startup() { - LOG_INFO("%s", __func__); + log::info(""); btif_a2dp_sink_cb.worker_thread.DoInThread( FROM_HERE, base::BindOnce(btif_a2dp_sink_startup_delayed)); return true; } static void btif_a2dp_sink_startup_delayed() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); // Nothing to do } bool btif_a2dp_sink_start_session(const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address); + log::info("peer_address={}", ADDRESS_TO_LOGGABLE_STR(peer_address)); if (btif_a2dp_sink_cb.worker_thread.DoInThread( FROM_HERE, base::BindOnce(btif_a2dp_sink_start_session_delayed, std::move(peer_ready_promise)))) { return true; } else { // cannot set promise but triggers crash - LOG(FATAL) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " fails to context switch"; + log::fatal("peer_address={} fails to context switch", + ADDRESS_TO_LOGGABLE_STR(peer_address)); return false; } } static void btif_a2dp_sink_start_session_delayed( std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__; + log::info(""); LockGuard lock(g_mutex); peer_ready_promise.set_value(); // Nothing to do @@ -250,9 +249,9 @@ static void btif_a2dp_sink_start_session_delayed( bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address, const RawAddress& new_peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": old_peer_address=" - << ADDRESS_TO_LOGGABLE_STR(old_peer_address) - << " new_peer_address=" << ADDRESS_TO_LOGGABLE_STR(new_peer_address); + log::info("old_peer_address={} new_peer_address={}", + ADDRESS_TO_LOGGABLE_STR(old_peer_address), + ADDRESS_TO_LOGGABLE_STR(new_peer_address)); CHECK(!new_peer_address.IsEmpty()); @@ -261,9 +260,8 @@ bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address, } if (!bta_av_co_set_active_peer(new_peer_address)) { - LOG(ERROR) << __func__ - << ": Cannot stream audio: cannot set active peer to " - << ADDRESS_TO_LOGGABLE_STR(new_peer_address); + log::error("Cannot stream audio: cannot set active peer to {}", + ADDRESS_TO_LOGGABLE_STR(new_peer_address)); peer_ready_promise.set_value(); return false; } @@ -277,33 +275,32 @@ bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address, } bool btif_a2dp_sink_end_session(const RawAddress& peer_address) { - LOG_INFO("%s: peer_address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("peer_address={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); btif_a2dp_sink_cb.worker_thread.DoInThread( FROM_HERE, base::BindOnce(btif_a2dp_sink_end_session_delayed)); return true; } static void btif_a2dp_sink_end_session_delayed() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); // Nothing to do } void btif_a2dp_sink_shutdown() { - LOG_INFO("%s", __func__); + log::info(""); btif_a2dp_sink_cb.worker_thread.DoInThread( FROM_HERE, base::BindOnce(btif_a2dp_sink_shutdown_delayed)); } static void btif_a2dp_sink_shutdown_delayed() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); // Nothing to do } void btif_a2dp_sink_cleanup() { - LOG_INFO("%s", __func__); + log::info(""); alarm_t* decode_alarm; @@ -333,7 +330,7 @@ void btif_a2dp_sink_cleanup() { } static void btif_a2dp_sink_cleanup_delayed() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); fixed_queue_free(btif_a2dp_sink_cb.rx_audio_queue, nullptr); @@ -357,8 +354,7 @@ tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count() { } static void btif_a2dp_sink_command_ready(BT_HDR_RIGID* p_msg) { - LOG_VERBOSE("%s: event %d %s", __func__, p_msg->event, - dump_media_event(p_msg->event)); + log::verbose("event {} {}", p_msg->event, dump_media_event(p_msg->event)); switch (p_msg->event) { case BTIF_MEDIA_SINK_DECODER_UPDATE: @@ -384,23 +380,23 @@ static void btif_a2dp_sink_command_ready(BT_HDR_RIGID* p_msg) { btif_a2dp_sink_on_suspend_event(); break; default: - LOG_ERROR("%s: unknown event %d", __func__, p_msg->event); + log::error("unknown event {}", p_msg->event); break; } - LOG_VERBOSE("%s: %s DONE", __func__, dump_media_event(p_msg->event)); + log::verbose("{} DONE", dump_media_event(p_msg->event)); osi_free(p_msg); } void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info) { - LOG_INFO("%s", __func__); + log::info(""); tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf = reinterpret_cast<tBTIF_MEDIA_SINK_DECODER_UPDATE*>( osi_malloc(sizeof(tBTIF_MEDIA_SINK_DECODER_UPDATE))); - LOG_VERBOSE("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__, p_codec_info[1], - p_codec_info[2], p_codec_info[3], p_codec_info[4], - p_codec_info[5], p_codec_info[6]); + log::verbose("p_codec_info[{:x}:{:x}:{:x}:{:x}:{:x}:{:x}]", p_codec_info[1], + p_codec_info[2], p_codec_info[3], p_codec_info[4], + p_codec_info[5], p_codec_info[6]); memcpy(p_buf->codec_info, p_codec_info, AVDT_CODEC_SIZE); p_buf->hdr.event = BTIF_MEDIA_SINK_DECODER_UPDATE; @@ -411,7 +407,7 @@ void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info) { } void btif_a2dp_sink_on_idle() { - LOG_INFO("%s", __func__); + log::info(""); BT_HDR_RIGID* p_buf = reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID))); p_buf->event = BTIF_MEDIA_SINK_SUSPEND; @@ -424,7 +420,7 @@ void btif_a2dp_sink_on_idle() { } void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* /* p_av_suspend */) { - LOG_INFO("%s", __func__); + log::info(""); BT_HDR_RIGID* p_buf = reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID))); p_buf->event = BTIF_MEDIA_SINK_SUSPEND; @@ -436,7 +432,7 @@ void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* /* p_av_suspend */) { } void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* /* p_av_suspend */) { - LOG_INFO("%s", __func__); + log::info(""); BT_HDR_RIGID* p_buf = reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID))); p_buf->event = BTIF_MEDIA_SINK_SUSPEND; @@ -448,7 +444,7 @@ void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* /* p_av_suspend */) { } bool btif_a2dp_sink_on_start() { - LOG_INFO("%s", __func__); + log::info(""); BT_HDR_RIGID* p_buf = reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID))); @@ -460,7 +456,7 @@ bool btif_a2dp_sink_on_start() { } static void btif_a2dp_sink_audio_handle_stop_decoding() { - LOG_INFO("%s", __func__); + log::info(""); alarm_t* old_alarm; { LockGuard lock(g_mutex); @@ -491,7 +487,7 @@ static void btif_decode_alarm_cb(void* /* context */) { } static void btif_a2dp_sink_clear_track_event() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); #ifdef __ANDROID__ @@ -503,7 +499,7 @@ static void btif_a2dp_sink_clear_track_event() { // Must be called while locked. static void btif_a2dp_sink_audio_handle_start_decoding() { - LOG_INFO("%s", __func__); + log::info(""); if (btif_a2dp_sink_cb.decode_alarm != nullptr) return; // Already started decoding @@ -513,7 +509,7 @@ static void btif_a2dp_sink_audio_handle_start_decoding() { btif_a2dp_sink_cb.decode_alarm = alarm_new_periodic("btif.a2dp_sink_decode"); if (btif_a2dp_sink_cb.decode_alarm == nullptr) { - LOG_ERROR("%s: unable to allocate decode alarm", __func__); + log::error("unable to allocate decode alarm"); return; } alarm_set(btif_a2dp_sink_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK_MS, @@ -531,13 +527,13 @@ static void btif_a2dp_sink_on_decode_complete(uint8_t* data, uint32_t len) { static void btif_a2dp_sink_handle_inc_media(BT_HDR* p_msg) { if ((btif_av_get_peer_sep() == AVDT_TSEP_SNK) || (btif_a2dp_sink_cb.rx_flush)) { - LOG_VERBOSE("%s: state changed happened in this tick", __func__); + log::verbose("state changed happened in this tick"); return; } CHECK(btif_a2dp_sink_cb.decoder_interface != nullptr); if (!btif_a2dp_sink_cb.decoder_interface->decode_packet(p_msg)) { - LOG_ERROR("%s: decoding failed", __func__); + log::error("decoding failed"); } } @@ -546,13 +542,13 @@ static void btif_a2dp_sink_avk_handle_timer() { BT_HDR* p_msg; if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) { - LOG_VERBOSE("%s: empty queue", __func__); + log::verbose("empty queue"); return; } /* Don't do anything in case of focus not granted */ if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) { - LOG_VERBOSE("%s: skipping frames since focus is not present", __func__); + log::verbose("skipping frames since focus is not present"); return; } /* Play only in BTIF_A2DP_SINK_FOCUS_GRANTED case */ @@ -561,32 +557,32 @@ static void btif_a2dp_sink_avk_handle_timer() { return; } - LOG_VERBOSE("%s: process frames begin", __func__); + log::verbose("process frames begin"); while (true) { p_msg = (BT_HDR*)fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue); if (p_msg == NULL) { break; } - LOG_VERBOSE("%s: number of packets in queue %zu", __func__, - fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue)); + log::verbose("number of packets in queue {}", + fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue)); /* Queue packet has less frames */ btif_a2dp_sink_handle_inc_media(p_msg); osi_free(p_msg); } - LOG_VERBOSE("%s: process frames end", __func__); + log::verbose("process frames end"); } /* when true media task discards any rx frames */ void btif_a2dp_sink_set_rx_flush(bool enable) { - LOG_INFO("%s: enable=%s", __func__, (enable) ? "true" : "false"); + log::info("enable={}", (enable) ? "true" : "false"); LockGuard lock(g_mutex); btif_a2dp_sink_cb.rx_flush = enable; } static void btif_a2dp_sink_audio_rx_flush_event() { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); // Flush all received encoded audio buffers fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free); @@ -594,30 +590,31 @@ static void btif_a2dp_sink_audio_rx_flush_event() { static void btif_a2dp_sink_decoder_update_event( tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf) { - LOG_INFO("%s", __func__); + log::info(""); LockGuard lock(g_mutex); - LOG_VERBOSE("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__, - p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3], - p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]); + log::verbose("p_codec_info[{:x}:{:x}:{:x}:{:x}:{:x}:{:x}]", + p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3], + p_buf->codec_info[4], p_buf->codec_info[5], + p_buf->codec_info[6]); int sample_rate = A2DP_GetTrackSampleRate(p_buf->codec_info); if (sample_rate == -1) { - LOG_ERROR("%s: cannot get the track frequency", __func__); + log::error("cannot get the track frequency"); return; } int bits_per_sample = A2DP_GetTrackBitsPerSample(p_buf->codec_info); if (bits_per_sample == -1) { - LOG_ERROR("%s: cannot get the bits per sample", __func__); + log::error("cannot get the bits per sample"); return; } int channel_count = A2DP_GetTrackChannelCount(p_buf->codec_info); if (channel_count == -1) { - LOG_ERROR("%s: cannot get the channel count", __func__); + log::error("cannot get the channel count"); return; } int channel_type = A2DP_GetSinkTrackChannelType(p_buf->codec_info); if (channel_type == -1) { - LOG_ERROR("%s: cannot get the Sink channel type", __func__); + log::error("cannot get the Sink channel type"); return; } btif_a2dp_sink_cb.sample_rate = sample_rate; @@ -625,7 +622,7 @@ static void btif_a2dp_sink_decoder_update_event( btif_a2dp_sink_cb.channel_count = channel_count; btif_a2dp_sink_cb.rx_flush = false; - LOG_VERBOSE("%s: reset to Sink role", __func__); + log::verbose("reset to Sink role"); bta_av_co_save_codec(p_buf->codec_info); @@ -633,13 +630,13 @@ static void btif_a2dp_sink_decoder_update_event( A2DP_GetDecoderInterface(p_buf->codec_info); if (btif_a2dp_sink_cb.decoder_interface == nullptr) { - LOG_ERROR("%s: cannot stream audio: no source decoder interface", __func__); + log::error("cannot stream audio: no source decoder interface"); return; } if (!btif_a2dp_sink_cb.decoder_interface->decoder_init( btif_a2dp_sink_on_decode_complete)) { - LOG_ERROR("%s: failed to initialize decoder", __func__); + log::error("failed to initialize decoder"); return; } @@ -647,7 +644,7 @@ static void btif_a2dp_sink_decoder_update_event( btif_a2dp_sink_cb.decoder_interface->decoder_configure(p_buf->codec_info); } - LOG_VERBOSE("%s: create audio track", __func__); + log::verbose("create audio track"); btif_a2dp_sink_cb.audio_track = #ifdef __ANDROID__ BtifAvrcpAudioTrackCreate(sample_rate, bits_per_sample, channel_count); @@ -655,7 +652,7 @@ static void btif_a2dp_sink_decoder_update_event( NULL; #endif if (btif_a2dp_sink_cb.audio_track == nullptr) { - LOG_ERROR("%s: track creation failed", __func__); + log::error("track creation failed"); return; } } @@ -665,7 +662,7 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) { if (btif_a2dp_sink_cb.rx_flush) /* Flush enabled, do not enqueue */ return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue); - LOG_VERBOSE("%s +", __func__); + log::verbose("+"); /* Allocate and queue this buffer */ BT_HDR* p_msg = reinterpret_cast<BT_HDR*>(osi_malloc(sizeof(*p_msg) + p_pkt->len)); @@ -685,8 +682,8 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) { if (btif_a2dp_sink_cb.decode_alarm == nullptr && fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) >= MAX_A2DP_DELAYED_START_FRAME_COUNT) { - LOG_VERBOSE("%s: Initiate decoding. Current focus state:%d", __func__, - btif_a2dp_sink_cb.rx_focus_state); + log::verbose("Initiate decoding. Current focus state:{}", + btif_a2dp_sink_cb.rx_focus_state); if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_GRANTED) { btif_a2dp_sink_audio_handle_start_decoding(); } @@ -696,7 +693,7 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) { } void btif_a2dp_sink_audio_rx_flush_req() { - LOG_INFO("%s", __func__); + log::info(""); if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) { /* Queue is already empty */ return; @@ -714,7 +711,7 @@ void btif_a2dp_sink_debug_dump(int /* fd */) { } void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state) { - LOG_INFO("%s", __func__); + log::info(""); tBTIF_MEDIA_SINK_FOCUS_UPDATE* p_buf = reinterpret_cast<tBTIF_MEDIA_SINK_FOCUS_UPDATE*>( osi_malloc(sizeof(tBTIF_MEDIA_SINK_FOCUS_UPDATE))); @@ -727,10 +724,10 @@ void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state) { static void btif_a2dp_sink_set_focus_state_event( btif_a2dp_sink_focus_state_t state) { - LOG_INFO("%s: state=%d", __func__, state); + log::info("state={}", state); LockGuard lock(g_mutex); - LOG_VERBOSE("%s: setting focus state to %d", __func__, state); + log::verbose("setting focus state to {}", state); btif_a2dp_sink_cb.rx_focus_state = state; if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) { fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free); @@ -741,7 +738,7 @@ static void btif_a2dp_sink_set_focus_state_event( } void btif_a2dp_sink_set_audio_track_gain(float gain) { - LOG_DEBUG("%s: set gain to %f", __func__, gain); + log::debug("set gain to {:f}", gain); LockGuard lock(g_mutex); #ifdef __ANDROID__ @@ -755,7 +752,7 @@ void * btif_a2dp_sink_get_audio_track(void) } static void btif_a2dp_sink_clear_track_event_req() { - LOG_INFO("%s", __func__); + log::info(""); BT_HDR_RIGID* p_buf = reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID))); @@ -765,7 +762,7 @@ static void btif_a2dp_sink_clear_track_event_req() { } static void btif_a2dp_sink_on_start_event() { - LOG_INFO("%s", __func__); + log::info(""); if ((btif_a2dp_sink_cb.decoder_interface != nullptr) && (btif_a2dp_sink_cb.decoder_interface->decoder_start != nullptr)) { @@ -776,7 +773,7 @@ static void btif_a2dp_sink_on_start_event() { } static void btif_a2dp_sink_on_suspend_event() { - LOG_INFO("%s", __func__); + log::info(""); if ((btif_a2dp_sink_cb.decoder_interface != nullptr) && (btif_a2dp_sink_cb.decoder_interface->decoder_suspend != nullptr)) { diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc index ad4c3922fc8..6b6555ec88d 100644 --- a/system/btif/src/btif_a2dp_source.cc +++ b/system/btif/src/btif_a2dp_source.cc @@ -23,6 +23,7 @@ #include <android_bluetooth_flags.h> #include <base/logging.h> #include <base/run_loop.h> +#include <bluetooth/log.h> #ifdef __ANDROID__ #include <cutils/trace.h> #endif @@ -59,6 +60,7 @@ using bluetooth::common::A2dpSessionMetrics; using bluetooth::common::BluetoothMetricsLogger; using bluetooth::common::RepeatingTimer; +using namespace bluetooth; extern std::unique_ptr<tUIPC_STATE> a2dp_uipc; @@ -329,7 +331,7 @@ void btif_a2dp_source_accumulate_stats(BtifMediaStats* src, } bool btif_a2dp_source_init(void) { - LOG_INFO("%s", __func__); + log::info(""); // Start A2DP Source media task btif_a2dp_source_thread.StartUp(); @@ -339,7 +341,7 @@ bool btif_a2dp_source_init(void) { } static void btif_a2dp_source_init_delayed(void) { - LOG_INFO("%s", __func__); + log::info(""); // When codec extensibility is enabled in the audio HAL interface, // the provider needs to be initialized earlier in order to ensure // get_a2dp_configuration and parse_a2dp_configuration can be @@ -350,10 +352,10 @@ static void btif_a2dp_source_init_delayed(void) { } bool btif_a2dp_source_startup(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (btif_a2dp_source_cb.State() != BtifA2dpSource::kStateOff) { - LOG_ERROR("%s: A2DP Source media task already running", __func__); + log::error("A2DP Source media task already running"); return false; } @@ -369,18 +371,18 @@ bool btif_a2dp_source_startup(void) { } static void btif_a2dp_source_startup_delayed() { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (!btif_a2dp_source_thread.EnableRealTimeScheduling()) { #if defined(__ANDROID__) - LOG(FATAL) << __func__ << ": unable to enable real time scheduling"; + log::fatal("unable to enable real time scheduling"); #endif } if (!bluetooth::audio::a2dp::init(&btif_a2dp_source_thread)) { if (btif_av_is_a2dp_offload_enabled()) { // TODO: BluetoothA2dp@1.0 is deprecated - LOG(WARNING) << __func__ << ": Using BluetoothA2dp HAL"; + log::warn("Using BluetoothA2dp HAL"); } else { - LOG(WARNING) << __func__ << ": Using legacy HAL"; + log::warn("Using legacy HAL"); btif_a2dp_control_init(); } } @@ -389,9 +391,8 @@ static void btif_a2dp_source_startup_delayed() { bool btif_a2dp_source_start_session(const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr(); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_STR(peer_address), + btif_a2dp_source_cb.StateStr()); btif_a2dp_source_setup_codec(peer_address); if (btif_a2dp_source_thread.DoInThread( FROM_HERE, @@ -400,21 +401,19 @@ bool btif_a2dp_source_start_session(const RawAddress& peer_address, return true; } else { // cannot set promise but triggers crash - LOG(FATAL) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr() - << " fails to context switch"; + log::fatal("peer_address={} state={} fails to context switch", + ADDRESS_TO_LOGGABLE_STR(peer_address), + btif_a2dp_source_cb.StateStr()); return false; } } static void btif_a2dp_source_start_session_delayed( const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr(); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_STR(peer_address), + btif_a2dp_source_cb.StateStr()); if (btif_a2dp_source_cb.State() != BtifA2dpSource::kStateRunning) { - LOG(ERROR) << __func__ << ": A2DP Source media task is not running"; + log::error("A2DP Source media task is not running"); peer_ready_promise.set_value(); return; } @@ -433,10 +432,10 @@ static void btif_a2dp_source_start_session_delayed( bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address, const RawAddress& new_peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": old_peer_address=" - << ADDRESS_TO_LOGGABLE_STR(old_peer_address) - << " new_peer_address=" << ADDRESS_TO_LOGGABLE_STR(new_peer_address) - << " state=" << btif_a2dp_source_cb.StateStr(); + log::info("old_peer_address={} new_peer_address={} state={}", + ADDRESS_TO_LOGGABLE_STR(old_peer_address), + ADDRESS_TO_LOGGABLE_STR(new_peer_address), + btif_a2dp_source_cb.StateStr()); CHECK(!new_peer_address.IsEmpty()); @@ -460,9 +459,8 @@ bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address, } bool btif_a2dp_source_end_session(const RawAddress& peer_address) { - LOG_INFO("%s: peer_address=%s state=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_a2dp_source_cb.StateStr().c_str()); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_a2dp_source_cb.StateStr()); btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_end_session_delayed, peer_address)); @@ -472,14 +470,13 @@ bool btif_a2dp_source_end_session(const RawAddress& peer_address) { static void btif_a2dp_source_end_session_delayed( const RawAddress& peer_address) { - LOG_INFO("%s: peer_address=%s state=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_a2dp_source_cb.StateStr().c_str()); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_a2dp_source_cb.StateStr()); if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateRunning) || (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateShuttingDown)) { btif_av_stream_stop(peer_address); } else { - LOG_ERROR("%s: A2DP Source media task is not running", __func__); + log::error("A2DP Source media task is not running"); } if (bluetooth::audio::a2dp::is_hal_enabled()) { bluetooth::audio::a2dp::end_session(); @@ -492,7 +489,7 @@ static void btif_a2dp_source_end_session_delayed( } void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) || (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateShuttingDown)) { @@ -509,7 +506,7 @@ void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) { static void btif_a2dp_source_shutdown_delayed( std::promise<void> shutdown_complete_promise) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); // Stop the timer btif_a2dp_source_cb.media_alarm.CancelAndWait(); @@ -529,7 +526,7 @@ static void btif_a2dp_source_shutdown_delayed( } void btif_a2dp_source_cleanup(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); // Make sure the source is shutdown std::promise<void> shutdown_complete_promise; @@ -543,7 +540,7 @@ void btif_a2dp_source_cleanup(void) { } static void btif_a2dp_source_cleanup_delayed(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); // Nothing to do } @@ -561,9 +558,8 @@ bool btif_a2dp_source_is_streaming(void) { } static void btif_a2dp_source_setup_codec(const RawAddress& peer_address) { - LOG_INFO("%s: peer_address=%s state=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_a2dp_source_cb.StateStr().c_str()); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_a2dp_source_cb.StateStr()); // Check to make sure the platform has 8 bits/byte since // we're using that in frame size calculations now. @@ -577,27 +573,26 @@ static void btif_a2dp_source_setup_codec(const RawAddress& peer_address) { static void btif_a2dp_source_setup_codec_delayed( const RawAddress& peer_address) { - LOG_INFO("%s: peer_address=%s state=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_a2dp_source_cb.StateStr().c_str()); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_a2dp_source_cb.StateStr()); tA2DP_ENCODER_INIT_PEER_PARAMS peer_params; bta_av_co_get_peer_params(peer_address, &peer_params); if (!bta_av_co_set_active_peer(peer_address)) { - LOG_ERROR("%s: Cannot stream audio: cannot set active peer to %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error("Cannot stream audio: cannot set active peer to {}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return; } btif_a2dp_source_cb.encoder_interface = bta_av_co_get_encoder_interface(); if (btif_a2dp_source_cb.encoder_interface == nullptr) { - LOG_ERROR("%s: Cannot stream audio: no source encoder interface", __func__); + log::error("Cannot stream audio: no source encoder interface"); return; } A2dpCodecConfig* a2dp_codec_config = bta_av_get_a2dp_current_codec(); if (a2dp_codec_config == nullptr) { - LOG_ERROR("%s: Cannot stream audio: current codec is not set", __func__); + log::error("Cannot stream audio: current codec is not set"); return; } @@ -615,7 +610,7 @@ static void btif_a2dp_source_setup_codec_delayed( } static void btif_a2dp_source_cleanup_codec() { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); // Must stop media task first before cleaning up the encoder btif_a2dp_source_stop_audio_req(); btif_a2dp_source_thread.DoInThread( @@ -623,7 +618,7 @@ static void btif_a2dp_source_cleanup_codec() { } static void btif_a2dp_source_cleanup_codec_delayed() { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (btif_a2dp_source_cb.encoder_interface != nullptr) { btif_a2dp_source_cb.encoder_interface->encoder_cleanup(); btif_a2dp_source_cb.encoder_interface = nullptr; @@ -631,14 +626,14 @@ static void btif_a2dp_source_cleanup_codec_delayed() { } void btif_a2dp_source_start_audio_req(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_start_event)); } void btif_a2dp_source_stop_audio_req(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_stop_event)); @@ -648,20 +643,18 @@ void btif_a2dp_source_encoder_user_config_update_req( const RawAddress& peer_address, const std::vector<btav_a2dp_codec_config_t>& codec_user_preferences, std::promise<void> peer_ready_promise) { - LOG(INFO) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr() << " " - << codec_user_preferences.size() << " codec_preference(s)"; + log::info("peer_address={} state={} {} codec_preference(s)", + ADDRESS_TO_LOGGABLE_STR(peer_address), + btif_a2dp_source_cb.StateStr(), codec_user_preferences.size()); if (!btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_encoder_user_config_update_event, peer_address, codec_user_preferences, std::move(peer_ready_promise)))) { // cannot set promise but triggers crash - LOG(FATAL) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr() - << " fails to context switch"; + log::fatal("peer_address={} state={} fails to context switch", + ADDRESS_TO_LOGGABLE_STR(peer_address), + btif_a2dp_source_cb.StateStr()); } } @@ -675,11 +668,10 @@ static void btif_a2dp_source_encoder_user_config_update_event( success = bta_av_co_set_codec_user_config(peer_address, codec_user_config, &restart_output); if (success) { - LOG(INFO) << __func__ << ": peer_address=" - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " state=" << btif_a2dp_source_cb.StateStr() - << " codec_preference={" << codec_user_config.ToString() - << "} restart_output=" << (restart_output ? "true" : "false"); + log::info( + "peer_address={} state={} codec_preference=[{}] restart_output={}", + ADDRESS_TO_LOGGABLE_STR(peer_address), btif_a2dp_source_cb.StateStr(), + codec_user_config.ToString(), (restart_output ? "true" : "false")); break; } } @@ -691,7 +683,7 @@ static void btif_a2dp_source_encoder_user_config_update_event( return; } if (!success) { - LOG(ERROR) << __func__ << ": cannot update codec user configuration(s)"; + log::error("cannot update codec user configuration(s)"); } if (!peer_address.IsEmpty() && peer_address == btif_av_source_active_peer()) { // No more actions needed with remote, and if succeed, user had changed the @@ -705,7 +697,7 @@ static void btif_a2dp_source_encoder_user_config_update_event( void btif_a2dp_source_feeding_update_req( const btav_a2dp_codec_config_t& codec_audio_config) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_feeding_update_event, codec_audio_config)); @@ -713,14 +705,14 @@ void btif_a2dp_source_feeding_update_req( static void btif_a2dp_source_audio_feeding_update_event( const btav_a2dp_codec_config_t& codec_audio_config) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (!bta_av_co_set_codec_audio_config(codec_audio_config)) { - LOG_ERROR("%s: cannot update codec audio feeding parameters", __func__); + log::error("cannot update codec audio feeding parameters"); } } void btif_a2dp_source_on_idle(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return; /* Make sure media task is stopped */ @@ -728,16 +720,16 @@ void btif_a2dp_source_on_idle(void) { } void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); btif_a2dp_source_cb.sw_audio_is_encoding = false; // allow using this API for other (acknowledgement and stopping media task) // than suspend if (p_av_suspend != nullptr && p_av_suspend->status != BTA_AV_SUCCESS) { - LOG_ERROR("%s: A2DP stop failed: status=%d, initiator=%s", __func__, - p_av_suspend->status, - (p_av_suspend->initiator ? "true" : "false")); + log::error("A2DP stop failed: status={}, initiator={}", + p_av_suspend->status, + (p_av_suspend->initiator ? "true" : "false")); if (p_av_suspend->initiator) { if (bluetooth::audio::a2dp::is_hal_enabled()) { bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE); @@ -764,7 +756,7 @@ void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) { } void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return; @@ -772,9 +764,9 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { // check for status failures if (p_av_suspend->status != BTA_AV_SUCCESS) { - LOG_WARN("%s: A2DP suspend failed: status=%d, initiator=%s", __func__, - p_av_suspend->status, - (p_av_suspend->initiator ? "true" : "false")); + log::warn("A2DP suspend failed: status={}, initiator={}", + p_av_suspend->status, + (p_av_suspend->initiator ? "true" : "false")); if (p_av_suspend->initiator) { if (bluetooth::audio::a2dp::is_hal_enabled()) { bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE); @@ -798,15 +790,15 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { /* when true media task discards any tx frames */ void btif_a2dp_source_set_tx_flush(bool enable) { - LOG_INFO("%s: enable=%s state=%s", __func__, (enable) ? "true" : "false", - btif_a2dp_source_cb.StateStr().c_str()); + log::info("enable={} state={}", (enable) ? "true" : "false", + btif_a2dp_source_cb.StateStr()); btif_a2dp_source_cb.tx_flush = enable; } static void btif_a2dp_source_audio_tx_start_event(void) { - LOG_INFO("%s: streaming %s state=%s", __func__, - btif_a2dp_source_is_streaming() ? "true" : "false", - btif_a2dp_source_cb.StateStr().c_str()); + log::info("streaming {} state={}", + btif_a2dp_source_is_streaming() ? "true" : "false", + btif_a2dp_source_cb.StateStr()); if (btif_av_is_a2dp_offload_running()) return; @@ -814,8 +806,9 @@ static void btif_a2dp_source_audio_tx_start_event(void) { CHECK(btif_a2dp_source_cb.encoder_interface != nullptr); btif_a2dp_source_cb.encoder_interface->feeding_reset(); - LOG_VERBOSE("%s: starting timer %" PRIu64 " ms", __func__, - btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms()); + log::verbose( + "starting timer {} ms", + btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms()); /* audio engine starting, reset tx suspended flag */ btif_a2dp_source_cb.tx_flush = false; @@ -845,9 +838,9 @@ static void btif_a2dp_source_audio_tx_start_event(void) { } static void btif_a2dp_source_audio_tx_stop_event(void) { - LOG_INFO("%s: streaming %s state=%s", __func__, - btif_a2dp_source_is_streaming() ? "true" : "false", - btif_a2dp_source_cb.StateStr().c_str()); + log::info("streaming {} state={}", + btif_a2dp_source_is_streaming() ? "true" : "false", + btif_a2dp_source_cb.StateStr()); if (btif_av_is_a2dp_offload_running()) return; if (!btif_a2dp_source_is_streaming()) return; @@ -916,7 +909,7 @@ static void btif_a2dp_source_audio_handle_timer(void) { log_tstamps_us("A2DP Source tx scheduling timer", timestamp_us); if (!btif_a2dp_source_is_streaming()) { - LOG_ERROR("%s: ERROR Media task Scheduled after Suspend", __func__); + log::error("ERROR Media task Scheduled after Suspend"); return; } CHECK(btif_a2dp_source_cb.encoder_interface != nullptr); @@ -947,8 +940,7 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) { } if (btif_a2dp_source_cb.sw_audio_is_encoding && bytes_read < len) { - LOG_WARN("%s: UNDERFLOW: ONLY READ %d BYTES OUT OF %d", __func__, - bytes_read, len); + log::warn("UNDERFLOW: ONLY READ {} BYTES OUT OF {}", bytes_read, len); btif_a2dp_source_cb.stats.media_read_total_underflow_bytes += (len - bytes_read); btif_a2dp_source_cb.stats.media_read_total_underflow_count++; @@ -975,7 +967,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, /* Check if the transmission queue has been flushed */ if (btif_a2dp_source_cb.tx_flush) { - LOG_VERBOSE("%s: tx suspended, discarded frame", __func__); + log::verbose("tx suspended, discarded frame"); btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages += fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue); @@ -990,9 +982,9 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, // TODO: Using frames_n here is probably wrong: should be "+ 1" instead. if (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue) + frames_n > btif_a2dp_source_dynamic_audio_buffer_size) { - LOG_WARN("%s: TX queue buffer size now=%u adding=%u max=%d", __func__, - (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue), - (uint32_t)frames_n, btif_a2dp_source_dynamic_audio_buffer_size); + log::warn("TX queue buffer size now={} adding={} max={}", + (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue), + (uint32_t)frames_n, btif_a2dp_source_dynamic_audio_buffer_size); // Keep track of drop-outs btif_a2dp_source_cb.stats.tx_queue_dropouts++; btif_a2dp_source_cb.stats.tx_queue_last_dropouts_us = now_us; @@ -1022,7 +1014,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, RawAddress peer_bda = btif_av_source_active_peer(); tBTM_STATUS status = BTM_ReadRSSI(peer_bda, btm_read_rssi_cb); if (status != BTM_CMD_STARTED) { - LOG_WARN("%s: Cannot read RSSI: status %d", __func__, status); + log::warn("Cannot read RSSI: status {}", status); } // Intel controllers don't handle ReadFailedContactCounter very well, it @@ -1035,15 +1027,14 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, status = BTM_ReadFailedContactCounter(peer_bda, btm_read_failed_contact_counter_cb); if (status != BTM_CMD_STARTED) { - LOG_WARN("%s: Cannot read Failed Contact Counter: status %d", __func__, - status); + log::warn("Cannot read Failed Contact Counter: status {}", status); } #endif status = BTM_ReadTxPower(peer_bda, BT_TRANSPORT_BR_EDR, btm_read_tx_power_cb); if (status != BTM_CMD_STARTED) { - LOG_WARN("%s: Cannot read Tx Power: status %d", __func__, status); + log::warn("Cannot read Tx Power: status {}", status); } } @@ -1060,7 +1051,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n, static void btif_a2dp_source_audio_tx_flush_event(void) { /* Flush all enqueued audio buffers (encoded) */ - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); if (btif_av_is_a2dp_offload_running()) return; if (btif_a2dp_source_cb.encoder_interface != nullptr) @@ -1078,7 +1069,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) { } static bool btif_a2dp_source_audio_tx_flush_req(void) { - LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str()); + log::info("state={}", btif_a2dp_source_cb.StateStr()); btif_a2dp_source_thread.DoInThread( FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_flush_event)); @@ -1104,9 +1095,9 @@ BT_HDR* btif_a2dp_source_audio_readbuf(void) { static void log_tstamps_us(const char* comment, uint64_t timestamp_us) { static uint64_t prev_us = 0; - LOG_VERBOSE("%s: [%s] ts %08" PRIu64 ", diff : %08" PRIu64 ", queue sz %zu", - __func__, comment, timestamp_us, timestamp_us - prev_us, - fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue)); + log::verbose("[{}] ts {:08}, diff : {:08}, queue sz {}", comment, + timestamp_us, timestamp_us - prev_us, + fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue)); prev_us = timestamp_us; } @@ -1378,14 +1369,13 @@ void btif_a2dp_source_set_dynamic_audio_buffer_size( static void btm_read_rssi_cb(void* data) { if (data == nullptr) { - LOG_ERROR("%s: Read RSSI request timed out", __func__); + log::error("Read RSSI request timed out"); return; } tBTM_RSSI_RESULT* result = (tBTM_RSSI_RESULT*)data; if (result->status != BTM_SUCCESS) { - LOG_ERROR("%s: unable to read remote RSSI (status %d)", __func__, - result->status); + log::error("unable to read remote RSSI (status {})", result->status); return; } @@ -1393,48 +1383,47 @@ static void btm_read_rssi_cb(void* data) { bluetooth::common::kUnknownConnectionHandle, result->hci_status, result->rssi); - LOG_WARN("%s: device: %s, rssi: %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->rssi); + log::warn("device: {}, rssi: {}", ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), + result->rssi); } static void btm_read_failed_contact_counter_cb(void* data) { if (data == nullptr) { - LOG_ERROR("%s: Read Failed Contact Counter request timed out", __func__); + log::error("Read Failed Contact Counter request timed out"); return; } tBTM_FAILED_CONTACT_COUNTER_RESULT* result = (tBTM_FAILED_CONTACT_COUNTER_RESULT*)data; if (result->status != BTM_SUCCESS) { - LOG_ERROR("%s: unable to read Failed Contact Counter (status %d)", __func__, - result->status); + log::error("unable to read Failed Contact Counter (status {})", + result->status); return; } log_read_failed_contact_counter_result( result->rem_bda, bluetooth::common::kUnknownConnectionHandle, result->hci_status, result->failed_contact_counter); - LOG_WARN("%s: device: %s, Failed Contact Counter: %u", __func__, - ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), - result->failed_contact_counter); + log::warn("device: {}, Failed Contact Counter: {}", + ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), + result->failed_contact_counter); } static void btm_read_tx_power_cb(void* data) { if (data == nullptr) { - LOG_ERROR("%s: Read Tx Power request timed out", __func__); + log::error("Read Tx Power request timed out"); return; } tBTM_TX_POWER_RESULT* result = (tBTM_TX_POWER_RESULT*)data; if (result->status != BTM_SUCCESS) { - LOG_ERROR("%s: unable to read Tx Power (status %d)", __func__, - result->status); + log::error("unable to read Tx Power (status {})", result->status); return; } log_read_tx_power_level_result(result->rem_bda, bluetooth::common::kUnknownConnectionHandle, result->hci_status, result->tx_power); - LOG_WARN("%s: device: %s, Tx Power: %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->tx_power); + log::warn("device: {}, Tx Power: {}", + ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->tx_power); } diff --git a/system/btif/src/btif_av.cc b/system/btif/src/btif_av.cc index 2ce600ef145..90d0361ae92 100644 --- a/system/btif/src/btif_av.cc +++ b/system/btif/src/btif_av.cc @@ -25,6 +25,7 @@ #include <base/functional/bind.h> #include <base/logging.h> #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <frameworks/proto_logging/stats/enums/bluetooth/a2dp/enums.pb.h> #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h> @@ -63,6 +64,8 @@ #include "stack/include/main_thread.h" #include "types/raw_address.h" +using namespace bluetooth; + /***************************************************************************** * Constants & Macros *****************************************************************************/ @@ -454,11 +457,11 @@ class BtifAvSource { } BtifAvPeer* peer = FindPeer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: peer is null", __func__); + log::warn("peer is null"); return false; } if (!peer->IsConnected()) { - LOG_WARN("%s: peer is not connected", __func__); + log::warn("peer is not connected"); return false; } return peer->IsInSilenceMode(); @@ -475,15 +478,14 @@ class BtifAvSource { if (peer_address.IsEmpty()) { return false; } - LOG_INFO("%s: peer: %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("peer: {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); BtifAvPeer* peer = FindPeer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: peer is null", __func__); + log::warn("peer is null"); return false; } if (!peer->IsConnected()) { - LOG_WARN("%s: peer is not connected", __func__); + log::warn("peer is not connected"); return false; } peer->SetSilence(silence); @@ -499,22 +501,19 @@ class BtifAvSource { */ bool SetActivePeer(const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __PRETTY_FUNCTION__ << ": peer: " - << ADDRESS_TO_LOGGABLE_STR(peer_address); + log::info("peer: {}", ADDRESS_TO_LOGGABLE_STR(peer_address)); if (active_peer_ == peer_address) { peer_ready_promise.set_value(); return true; // Nothing has changed } if (peer_address.IsEmpty()) { - LOG_VERBOSE("%s: peer address is empty, shutdown the Audio source", - __func__); + log::verbose("peer address is empty, shutdown the Audio source"); if (!btif_av_src_sink_coexist_enabled() || (btif_av_src_sink_coexist_enabled() && btif_av_sink_active_peer().IsEmpty())) { if (!bta_av_co_set_active_peer(peer_address)) { - LOG(WARNING) << __func__ - << ": unable to set active peer to empty in BtaAvCo"; + log::warn("unable to set active peer to empty in BtaAvCo"); } } @@ -526,7 +525,7 @@ class BtifAvSource { using namespace std::chrono_literals; if (shutdown_complete_future.wait_for(1s) == std::future_status::timeout) { - LOG_ERROR("Timed out waiting for A2DP source shutdown to complete."); + log::error("Timed out waiting for A2DP source shutdown to complete."); } active_peer_ = peer_address; peer_ready_promise.set_value(); @@ -536,9 +535,8 @@ class BtifAvSource { if (btif_av_src_sink_coexist_enabled()) btif_av_sink_delete_active_peer(); BtifAvPeer* peer = FindPeer(peer_address); if (peer == nullptr || !peer->IsConnected()) { - LOG(ERROR) << __func__ << ": Error setting " - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " as active Source peer"; + log::error("Error setting {} as active Source peer", + ADDRESS_TO_LOGGABLE_STR(peer_address)); peer_ready_promise.set_value(); return false; } @@ -554,14 +552,13 @@ class BtifAvSource { void DeleteActivePeer(void) { std::promise<void> shutdown_complete_promise; - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (btif_av_sink_active_peer().IsEmpty()) { if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) { - LOG_WARN("%s : unable to set active peer to empty in BtaAvCo", - __func__); + log::warn("unable to set active peer to empty in BtaAvCo"); } } else { - LOG_WARN("%s : there is an active peer as source role", __func__); + log::warn("there is an active peer as source role"); } btif_a2dp_source_end_session(active_peer_); btif_a2dp_source_shutdown(std::move(shutdown_complete_promise)); @@ -680,22 +677,19 @@ class BtifAvSink { */ bool SetActivePeer(const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG(INFO) << __PRETTY_FUNCTION__ << ": peer: " - << ADDRESS_TO_LOGGABLE_STR(peer_address); + log::info("peer: {}", ADDRESS_TO_LOGGABLE_STR(peer_address)); if (active_peer_ == peer_address) { peer_ready_promise.set_value(); return true; // Nothing has changed } if (peer_address.IsEmpty()) { - LOG_VERBOSE("%s: peer address is empty, shutdown the Audio sink", - __func__); + log::verbose("peer address is empty, shutdown the Audio sink"); if (!btif_av_src_sink_coexist_enabled() || (btif_av_src_sink_coexist_enabled() && btif_av_source_active_peer().IsEmpty())) { if (!bta_av_co_set_active_peer(peer_address)) { - LOG(WARNING) << __func__ - << ": unable to set active peer to empty in BtaAvCo"; + log::warn("unable to set active peer to empty in BtaAvCo"); } } @@ -711,9 +705,8 @@ class BtifAvSink { } BtifAvPeer* peer = FindPeer(peer_address); if (peer == nullptr || !peer->IsConnected()) { - LOG(ERROR) << __func__ << ": Error setting " - << ADDRESS_TO_LOGGABLE_STR(peer_address) - << " as active Sink peer"; + log::error("Error setting {} as active Sink peer", + ADDRESS_TO_LOGGABLE_STR(peer_address)); peer_ready_promise.set_value(); return false; } @@ -723,21 +716,20 @@ class BtifAvSink { // cannot set promise but need to be handled within restart_session return false; } - LOG(INFO) << "Setting the active peer to peer address %s" - << ADDRESS_TO_LOGGABLE_STR(peer_address); + log::info("Setting the active peer to peer address {}", + ADDRESS_TO_LOGGABLE_STR(peer_address)); active_peer_ = peer_address; return true; } void DeleteActivePeer(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (btif_av_source_active_peer().IsEmpty()) { if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) { - LOG(WARNING) << __func__ - << ": unable to set active peer to empty in BtaAvCo"; + log::warn("unable to set active peer to empty in BtaAvCo"); } } else { - LOG(WARNING) << __func__ << ": there is an active peer as sink role"; + log::warn("there is an active peer as sink role"); } btif_a2dp_sink_end_session(active_peer_); btif_a2dp_sink_shutdown(); @@ -1099,17 +1091,16 @@ const RawAddress& BtifAvPeer::ActivePeerAddress() const { if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) { RawAddress addr = btif_av_sink.ActivePeer(); if (RawAddress::kEmpty == addr) { - LOG(WARNING) << __PRETTY_FUNCTION__ << ": A2DP peer " - << btif_av_source.ActivePeer() << " is Sink"; + log::warn("A2DP peer {} is Sink", + ADDRESS_TO_LOGGABLE_STR(btif_av_source.ActivePeer())); return btif_av_source.ActivePeer(); } - LOG(WARNING) << __PRETTY_FUNCTION__ << ": A2DP peer " - << btif_av_sink.ActivePeer() << " is Source"; + log::warn("A2DP peer {} is Source", + ADDRESS_TO_LOGGABLE_STR(btif_av_sink.ActivePeer())); return btif_av_sink.ActivePeer(); } - LOG(FATAL) << __PRETTY_FUNCTION__ << ": A2DP peer " - << ADDRESS_TO_LOGGABLE_STR(PeerAddress()) - << " is neither Source nor Sink"; + log::fatal("A2DP peer {} is neither Source nor Sink", + ADDRESS_TO_LOGGABLE_STR(PeerAddress())); return RawAddress::kEmpty; } @@ -1131,8 +1122,7 @@ bt_status_t BtifAvSource::Init( const std::vector<btav_a2dp_codec_config_t>& codec_priorities, const std::vector<btav_a2dp_codec_config_t>& offloading_preference, std::vector<btav_a2dp_codec_info_t>* supported_codecs) { - LOG_INFO("%s: max_connected_audio_devices=%d", __PRETTY_FUNCTION__, - max_connected_audio_devices); + log::info("max_connected_audio_devices={}", max_connected_audio_devices); if (enabled_) return BT_STATUS_SUCCESS; CleanupAllPeers(); max_connected_peers_ = max_connected_audio_devices; @@ -1140,7 +1130,7 @@ bt_status_t BtifAvSource::Init( /* A2DP OFFLOAD */ a2dp_offload_enabled_ = GetInterfaceToProfiles()->config->isA2DPOffloadEnabled(); - LOG_VERBOSE("a2dp_offload.enable = %d", a2dp_offload_enabled_); + log::verbose("a2dp_offload.enable = {}", a2dp_offload_enabled_); callbacks_ = callbacks; if (a2dp_offload_enabled_) { @@ -1162,7 +1152,7 @@ bt_status_t BtifAvSource::Init( } void BtifAvSource::Cleanup() { - LOG_INFO("%s", __PRETTY_FUNCTION__); + log::info(""); if (!enabled_) return; enabled_ = false; @@ -1211,8 +1201,8 @@ BtifAvPeer* BtifAvSource::FindPeerByPeerId(uint8_t peer_id) { BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address, tBTA_AV_HNDL bta_handle) { std::unique_lock<std::mutex> lock1(mutex_); - LOG_VERBOSE("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); + log::verbose("peer_address={} bta_handle=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); BtifAvPeer* peer = FindPeer(peer_address); if (peer != nullptr) return peer; @@ -1230,10 +1220,10 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address, } } if (peer_id == kPeerIdMax) { - LOG_ERROR( - "%s: Cannot create peer for peer_address=%s : " - "cannot allocate unique Peer ID", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error( + "Cannot create peer for peer_address={} : cannot allocate unique Peer " + "ID", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return nullptr; } @@ -1241,18 +1231,17 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address, if (bta_handle == kBtaHandleUnknown) { auto it = peer_id2bta_handle_.find(peer_id); if (it == peer_id2bta_handle_.end() || it->second == kBtaHandleUnknown) { - LOG_ERROR( - "%s: Cannot create peer for peer_address=%s : " - "cannot convert Peer ID=%d to unique BTA Handle", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id); + log::error( + "Cannot create peer for peer_address={} : cannot convert Peer ID={} " + "to unique BTA Handle", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id); return nullptr; } bta_handle = it->second; } - LOG_INFO("%s: Create peer: peer_address=%s bta_handle=0x%x peer_id=%d", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), - bta_handle, peer_id); + log::info("Create peer: peer_address={} bta_handle=0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle, peer_id); peer = new BtifAvPeer(peer_address, AVDT_TSEP_SNK, bta_handle, peer_id); peers_.insert(std::make_pair(peer_address, peer)); peer->Init(); @@ -1262,9 +1251,9 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address, bool BtifAvSource::AllowedToConnect(const RawAddress& peer_address) const { int connected = 0; if (btif_av_src_sink_coexist_enabled() && invalid_peer_check_) { - LOG_INFO( - "invalid_peer_check_ so allow to connect here, when" - " BTA_AV_OPEN_EVT coming, would check again!"); + log::info( + "invalid_peer_check_ so allow to connect here, when BTA_AV_OPEN_EVT " + "coming, would check again!"); return true; } @@ -1289,9 +1278,8 @@ bool BtifAvSource::AllowedToConnect(const RawAddress& peer_address) const { } } if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) { - LOG_INFO("%s: connected=%d, max_connected_peers_=%d, sink_peers=%d", - __PRETTY_FUNCTION__, connected, max_connected_peers_, - (int)btif_av_sink.Peers().size()); + log::info("connected={}, max_connected_peers_={}, sink_peers={}", connected, + max_connected_peers_, (int)btif_av_sink.Peers().size()); /* if source device connected, don't connect sink device */ if (connected >= max_connected_peers_ || !btif_av_sink.Peers().empty()) { @@ -1318,8 +1306,8 @@ void BtifAvSource::DeleteIdlePeers() { BtifAvPeer* peer = it->second; auto prev_it = it++; if (!peer->CanBeDeleted()) continue; - LOG_INFO("%s: Deleting idle peer: %s bta_handle=0x%x", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle()); + log::info("Deleting idle peer: {} bta_handle=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle()); peer->Cleanup(); peers_.erase(prev_it); delete peer; @@ -1359,15 +1347,14 @@ void BtifAvSource::BtaHandleRegistered(uint8_t peer_id, BtifAvPeer* peer = FindPeerByPeerId(peer_id); if (peer != nullptr && peer->BtaHandle() != bta_handle) { if (peer->BtaHandle() == kBtaHandleUnknown) { - LOG_VERBOSE("%s: Assign peer: peer_address=%s bta_handle=0x%x peer_id=%d", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle, - peer_id); + log::verbose("Assign peer: peer_address={} bta_handle=0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle, + peer_id); } else { - LOG_WARN( - "%s: Correct peer: peer_address=%s bta_handle=0x%x->0x%x peer_id=%d", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->BtaHandle(), bta_handle, peer_id); + log::warn( + "Correct peer: peer_address={} bta_handle=0x{:x}->0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle(), + bta_handle, peer_id); } peer->SetBtaHandle(bta_handle); } @@ -1378,24 +1365,23 @@ BtifAvPeer* BtifAvSource::popPeer(const RawAddress& peer_address) { if (it == peers_.end()) return nullptr; BtifAvPeer* peer = it->second; peers_.erase(it); - LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->StateMachine().StateId()); + log::info("peer_address={}, state={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + peer->StateMachine().StateId()); return peer; } void BtifAvSource::AddPeer(BtifAvPeer* peer) { - LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->StateMachine().StateId()); + log::info("peer_address={}, state={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + peer->StateMachine().StateId()); peers_.insert(std::make_pair(peer->PeerAddress(), peer)); } BtifAvSink::~BtifAvSink() { CleanupAllPeers(); } bt_status_t BtifAvSink::Init(btav_sink_callbacks_t* callbacks, int max_connected_audio_devices) { - LOG_INFO("%s(max_connected_audio_devices=%d)", __PRETTY_FUNCTION__, - max_connected_audio_devices); + log::info("(max_connected_audio_devices={})", max_connected_audio_devices); if (enabled_) return BT_STATUS_SUCCESS; CleanupAllPeers(); @@ -1420,7 +1406,7 @@ bt_status_t BtifAvSink::Init(btav_sink_callbacks_t* callbacks, } void BtifAvSink::Cleanup() { - LOG_INFO("%s", __PRETTY_FUNCTION__); + log::info(""); if (!enabled_) return; enabled_ = false; @@ -1468,8 +1454,8 @@ BtifAvPeer* BtifAvSink::FindPeerByPeerId(uint8_t peer_id) { BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address, tBTA_AV_HNDL bta_handle) { - LOG_VERBOSE("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); + log::verbose("peer_address={} bta_handle=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); BtifAvPeer* peer = FindPeer(peer_address); if (peer != nullptr) return peer; @@ -1488,10 +1474,10 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address, } } if (peer_id == kPeerIdMax) { - LOG_ERROR( - "%s: Cannot create peer for peer_address=%s : " - "cannot allocate unique Peer ID", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error( + "Cannot create peer for peer_address={} : cannot allocate unique Peer " + "ID", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return nullptr; } @@ -1499,18 +1485,17 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address, if (bta_handle == kBtaHandleUnknown) { auto it = peer_id2bta_handle_.find(peer_id); if (it == peer_id2bta_handle_.end() || it->second == kBtaHandleUnknown) { - LOG_ERROR( - "%s: Cannot create peer for peer_address=%s : " - "cannot convert Peer ID=%d to unique BTA Handle", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id); + log::error( + "Cannot create peer for peer_address={} : cannot convert Peer ID={} " + "to unique BTA Handle", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id); return nullptr; } bta_handle = it->second; } - LOG_INFO("%s: Create peer: peer_address=%s bta_handle=0x%x peer_id=%d", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), - bta_handle, peer_id); + log::info("Create peer: peer_address={} bta_handle=0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle, peer_id); peer = new BtifAvPeer(peer_address, AVDT_TSEP_SRC, bta_handle, peer_id); peers_.insert(std::make_pair(peer_address, peer)); peer->Init(); @@ -1521,9 +1506,9 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const { int connected = 0; if (btif_av_src_sink_coexist_enabled() && invalid_peer_check_) { - LOG_INFO( - "invalid_peer_check_ so allow to connect here, when" - " BTA_AV_OPEN_EVT coming, would check again!"); + log::info( + "invalid_peer_check_ so allow to connect here, when BTA_AV_OPEN_EVT " + "coming, would check again!"); return true; } // Count peers that are in the process of connecting or already connected @@ -1544,10 +1529,11 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const { case BtifAvStateMachine::kStateIdle: if ((btif_a2dp_sink_get_audio_track() != nullptr) && (peer->PeerAddress() != peer_address)) { - LOG_INFO("%s: there is another peer with audio track(%p), another=%s, peer=%s", - __PRETTY_FUNCTION__, btif_a2dp_sink_get_audio_track(), - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info( + "there is another peer with audio track({}), another={}, peer={}", + fmt::ptr(btif_a2dp_sink_get_audio_track()), + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); connected++; } break; @@ -1556,9 +1542,9 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const { } } if (btif_av_both_enable()) { - LOG_INFO("connected=%d, max_connected_peers_=%d, source_peers=%d", - connected, max_connected_peers_, - (int)btif_av_source.Peers().size()); + log::info("connected={}, max_connected_peers_={}, source_peers={}", + connected, max_connected_peers_, + (int)btif_av_source.Peers().size()); /* if source device connected, don't connect sink device */ return (connected < max_connected_peers_) && btif_av_source.Peers().empty(); } @@ -1581,8 +1567,8 @@ void BtifAvSink::DeleteIdlePeers() { BtifAvPeer* peer = it->second; auto prev_it = it++; if (!peer->CanBeDeleted()) continue; - LOG_INFO("%s: Deleting idle peer: %s bta_handle=0x%x", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle()); + log::info("Deleting idle peer: {} bta_handle=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle()); peer->Cleanup(); peers_.erase(prev_it); delete peer; @@ -1621,15 +1607,14 @@ void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) { BtifAvPeer* peer = FindPeerByPeerId(peer_id); if (peer != nullptr && peer->BtaHandle() != bta_handle) { if (peer->BtaHandle() == kBtaHandleUnknown) { - LOG_VERBOSE("%s: Assign peer: peer_address=%s bta_handle=0x%x peer_id=%d", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle, - peer_id); + log::verbose("Assign peer: peer_address={} bta_handle=0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle, + peer_id); } else { - LOG_WARN( - "%s: Correct peer: peer_address=%s bta_handle=0x%x->0x%x peer_id=%d", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->BtaHandle(), bta_handle, peer_id); + log::warn( + "Correct peer: peer_address={} bta_handle=0x{:x}->0x{:x} peer_id={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle(), + bta_handle, peer_id); } peer->SetBtaHandle(bta_handle); } @@ -1640,22 +1625,21 @@ BtifAvPeer* BtifAvSink::popPeer(const RawAddress& peer_address) { if (it == peers_.end()) return nullptr; BtifAvPeer* peer = it->second; peers_.erase(it); - LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->StateMachine().StateId()); + log::info("peer_address={}, state={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + peer->StateMachine().StateId()); return peer; } void BtifAvSink::AddPeer(BtifAvPeer* peer) { - LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->StateMachine().StateId()); + log::info("peer_address={}, state={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + peer->StateMachine().StateId()); peers_.insert(std::make_pair(peer->PeerAddress(), peer)); } void BtifAvStateMachine::StateIdle::OnEnter() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); peer_.SetEdr(0); peer_.ClearAllFlags(); @@ -1691,16 +1675,14 @@ void BtifAvStateMachine::StateIdle::OnEnter() { } void BtifAvStateMachine::StateIdle::OnExit() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); } bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { - LOG_VERBOSE( - "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - logbool(peer_.IsActivePeer()).c_str()); + log::verbose("Peer {} : event={} flags={} active_peer={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + logbool(peer_.IsActivePeer())); switch (event) { case BTA_AV_ENABLE_EVT: @@ -1737,10 +1719,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { if (!can_connect) sink_disconnect_src(peer_.PeerAddress()); } if (!can_connect) { - LOG_ERROR( - "%s: Cannot connect to peer %s: too many connected " - "peers", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::error("Cannot connect to peer {}: too many connected peers", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); if (peer_.SelfInitiatedConnection()) { btif_queue_advance(); } @@ -1774,10 +1754,9 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { // connection first and then immediately initiate the AV connection // // TODO: We may need to do this only on an AVRCP Play. FixMe - LOG_WARN("%s: Peer %s : event=%s received without AV", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : event={} received without AV", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); bool can_connect = true; // Check whether connection is allowed @@ -1799,10 +1778,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { } } if (!can_connect) { - LOG_ERROR( - "%s: Cannot connect to peer %s: too many connected " - "peers", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::error("Cannot connect to peer {}: too many connected peers", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); break; } /* if peer is source, then start timer for sink connect to src */ @@ -1852,12 +1829,11 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { tBTA_AV_STATUS status = p_bta_data->open.status; bool can_connect = true; - LOG_INFO( - "%s: Peer %s : event=%s flags=%s status=%d(%s) edr=0x%x", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - status, (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED", - p_bta_data->open.edr); + log::info("Peer {} : event={} flags={} status={}({}) edr=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), status, + (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED", + p_bta_data->open.edr); btif_report_connection_state( peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTING, @@ -1866,15 +1842,15 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { if (p_bta_data->open.status == BTA_AV_SUCCESS) { peer_.SetEdr(p_bta_data->open.edr); if (btif_av_src_sink_coexist_enabled()) { - LOG_VERBOSE("%s: Peer %s sep=%d, open_sep=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - peer_.PeerSep(), p_bta_data->open.sep); + log::verbose("Peer {} sep={}, open_sep={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + peer_.PeerSep(), p_bta_data->open.sep); /* if peer is wrong sep type, move it to BtifAvSxxx */ if (peer_.PeerSep() == AVDT_TSEP_SNK) { - LOG_VERBOSE("set source invalid_peer_check as false"); + log::verbose("set source invalid_peer_check as false"); btif_av_source.SetInvalidPeerCheck(false); } else { - LOG_VERBOSE("set sink invalid_peer_check as false"); + log::verbose("set sink invalid_peer_check as false"); btif_av_sink.SetInvalidPeerCheck(false); } if (peer_.PeerSep() != p_bta_data->open.sep) { @@ -1883,21 +1859,21 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { tmp_peer = btif_av_source.popPeer(peer_.PeerAddress()); if (peer_.PeerAddress() != tmp_peer->PeerAddress()) - LOG_ERROR("error, not same peer"); + log::error("error, not same peer"); btif_av_sink.AddPeer(tmp_peer); } else { tmp_peer = btif_av_sink.popPeer(peer_.PeerAddress()); if (peer_.PeerAddress() != tmp_peer->PeerAddress()) - LOG_ERROR("error, not same peer"); + log::error("error, not same peer"); btif_av_source.AddPeer(tmp_peer); } peer_.SetSep(p_bta_data->open.sep); } if (btif_rc_is_connected_peer(peer_.PeerAddress())) { - LOG_VERBOSE("%s, AVRCP connected, update avrc sep", __func__); + log::verbose("AVRCP connected, update avrc sep"); BTA_AvSetPeerSep(peer_.PeerAddress(), peer_.PeerSep()); } btif_rc_check_pending_cmd(p_bta_data->open.bd_addr); @@ -1909,11 +1885,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { : btif_av_sink.AllowedToConnect(peer_.PeerAddress()); if (!can_connect) { - LOG_ERROR( - "%s: Cannot connect to peer %s: too many connected " - "peers", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::error("Cannot connect to peer {}: too many connected peers", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); if (peer_.IsSink()) { src_disconnect_sink(peer_.PeerAddress()); @@ -1963,10 +1936,9 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { case BTIF_AV_AVRCP_CLOSE_EVT: case BTA_AV_RC_CLOSE_EVT: { - LOG_VERBOSE("%s: Peer %s : event=%s : Stopping AV timer", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::verbose("Peer {} : event={} : Stopping AV timer", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); alarm_cancel(peer_.AvOpenOnRcTimer()); if (event == BTA_AV_RC_CLOSE_EVT) { @@ -1975,17 +1947,16 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { } break; case BTIF_AV_OFFLOAD_START_REQ_EVT: - LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::error("Peer {} : event={}: stream is not Opened", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); break; default: - LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Unhandled event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); return false; } @@ -1993,8 +1964,7 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) { } void BtifAvStateMachine::StateOpening::OnEnter() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); // Inform the application that we are entering connecting state if (btif_av_both_enable()) { @@ -2007,17 +1977,15 @@ void BtifAvStateMachine::StateOpening::OnEnter() { } void BtifAvStateMachine::StateOpening::OnExit() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); } bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, void* p_data) { - LOG_VERBOSE( - "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - logbool(peer_.IsActivePeer()).c_str()); + log::verbose("Peer {} : event={} flags={} active_peer={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + logbool(peer_.IsActivePeer())); switch (event) { case BTIF_AV_STOP_STREAM_REQ_EVT: @@ -2028,11 +1996,10 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, // ACL Disconnected needs to be handled only in Opening state, because // it is in an intermediate state. In other states we can handle // incoming/outgoing connect/disconnect requests. - LOG_WARN( - "%s: Peer %s : event=%s: transitioning to Idle due to ACL " - "Disconnect", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn( + "Peer {} : event={}: transitioning to Idle due to ACL Disconnect", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: A2DP_CONNECTION_ACL_DISCONNECTED, 1); @@ -2045,10 +2012,9 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, } break; case BTA_AV_REJECT_EVT: - LOG_WARN("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::warn("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: A2DP_CONNECTION_REJECT_EVT, 1); @@ -2066,26 +2032,25 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, int av_state; tBTA_AV_STATUS status = p_bta_data->open.status; - LOG_INFO( - "%s: Peer %s : event=%s flags=%s status=%d(%s) edr=0x%x", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - status, (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED", - p_bta_data->open.edr); + log::info("Peer {} : event={} flags={} status={}({}) edr=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), status, + (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED", + p_bta_data->open.edr); if (p_bta_data->open.status == BTA_AV_SUCCESS) { av_state = BtifAvStateMachine::kStateOpened; peer_.SetEdr(p_bta_data->open.edr); if (btif_av_src_sink_coexist_enabled()) { - LOG_VERBOSE("%s: Peer %s sep=%d, open_sep=%d", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - peer_.PeerSep(), p_bta_data->open.sep); + log::verbose("Peer {} sep={}, open_sep={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + peer_.PeerSep(), p_bta_data->open.sep); /* if peer is wrong sep type, move it to BtifAvSxxx */ if (peer_.PeerSep() == AVDT_TSEP_SNK) { - LOG_VERBOSE("set source invalid_peer_check as false"); + log::verbose("set source invalid_peer_check as false"); btif_av_source.SetInvalidPeerCheck(false); } else { - LOG_VERBOSE("set sink invalid_peer_check as false"); + log::verbose("set sink invalid_peer_check as false"); btif_av_sink.SetInvalidPeerCheck(false); } if (peer_.PeerSep() != p_bta_data->open.sep) { @@ -2094,21 +2059,21 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, tmp_peer = btif_av_source.popPeer(peer_.PeerAddress()); if (peer_.PeerAddress() != tmp_peer->PeerAddress()) - LOG_ERROR("error, not same peer"); + log::error("error, not same peer"); btif_av_sink.AddPeer(tmp_peer); } else { tmp_peer = btif_av_sink.popPeer(peer_.PeerAddress()); if (peer_.PeerAddress() != tmp_peer->PeerAddress()) - LOG_ERROR("error, not same peer"); + log::error("error, not same peer"); btif_av_source.AddPeer(tmp_peer); } peer_.SetSep(p_bta_data->open.sep); } if (btif_rc_is_connected_peer(peer_.PeerAddress())) { - LOG_VERBOSE("%s, AVRCP connected, update avrc sep", __func__); + log::verbose("AVRCP connected, update avrc sep"); BTA_AvSetPeerSep(peer_.PeerAddress(), peer_.PeerSep()); } btif_rc_check_pending_cmd(p_bta_data->open.bd_addr); @@ -2143,8 +2108,8 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, if (btif_rc_is_connected_peer(peer_.PeerAddress())) { // Disconnect the AVRCP connection, in case the A2DP connectiton // failed for any reason. - LOG_WARN("%s: Peer %s : Disconnecting AVRCP", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::warn("Peer {} : Disconnecting AVRCP", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); uint8_t peer_handle = btif_rc_get_connected_peer_handle(peer_.PeerAddress()); if (peer_handle != BTRC_HANDLE_NONE) { @@ -2202,11 +2167,11 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, case BTIF_AV_CONNECT_REQ_EVT: { // The device has moved already to Opening, hence don't report the // connection state. - LOG_WARN( - "%s: Peer %s : event=%s : device is already connecting, " - "ignore Connect request", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn( + "Peer {} : event={} : device is already connecting, ignore Connect " + "request", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); log_counter_metrics_btif( android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1); @@ -2216,21 +2181,20 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, case BTA_AV_PENDING_EVT: { // The device has moved already to Opening, hence don't report the // connection state. - LOG_WARN( - "%s: Peer %s : event=%s : device is already connecting, " - "ignore incoming request", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn( + "Peer {} : event={} : device is already connecting, ignore incoming " + "request", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); log_counter_metrics_btif( android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING, 1); } break; case BTIF_AV_OFFLOAD_START_REQ_EVT: - LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::error("Peer {} : event={}: stream is not Opened", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: A2DP_OFFLOAD_START_REQ_FAILURE, @@ -2274,17 +2238,16 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event, log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum:: A2DP_CONNECTION_UNKNOWN_EVENT, 1); - LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Unhandled event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); return false; } return true; } void BtifAvStateMachine::StateOpened::OnEnter() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); peer_.ClearFlags(BtifAvPeer::kFlagLocalSuspendPending | BtifAvPeer::kFlagPendingStart | @@ -2299,15 +2262,14 @@ void BtifAvStateMachine::StateOpened::OnEnter() { std::promise<void> peer_ready_promise; if (!btif_av_sink.SetActivePeer(peer_.PeerAddress(), std::move(peer_ready_promise))) { - LOG_ERROR("%s: Error setting %s as active Source peer", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::error("Error setting {} as active Source peer", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); } } } void BtifAvStateMachine::StateOpened::OnExit() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); peer_.ClearFlags(BtifAvPeer::kFlagPendingStart); } @@ -2316,18 +2278,16 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, void* p_data) { tBTA_AV* p_av = (tBTA_AV*)p_data; - LOG_VERBOSE( - "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - logbool(peer_.IsActivePeer()).c_str()); + log::verbose("Peer {} : event={} flags={} active_peer={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + logbool(peer_.IsActivePeer())); if ((event == BTA_AV_REMOTE_CMD_EVT) && peer_.CheckFlags(BtifAvPeer::kFlagRemoteSuspend) && (p_av->remote_cmd.rc_id == AVRC_ID_PLAY)) { - LOG_VERBOSE("%s: Peer %s : Resetting remote suspend flag on RC PLAY", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {} : Resetting remote suspend flag on RC PLAY", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend); } @@ -2338,15 +2298,14 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, break; // Ignore case BTIF_AV_START_STREAM_REQ_EVT: { - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); if (p_data) { const btif_av_start_stream_req_t* p_start_steam_req = static_cast<const btif_av_start_stream_req_t*>(p_data); - LOG_INFO("Stream use_latency_mode=%s", - p_start_steam_req->use_latency_mode ? "true" : "false"); + log::info("Stream use_latency_mode={}", + p_start_steam_req->use_latency_mode ? "true" : "false"); peer_.SetUseLatencyMode(p_start_steam_req->use_latency_mode); } @@ -2355,13 +2314,11 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, } break; case BTA_AV_START_EVT: { - LOG_INFO( - "%s: Peer %s : event=%s status=%d suspending=%d " - "initiator=%d flags=%s", - __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), p_av->start.status, - p_av->start.suspending, p_av->start.initiator, - peer_.FlagsToString().c_str()); + log::info( + "Peer {} : event={} status={} suspending={} initiator={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), p_av->start.status, + p_av->start.suspending, p_av->start.initiator, peer_.FlagsToString()); if ((p_av->start.status == BTA_SUCCESS) && p_av->start.suspending) return true; @@ -2373,14 +2330,12 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, if (peer_.IsSink()) { if (!peer_.CheckFlags(BtifAvPeer::kFlagPendingStart | BtifAvPeer::kFlagRemoteSuspend)) { - LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : trigger Suspend as remote initiated"; + log::warn("Peer {} : trigger Suspend as remote initiated", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())); should_suspend = true; } else if (!peer_.IsActivePeer()) { - LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : trigger Suspend as non-active"; + log::warn("Peer {} : trigger Suspend as non-active", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())); should_suspend = true; } @@ -2432,9 +2387,8 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS); // Change state to Idle, send acknowledgement if start is pending if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) { - LOG_WARN("%s: Peer %s : failed pending start request", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::warn("Peer {} : failed pending start request", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); tBTA_AV_START av_start = {.chnl = p_av->close.chnl, .hndl = p_av->close.hndl, .status = BTA_AV_FAIL_STREAM, @@ -2455,13 +2409,11 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, case BTA_AV_RECONFIG_EVT: if (p_av->reconfig.status != BTA_AV_SUCCESS) { - LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : failed reconfiguration"; + log::warn("Peer {} : failed reconfiguration", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())); if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) { - LOG(ERROR) << __PRETTY_FUNCTION__ << ": Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : cannot proceed to do AvStart"; + log::error("Peer {} : cannot proceed to do AvStart", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())); peer_.ClearFlags(BtifAvPeer::kFlagPendingStart); btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE); } @@ -2474,43 +2426,40 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, } if (peer_.IsActivePeer()) { - LOG(INFO) << __PRETTY_FUNCTION__ << " : Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : Reconfig done - calling startSession() to audio HAL"; + log::info( + "Peer {} : Reconfig done - calling startSession() to audio HAL", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())); std::promise<void> peer_ready_promise; std::future<void> peer_ready_future = peer_ready_promise.get_future(); btif_a2dp_source_start_session(peer_.PeerAddress(), std::move(peer_ready_promise)); } if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) { - LOG(INFO) << __PRETTY_FUNCTION__ << " : Peer " - << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()) - << " : Reconfig done - calling BTA_AvStart(" - << loghex(peer_.BtaHandle()) << ")"; + log::info("Peer {} : Reconfig done - calling BTA_AvStart({})", + ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()), + loghex(peer_.BtaHandle())); BTA_AvStart(peer_.BtaHandle(), peer_.UseLatencyMode()); } break; case BTIF_AV_CONNECT_REQ_EVT: { - LOG_WARN("%s: Peer %s : Ignore %s for same device", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Ignore {} for same device", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_queue_advance(); } break; case BTIF_AV_OFFLOAD_START_REQ_EVT: - LOG_ERROR("%s: Peer %s : event=%s: stream is not Started", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::error("Peer {} : event={}: stream is not Started", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); break; case BTIF_AV_AVRCP_REMOTE_PLAY_EVT: if (peer_.CheckFlags(BtifAvPeer::kFlagRemoteSuspend)) { - LOG_VERBOSE("%s: Peer %s : Resetting remote suspend flag on RC PLAY", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {} : Resetting remote suspend flag on RC PLAY", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend); } break; @@ -2520,27 +2469,25 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, case BTIF_AV_SET_LATENCY_REQ_EVT: { const btif_av_set_latency_req_t* p_set_latency_req = static_cast<const btif_av_set_latency_req_t*>(p_data); - LOG_INFO("Peer %s : event=%s flags=%s is_low_latency=%s", - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str(), - p_set_latency_req->is_low_latency ? "true" : "false"); + log::info("Peer {} : event={} flags={} is_low_latency={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + p_set_latency_req->is_low_latency ? "true" : "false"); BTA_AvSetLatency(peer_.BtaHandle(), p_set_latency_req->is_low_latency); } break; default: - LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Unhandled event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); return false; } return true; } void BtifAvStateMachine::StateStarted::OnEnter() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); // We are again in started state, clear any remote suspend flags peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend); @@ -2553,29 +2500,26 @@ void BtifAvStateMachine::StateStarted::OnEnter() { } void BtifAvStateMachine::StateStarted::OnExit() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); } bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, void* p_data) { tBTA_AV* p_av = (tBTA_AV*)p_data; - LOG_VERBOSE( - "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - logbool(peer_.IsActivePeer()).c_str()); + log::verbose("Peer {} : event={} flags={} active_peer={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + logbool(peer_.IsActivePeer())); switch (event) { case BTIF_AV_ACL_DISCONNECTED: break; // Ignore case BTIF_AV_START_STREAM_REQ_EVT: - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); // We were started remotely, just ACK back the local request if (peer_.IsSink()) btif_a2dp_on_started(peer_.PeerAddress(), nullptr); break; @@ -2583,10 +2527,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, // FIXME -- use suspend = true always to work around issue with BTA AV case BTIF_AV_STOP_STREAM_REQ_EVT: case BTIF_AV_SUSPEND_STREAM_REQ_EVT: - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); // There is a pending LocalSuspend already, ignore. if (peer_.CheckFlags(BtifAvPeer::kFlagLocalSuspendPending)) { @@ -2617,10 +2560,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, break; case BTIF_AV_DISCONNECT_REQ_EVT: - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); // Request AVDTP to close BTA_AvClose(peer_.BtaHandle()); @@ -2638,11 +2580,10 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, break; case BTA_AV_SUSPEND_EVT: { - LOG_INFO("%s: Peer %s : event=%s status=%d initiator=%d flags=%s", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), p_av->suspend.status, - p_av->suspend.initiator, peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} status={} initiator={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), p_av->suspend.status, + p_av->suspend.initiator, peer_.FlagsToString()); // A2DP suspended, stop A2DP encoder / decoder until resumed if (peer_.IsActivePeer() || !btif_av_stream_started_ready()) { @@ -2679,10 +2620,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, } break; case BTA_AV_STOP_EVT: - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); peer_.SetFlags(BtifAvPeer::kFlagPendingStop); peer_.ClearFlags(BtifAvPeer::kFlagLocalSuspendPending); @@ -2702,10 +2642,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, break; case BTA_AV_CLOSE_EVT: - LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::info("Peer {} : event={} flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); // Inform the application that we are disconnecting btif_report_connection_state( peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTING, @@ -2730,11 +2669,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, if (peer_.CheckFlags(BtifAvPeer::kFlagLocalSuspendPending | BtifAvPeer::kFlagRemoteSuspend | BtifAvPeer::kFlagPendingStop)) { - LOG_WARN("%s: Peer %s : event=%s flags=%s: stream is Suspending", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str()); + log::warn("Peer {} : event={} flags={}: stream is Suspending", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString()); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); break; } @@ -2748,11 +2685,10 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, case BTIF_AV_SET_LATENCY_REQ_EVT: { const btif_av_set_latency_req_t* p_set_latency_req = static_cast<const btif_av_set_latency_req_t*>(p_data); - LOG_INFO("Peer %s : event=%s flags=%s is_low_latency=%s", - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), - peer_.FlagsToString().c_str(), - p_set_latency_req->is_low_latency ? "true" : "false"); + log::info("Peer {} : event={} flags={} is_low_latency={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + p_set_latency_req->is_low_latency ? "true" : "false"); BTA_AvSetLatency(peer_.BtaHandle(), p_set_latency_req->is_low_latency); } break; @@ -2760,9 +2696,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, CHECK_RC_EVENT(event, (tBTA_AV*)p_data); default: - LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Unhandled event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); return false; } @@ -2770,8 +2706,7 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event, } void BtifAvStateMachine::StateClosing::OnEnter() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); if (peer_.IsActivePeer()) { if (peer_.IsSink()) { @@ -2785,17 +2720,15 @@ void BtifAvStateMachine::StateClosing::OnEnter() { } void BtifAvStateMachine::StateClosing::OnExit() { - LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress())); } bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event, void* p_data) { - LOG_VERBOSE( - "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(), - logbool(peer_.IsActivePeer()).c_str()); + log::verbose("Peer {} : event={} flags={} active_peer={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event), peer_.FlagsToString(), + logbool(peer_.IsActivePeer())); switch (event) { case BTIF_AV_SUSPEND_STREAM_REQ_EVT: @@ -2829,25 +2762,24 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event, break; case BTIF_AV_OFFLOAD_START_REQ_EVT: - LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened", - __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::error("Peer {} : event={}: stream is not Opened", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL); break; case BTIF_AV_CONNECT_REQ_EVT: - LOG_WARN("%s: Peer %s : Ignore %s in StateClosing", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Ignore {} in StateClosing", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); btif_queue_advance(); peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle); break; default: - LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__, - ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), - BtifAvEvent::EventName(event).c_str()); + log::warn("Peer {} : Unhandled event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()), + BtifAvEvent::EventName(event)); return false; } return true; @@ -2861,21 +2793,20 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event, static void btif_av_source_initiate_av_open_timer_timeout(void* data) { BtifAvPeer* peer = (BtifAvPeer*)data; - LOG_VERBOSE("%s: Peer %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); // Check if AVRCP is connected to the peer if (!btif_rc_is_connected_peer(peer->PeerAddress())) { - LOG_ERROR("%s: AVRCP peer %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::error("AVRCP peer {} is not connected", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); return; } // Connect to the AVRCP peer if (btif_av_source.Enabled() && btif_av_source.FindPeer(peer->PeerAddress()) == peer) { - LOG_VERBOSE("%s: Connecting to AVRCP peer %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::verbose("Connecting to AVRCP peer {}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); btif_av_source_dispatch_sm_event(peer->PeerAddress(), BTIF_AV_CONNECT_REQ_EVT); } @@ -2888,21 +2819,20 @@ static void btif_av_source_initiate_av_open_timer_timeout(void* data) { static void btif_av_sink_initiate_av_open_timer_timeout(void* data) { BtifAvPeer* peer = (BtifAvPeer*)data; - LOG_VERBOSE("%s: Peer %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); // Check if AVRCP is connected to the peer if (!btif_rc_is_connected_peer(peer->PeerAddress())) { - LOG_ERROR("%s: AVRCP peer %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::error("AVRCP peer {} is not connected", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); return; } // Connect to the AVRCP peer if (btif_av_sink.Enabled() && btif_av_sink.FindPeer(peer->PeerAddress()) == peer) { - LOG_VERBOSE("%s: Connecting to AVRCP peer %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); + log::verbose("Connecting to AVRCP peer {}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress())); btif_av_sink_dispatch_sm_event(peer->PeerAddress(), BTIF_AV_CONNECT_REQ_EVT); } @@ -2918,12 +2848,12 @@ static void btif_report_connection_state(const RawAddress& peer_address, btav_connection_state_t state, bt_status_t status, uint8_t error_code) { - LOG_INFO("%s: peer_address=%s state=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), state); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + state); if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_ERROR("%s: peer is null", __func__); + log::error("peer is null"); return; } @@ -2967,8 +2897,8 @@ static void btif_report_connection_state(const RawAddress& peer_address, */ static void btif_report_audio_state(const RawAddress& peer_address, btav_audio_state_t state) { - LOG_INFO("%s: peer_address=%s state=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), state); + log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + state); if (btif_av_both_enable()) { BtifAvPeer* peer = btif_av_find_peer(peer_address); @@ -3020,8 +2950,7 @@ void btif_av_report_source_codec_state( const std::vector<btav_a2dp_codec_config_t>& codecs_local_capabilities, const std::vector<btav_a2dp_codec_config_t>& codecs_selectable_capabilities) { - LOG_VERBOSE("%s: peer_address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::verbose("peer_address={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (btif_av_source.Enabled()) { do_in_jni_thread( FROM_HERE, @@ -3040,8 +2969,8 @@ void btif_av_report_source_codec_state( */ static void btif_av_report_sink_audio_config_state( const RawAddress& peer_address, int sample_rate, int channel_count) { - LOG_INFO("%s: Peer %s : sample_rate=%d channel_count=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), sample_rate, channel_count); + log::info("Peer {} : sample_rate={} channel_count={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), sample_rate, channel_count); if (btif_av_sink.Enabled()) { do_in_jni_thread(FROM_HERE, base::BindOnce(btif_av_sink.Callbacks()->audio_config_cb, @@ -3059,7 +2988,7 @@ static void btif_av_query_mandatory_codec_priority( const RawAddress& peer_address) { auto query_priority = [](const RawAddress& peer_address) { if (!btif_av_source.Enabled()) { - LOG_WARN("BTIF AV Source is not enabled"); + log::warn("BTIF AV Source is not enabled"); return; } btav_source_callbacks_t* callbacks = btif_av_source.Callbacks(); @@ -3069,7 +2998,7 @@ static void btif_av_query_mandatory_codec_priority( auto apply_priority = [](const RawAddress& peer_address, bool preferred) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("btif_av_query_mandatory_codec_priority: peer is null"); + log::warn("btif_av_query_mandatory_codec_priority: peer is null"); return; } peer->SetMandatoryCodecPreferred(preferred); @@ -3094,44 +3023,39 @@ static BtifAvPeer* btif_av_handle_both_peer(uint8_t peer_sep, /* if no this peer, default it's sink device */ if (peer == nullptr) { if (peer_sep == AVDT_TSEP_SRC) { - LOG_VERBOSE("%s: peer_sep(%d), create a new source peer", __func__, - peer_sep); + log::verbose("peer_sep({}), create a new source peer", peer_sep); peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle); } else if (peer_sep == AVDT_TSEP_SNK) { - LOG_VERBOSE("%s: peer_sep(%d), create a new sink peer", __func__, - peer_sep); + log::verbose("peer_sep({}), create a new sink peer", peer_sep); peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle); } else { btif_av_source.SetInvalidPeerCheck(true); if (!btif_av_source.Peers().empty()) { - LOG_VERBOSE( - "%s: peer_sep invalid, and already has sink peer," - " so try create a new sink peer", - __func__); + log::verbose( + "peer_sep invalid, and already has sink peer, so try create a " + "new sink peer"); peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle); } else if (!btif_av_sink.Peers().empty()) { - LOG_VERBOSE( - "%s: peer_sep invalid, and already has source peer," - " so try create a new source peer", - __func__); + log::verbose( + "peer_sep invalid, and already has source peer, so try create " + "a new source peer"); peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle); } else { - LOG_VERBOSE( - "%s: peer_sep invalid, and no active peer," - " so try create a new sink peer", - __func__); + log::verbose( + "peer_sep invalid, and no active peer, so try create a new " + "sink peer"); peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle); } } } } else { if (peer_sep == AVDT_TSEP_SNK) { - LOG_VERBOSE("%s: peer_sep(%d), only init src create a new source peer", - __func__, peer_sep); + log::verbose("peer_sep({}), only init src create a new source peer", + peer_sep); peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle); } else if (peer_sep == AVDT_TSEP_SRC) { - LOG_VERBOSE("%s: peer_sep(%d), only init sink create a new source peer", - __func__, peer_sep); + log::verbose("peer_sep({}), only init sink create a new source peer", + peer_sep); peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle); } } @@ -3141,7 +3065,7 @@ static BtifAvPeer* btif_av_handle_both_peer(uint8_t peer_sep, } else if (peer_sep == AVDT_TSEP_SRC) { peer = btif_av_sink.FindPeerByHandle(bta_handle); } - LOG_VERBOSE("%s:peer is check 3", __func__); + log::verbose("peer is check 3"); } } else if (bta_handle != 0) { if (peer_sep == AVDT_TSEP_INVALID) { @@ -3174,8 +3098,8 @@ static void btif_av_handle_event(uint8_t peer_sep, const RawAddress& peer_address, tBTA_AV_HNDL bta_handle, const BtifAvEvent& btif_av_event) { - LOG_DEBUG("Handle event peer_address=%s bta_handle=0x%x", - ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); + log::debug("Handle event peer_address={} bta_handle=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle); BtifAvPeer* peer = nullptr; @@ -3198,12 +3122,12 @@ static void btif_av_handle_event(uint8_t peer_sep, } } if (peer == nullptr) { - LOG_ERROR( - "jni_thread: Cannot find or create %s peer for peer_address=%s " - " bta_handle=0x%x : event dropped: %s", - peer_stream_endpoint_text(peer_sep).c_str(), + log::error( + "jni_thread: Cannot find or create {} peer for peer_address={} " + "bta_handle=0x{:x} : event dropped: {}", + peer_stream_endpoint_text(peer_sep), ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle, - btif_av_event.ToString().c_str()); + btif_av_event.ToString()); return; } @@ -3227,22 +3151,22 @@ static void btif_av_handle_bta_av_event(uint8_t peer_sep, tBTA_AV* p_data = (tBTA_AV*)btif_av_event.Data(); std::string msg; - LOG_DEBUG( - "jni_thread: Handle BTA AV or AVRCP event %s: peer_sep=%hhu event=%s", - peer_stream_endpoint_text(peer_sep).c_str(), peer_sep, - btif_av_event.ToString().c_str()); + log::debug( + "jni_thread: Handle BTA AV or AVRCP event {}: peer_sep={} event={}", + peer_stream_endpoint_text(peer_sep), peer_sep, btif_av_event.ToString()); switch (event) { case BTA_AV_ENABLE_EVT: { const tBTA_AV_ENABLE& enable = p_data->enable; - LOG_DEBUG("Enable features=0x%x", enable.features); + log::debug("Enable features=0x{:x}", enable.features); return; // Nothing to do } case BTA_AV_REGISTER_EVT: { const tBTA_AV_REGISTER& reg = p_data->reg; bta_handle = reg.hndl; uint8_t peer_id = reg.app_id; // The PeerId is used as AppId - LOG_DEBUG("Register bta_handle=0x%x app_id=%d", bta_handle, reg.app_id); + log::debug("Register bta_handle=0x{:x} app_id={}", bta_handle, + reg.app_id); if (btif_av_src_sink_coexist_enabled()) { if (peer_sep == AVDT_TSEP_INVALID) { if (reg.peer_sep == AVDT_TSEP_SNK) @@ -3395,7 +3319,7 @@ bool btif_av_src_sink_coexist_enabled(void) { static void bta_av_source_callback(tBTA_AV_EVT event, tBTA_AV* p_data) { BtifAvEvent btif_av_event(event, p_data, sizeof(tBTA_AV)); - LOG_VERBOSE("%s: event=%s", __func__, btif_av_event.ToString().c_str()); + log::verbose("event={}", btif_av_event.ToString()); do_in_main_thread( FROM_HERE, base::BindOnce(&btif_av_handle_bta_av_event, @@ -3430,7 +3354,7 @@ static void bta_av_event_callback(tBTA_AV_EVT event, tBTA_AV* p_data) { static void bta_av_sink_media_callback(const RawAddress& peer_address, tBTA_AV_EVT event, tBTA_AV_MEDIA* p_data) { - LOG_VERBOSE("%s: event=%d", __func__, event); + log::verbose("event={}", event); switch (event) { case BTA_AV_SINK_MEDIA_DATA_EVT: { @@ -3440,7 +3364,7 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address, if ((state == BtifAvStateMachine::kStateStarted) || (state == BtifAvStateMachine::kStateOpened)) { uint8_t queue_len = btif_a2dp_sink_enqueue_buf((BT_HDR*)p_data); - LOG_VERBOSE("%s: Packets in Sink queue %d", __func__, queue_len); + log::verbose("Packets in Sink queue {}", queue_len); } } break; @@ -3448,8 +3372,8 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address, case BTA_AV_SINK_MEDIA_CFG_EVT: { btif_av_sink_config_req_t config_req; - LOG_VERBOSE("%s: address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_data->avk_config.bd_addr)); + log::verbose("address={}", + ADDRESS_TO_LOGGABLE_CSTR(p_data->avk_config.bd_addr)); // Update the codec info of the A2DP Sink decoder btif_a2dp_sink_update_decoder((uint8_t*)(p_data->avk_config.codec_info)); @@ -3457,13 +3381,13 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address, config_req.sample_rate = A2DP_GetTrackSampleRate(p_data->avk_config.codec_info); if (config_req.sample_rate == -1) { - LOG_ERROR("%s: Cannot get the track frequency", __func__); + log::error("Cannot get the track frequency"); break; } config_req.channel_count = A2DP_GetTrackChannelCount(p_data->avk_config.codec_info); if (config_req.channel_count == -1) { - LOG_ERROR("%s: Cannot get the channel count", __func__); + log::error("Cannot get the channel count"); break; } config_req.peer_address = p_data->avk_config.bd_addr; @@ -3487,7 +3411,7 @@ static bt_status_t init_src( const std::vector<btav_a2dp_codec_config_t>& codec_priorities, const std::vector<btav_a2dp_codec_config_t>& offloading_preference, std::vector<btav_a2dp_codec_info_t>* supported_codecs) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return btif_av_source.Init(callbacks, max_connected_audio_devices, codec_priorities, offloading_preference, supported_codecs); @@ -3496,26 +3420,26 @@ static bt_status_t init_src( // Initializes the AV interface for sink mode static bt_status_t init_sink(btav_sink_callbacks_t* callbacks, int max_connected_audio_devices) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return btif_av_sink.Init(callbacks, max_connected_audio_devices); } // Updates the final focus state reported by components calling this module static void update_audio_focus_state(int state) { - LOG_VERBOSE("%s: state=%d", __func__, state); + log::verbose("state={}", state); btif_a2dp_sink_set_focus_state_req((btif_a2dp_sink_focus_state_t)state); } // Updates the track gain (used for ducking). static void update_audio_track_gain(float gain) { - LOG_VERBOSE("%s: gain=%f", __func__, gain); + log::verbose("gain={:f}", gain); btif_a2dp_sink_set_audio_track_gain(gain); } // Establishes the AV signalling channel with the remote headset static bt_status_t connect_int(RawAddress* peer_address, uint16_t uuid) { - LOG_VERBOSE("%s: peer_address=%s uuid=0x%x", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*peer_address), uuid); + log::verbose("peer_address={} uuid=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(*peer_address), uuid); if (btif_av_both_enable()) { const RawAddress tmp = *peer_address; if (uuid == UUID_SERVCLASS_AUDIO_SOURCE) { @@ -3542,19 +3466,19 @@ static bt_status_t connect_int(RawAddress* peer_address, uint16_t uuid) { bt_status_t status = do_in_main_thread( FROM_HERE, base::BindOnce(connection_task, peer_address, uuid)); if (status != BT_STATUS_SUCCESS) { - LOG(ERROR) << __func__ << ": can't post connection task to main_thread"; + log::error("can't post connection task to main_thread"); } return status; } static void set_source_silence_peer_int(const RawAddress& peer_address, bool silence) { - LOG_VERBOSE("%s: peer_address=%s, silence=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - silence ? "true" : "false"); + log::verbose("peer_address={}, silence={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), + silence ? "true" : "false"); if (!btif_av_source.SetSilencePeer(peer_address, silence)) { - LOG_ERROR("%s: Error setting silence state to %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error("Error setting silence state to {}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); } } @@ -3562,17 +3486,17 @@ static void set_source_silence_peer_int(const RawAddress& peer_address, static void set_active_peer_int(uint8_t peer_sep, const RawAddress& peer_address, std::promise<void> peer_ready_promise) { - LOG_VERBOSE("%s: peer_sep=%s (%d) peer_address=%s", __func__, - (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::verbose("peer_sep={} ({}) peer_address={}", + (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep, + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); BtifAvPeer* peer = nullptr; if (peer_sep == AVDT_TSEP_SNK) { if (!btif_av_src_sink_coexist_enabled() || (btif_av_src_sink_coexist_enabled() && btif_av_both_enable() && (btif_av_sink.FindPeer(peer_address) == nullptr))) { btif_av_source.SetActivePeer(peer_address, std::move(peer_ready_promise)); - LOG_ERROR("%s: Error setting %s as active Sink peer", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error("Error setting {} as active Sink peer", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); } return; } @@ -3581,39 +3505,39 @@ static void set_active_peer_int(uint8_t peer_sep, btif_av_both_enable() && (btif_av_source.FindPeer(peer_address) == nullptr))) { if (!btif_av_sink.SetActivePeer(peer_address, std::move(peer_ready_promise))) { - LOG_ERROR("%s: Error setting %s as active Source peer", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::error("Error setting {} as active Source peer", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); } } return; } // If reached here, we could not set the active peer - LOG_ERROR("%s: Cannot set active %s peer to %s: peer not %s", __func__, - (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - (peer == nullptr) ? "found" : "connected"); + log::error("Cannot set active {} peer to {}: peer not {}", + (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), + (peer == nullptr) ? "found" : "connected"); peer_ready_promise.set_value(); } static bt_status_t src_connect_sink(const RawAddress& peer_address) { if (!btif_av_source.Enabled()) { - LOG_WARN("BTIF AV Source is not enabled"); + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } RawAddress peer_address_copy(peer_address); - LOG_DEBUG("Connecting to AV sink peer:%s", - ADDRESS_TO_LOGGABLE_CSTR(peer_address_copy)); + log::debug("Connecting to AV sink peer:{}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address_copy)); return btif_queue_connect(UUID_SERVCLASS_AUDIO_SOURCE, &peer_address_copy, connect_int); } static bt_status_t sink_connect_src(const RawAddress& peer_address) { - LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_sink.Enabled()) { - LOG_WARN("%s: BTIF AV Sink is not enabled", __func__); + log::warn("BTIF AV Sink is not enabled"); return BT_STATUS_NOT_READY; } @@ -3623,10 +3547,10 @@ static bt_status_t sink_connect_src(const RawAddress& peer_address) { } static bt_status_t src_disconnect_sink(const RawAddress& peer_address) { - LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_source.Enabled()) { - LOG_WARN("%s: BTIF AV Source is not enabled", __func__); + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } @@ -3640,10 +3564,10 @@ static bt_status_t src_disconnect_sink(const RawAddress& peer_address) { } static bt_status_t sink_disconnect_src(const RawAddress& peer_address) { - LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_sink.Enabled()) { - LOG_WARN("%s: BTIF AV Sink is not enabled", __func__); + log::warn("BTIF AV Sink is not enabled"); return BT_STATUS_NOT_READY; } @@ -3657,10 +3581,10 @@ static bt_status_t sink_disconnect_src(const RawAddress& peer_address) { } static bt_status_t sink_set_active_device(const RawAddress& peer_address) { - LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_sink.Enabled()) { - LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled"; + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } @@ -3673,16 +3597,16 @@ static bt_status_t sink_set_active_device(const RawAddress& peer_address) { if (status == BT_STATUS_SUCCESS) { peer_ready_future.wait(); } else { - LOG(WARNING) << __func__ << ": BTIF AV Sink fails to change peer"; + log::warn("BTIF AV Sink fails to change peer"); } return status; } static bt_status_t src_set_silence_sink(const RawAddress& peer_address, bool silence) { - LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_source.Enabled()) { - LOG_WARN("%s: BTIF AV Source is not enabled", __func__); + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } @@ -3692,10 +3616,10 @@ static bt_status_t src_set_silence_sink(const RawAddress& peer_address, } static bt_status_t src_set_active_sink(const RawAddress& peer_address) { - LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!btif_av_source.Enabled()) { - LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled"; + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } @@ -3708,7 +3632,7 @@ static bt_status_t src_set_active_sink(const RawAddress& peer_address) { if (status == BT_STATUS_SUCCESS) { peer_ready_future.wait(); } else { - LOG(WARNING) << __func__ << ": BTIF AV Source fails to change peer"; + log::warn("BTIF AV Source fails to change peer"); } return status; } @@ -3716,15 +3640,15 @@ static bt_status_t src_set_active_sink(const RawAddress& peer_address) { static bt_status_t codec_config_src( const RawAddress& peer_address, std::vector<btav_a2dp_codec_config_t> codec_preferences) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_av_source.Enabled()) { - LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled"; + log::warn("BTIF AV Source is not enabled"); return BT_STATUS_NOT_READY; } if (peer_address.IsEmpty()) { - LOG(WARNING) << __func__ << ": BTIF AV Source needs peer to config"; + log::warn("BTIF AV Source needs peer to config"); return BT_STATUS_PARM_INVALID; } @@ -3738,20 +3662,20 @@ static bt_status_t codec_config_src( if (status == BT_STATUS_SUCCESS) { peer_ready_future.wait(); } else { - LOG(WARNING) << __func__ << ": BTIF AV Source fails to config codec"; + log::warn("BTIF AV Source fails to config codec"); } return status; } static void cleanup_src(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); do_in_main_thread(FROM_HERE, base::BindOnce(&BtifAvSource::Cleanup, base::Unretained(&btif_av_source))); } static void cleanup_sink(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); do_in_main_thread(FROM_HERE, base::BindOnce(&BtifAvSink::Cleanup, base::Unretained(&btif_av_sink))); } @@ -3787,22 +3711,21 @@ bool btif_av_is_sink_enabled(void) { return btif_av_sink.Enabled(); } bool btif_av_is_source_enabled(void) { return btif_av_source.Enabled(); } void btif_av_stream_start(void) { - LOG_INFO("%s", __func__); + log::info(""); btif_av_source_dispatch_sm_event(btif_av_source_active_peer(), BTIF_AV_START_STREAM_REQ_EVT); } void btif_av_stream_start_with_latency(bool use_latency_mode) { - LOG_INFO("%s", __func__); + log::info(""); btif_av_start_stream_req_t start_stream_req; start_stream_req.use_latency_mode = use_latency_mode; BtifAvEvent btif_av_event(BTIF_AV_START_STREAM_REQ_EVT, &start_stream_req, sizeof(start_stream_req)); - LOG_INFO("peer_address=%s event=%s use_latency_mode=%s", - ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()), - btif_av_event.ToString().c_str(), - use_latency_mode ? "true" : "false"); + log::info("peer_address={} event={} use_latency_mode={}", + ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()), + btif_av_event.ToString(), use_latency_mode ? "true" : "false"); do_in_main_thread( FROM_HERE, base::BindOnce(&btif_av_handle_event, @@ -3833,7 +3756,7 @@ void src_do_suspend_in_main_thread(btif_av_sm_event_t event) { } void btif_av_stream_stop(const RawAddress& peer_address) { - LOG_INFO("%s peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (!peer_address.IsEmpty()) { btif_av_source_dispatch_sm_event(peer_address, BTIF_AV_STOP_STREAM_REQ_EVT); @@ -3846,40 +3769,40 @@ void btif_av_stream_stop(const RawAddress& peer_address) { } void btif_av_stream_suspend(void) { - LOG_INFO("%s", __func__); + log::info(""); // The active peer might have changed and we might be in the process // of reconfiguring the stream. We need to suspend the appropriate peer(s). src_do_suspend_in_main_thread(BTIF_AV_SUSPEND_STREAM_REQ_EVT); } void btif_av_stream_start_offload(void) { - LOG_INFO("%s", __func__); + log::info(""); btif_av_source_dispatch_sm_event(btif_av_source_active_peer(), BTIF_AV_OFFLOAD_START_REQ_EVT); } void btif_av_src_disconnect_sink(const RawAddress& peer_address) { - LOG_INFO("%s: peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address)); src_disconnect_sink(peer_address); } bool btif_av_stream_ready(void) { // Make sure the main adapter is enabled if (btif_is_enabled() == 0) { - LOG_VERBOSE("%s: Main adapter is not enabled", __func__); + log::verbose("Main adapter is not enabled"); return false; } BtifAvPeer* peer = btif_av_find_active_peer(); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } int state = peer->StateMachine().StateId(); - LOG_INFO("%s: Peer %s : state=%d, flags=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state, - peer->FlagsToString().c_str()); + log::info("Peer {} : state={}, flags={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state, + peer->FlagsToString()); // check if we are remotely suspended or stop is pending if (peer->CheckFlags(BtifAvPeer::kFlagRemoteSuspend | BtifAvPeer::kFlagPendingStop)) { @@ -3892,7 +3815,7 @@ bool btif_av_stream_ready(void) { bool btif_av_stream_started_ready(void) { BtifAvPeer* peer = btif_av_find_active_peer(); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } @@ -3906,9 +3829,9 @@ bool btif_av_stream_started_ready(void) { } else { ready = (state == BtifAvStateMachine::kStateStarted); } - LOG_INFO("%s: Peer %s : state=%d flags=%s ready=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state, - peer->FlagsToString().c_str(), ready); + log::info("Peer {} : state={} flags={} ready={}", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state, + peer->FlagsToString(), ready); return ready; } @@ -3916,9 +3839,9 @@ bool btif_av_stream_started_ready(void) { static void btif_av_source_dispatch_sm_event(const RawAddress& peer_address, btif_av_sm_event_t event) { BtifAvEvent btif_av_event(event, nullptr, 0); - LOG_VERBOSE("%s: peer_address=%s event=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_av_event.ToString().c_str()); + log::verbose("peer_address={} event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_av_event.ToString()); do_in_main_thread(FROM_HERE, base::BindOnce(&btif_av_handle_event, AVDT_TSEP_SNK, // peer_sep @@ -3929,9 +3852,9 @@ static void btif_av_source_dispatch_sm_event(const RawAddress& peer_address, static void btif_av_sink_dispatch_sm_event(const RawAddress& peer_address, btif_av_sm_event_t event) { BtifAvEvent btif_av_event(event, nullptr, 0); - LOG_VERBOSE("%s: peer_address=%s event=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), - btif_av_event.ToString().c_str()); + log::verbose("peer_address={} event={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), + btif_av_event.ToString()); do_in_main_thread(FROM_HERE, base::BindOnce(&btif_av_handle_event, AVDT_TSEP_SRC, // peer_sep @@ -3940,8 +3863,7 @@ static void btif_av_sink_dispatch_sm_event(const RawAddress& peer_address, } bt_status_t btif_av_source_execute_service(bool enable) { - LOG_VERBOSE("%s: Source service: %s", __func__, - (enable) ? "enable" : "disable"); + log::verbose("Source service: {}", (enable) ? "enable" : "disable"); if (enable) { // Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not @@ -3977,8 +3899,7 @@ bt_status_t btif_av_source_execute_service(bool enable) { } bt_status_t btif_av_sink_execute_service(bool enable) { - LOG_VERBOSE("%s: Sink service: %s", __func__, - (enable) ? "enable" : "disable"); + log::verbose("Sink service: {}", (enable) ? "enable" : "disable"); if (enable) { // Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not @@ -4009,41 +3930,40 @@ bt_status_t btif_av_sink_execute_service(bool enable) { // Get the AV callback interface for A2DP source profile const btav_source_interface_t* btif_av_get_src_interface(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &bt_av_src_interface; } // Get the AV callback interface for A2DP sink profile const btav_sink_interface_t* btif_av_get_sink_interface(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &bt_av_sink_interface; } bool btif_av_is_connected(void) { BtifAvPeer* peer = btif_av_find_active_peer(); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } bool connected = peer->IsConnected(); - LOG_VERBOSE("%s: Peer %s is %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - (connected) ? "connected" : "not connected"); + log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + (connected) ? "connected" : "not connected"); return connected; } uint8_t btif_av_get_peer_sep(void) { BtifAvPeer* peer = btif_av_find_active_peer(); if (peer == nullptr) { - LOG_INFO("No active sink or source peer found"); + log::info("No active sink or source peer found"); return AVDT_TSEP_INVALID; } uint8_t peer_sep = peer->PeerSep(); - LOG_VERBOSE("Peer %s SEP is %s (%d)", - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep); + log::verbose("Peer {} SEP is {} ({})", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep); return peer_sep; } @@ -4051,12 +3971,12 @@ void btif_av_clear_remote_suspend_flag(void) { auto clear_remote_suspend_flag = []() { BtifAvPeer* peer = btif_av_find_active_peer(); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return; } - LOG_VERBOSE("%s: Peer %s : flags=%s are cleared", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - peer->FlagsToString().c_str()); + log::verbose("Peer {} : flags={} are cleared", + ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + peer->FlagsToString()); peer->ClearFlags(BtifAvPeer::kFlagRemoteSuspend); }; // switch to main thread to prevent a race condition of accessing peers @@ -4066,42 +3986,42 @@ void btif_av_clear_remote_suspend_flag(void) { bool btif_av_is_peer_edr(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No peer found for peer_address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::warn("No peer found for peer_address={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return false; } if (!peer->IsConnected()) { - LOG_WARN("%s: Peer %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::warn("Peer {} is not connected", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return false; } bool is_edr = peer->IsEdr(); - LOG_VERBOSE("%s: Peer %s : is_edr=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_edr); + log::verbose("Peer {} : is_edr={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address), + is_edr); return is_edr; } bool btif_av_peer_supports_3mbps(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No peer found for peer_address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::warn("No peer found for peer_address={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return false; } bool is3mbps = peer->Is3Mbps(); bool is_connected = peer->IsConnected(); - LOG_VERBOSE("%s: Peer %s : connected=%d, edr_3mbps=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_connected, is3mbps); + log::verbose("Peer {} : connected={}, edr_3mbps={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_connected, is3mbps); return (is_connected && is3mbps); } bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No peer found for peer_address=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::warn("No peer found for peer_address={}", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); return false; } return peer->IsMandatoryCodecPreferred(); @@ -4109,8 +4029,8 @@ bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address) { void btif_av_acl_disconnected(const RawAddress& peer_address) { // Inform the application that ACL is disconnected and move to idle state - LOG_INFO("%s: Peer %s : ACL Disconnected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer_address)); + log::info("Peer {} : ACL Disconnected", + ADDRESS_TO_LOGGABLE_CSTR(peer_address)); if (btif_av_both_enable()) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer != nullptr) { @@ -4255,15 +4175,15 @@ void btif_av_set_dynamic_audio_buffer_size(uint8_t dynamic_audio_buffer_size) { } void btif_av_set_low_latency(bool is_low_latency) { - LOG_INFO("is_low_latency: %s", is_low_latency ? "true" : "false"); + log::info("is_low_latency: {}", is_low_latency ? "true" : "false"); btif_av_set_latency_req_t set_latency_req; set_latency_req.is_low_latency = is_low_latency; BtifAvEvent btif_av_event(BTIF_AV_SET_LATENCY_REQ_EVT, &set_latency_req, sizeof(set_latency_req)); - LOG_INFO("peer_address=%s event=%s", - ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()), - btif_av_event.ToString().c_str()); + log::info("peer_address={} event={}", + ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()), + btif_av_event.ToString()); do_in_main_thread( FROM_HERE, base::BindOnce(&btif_av_handle_event, AVDT_TSEP_SNK, // peer_sep @@ -4282,49 +4202,46 @@ static void btif_av_source_delete_active_peer(void) { bool btif_av_is_connected_addr(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } bool connected = peer->IsConnected(); - LOG_VERBOSE("%s: Peer %s is %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - (connected) ? "connected" : "not connected"); + log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + (connected) ? "connected" : "not connected"); return connected; } bool btif_av_peer_is_connected_sink(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_source_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } bool connected = peer->IsConnected(); - LOG_VERBOSE("%s: Peer %s is %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - (connected) ? "connected" : "not connected"); + log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + (connected) ? "connected" : "not connected"); return connected; } bool btif_av_peer_is_connected_source(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_sink_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } bool connected = peer->IsConnected(); - LOG_VERBOSE("%s: Peer %s is %s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), - (connected) ? "connected" : "not connected"); + log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), + (connected) ? "connected" : "not connected"); return connected; } bool btif_av_peer_is_sink(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_source_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } @@ -4334,7 +4251,7 @@ bool btif_av_peer_is_sink(const RawAddress& peer_address) { bool btif_av_peer_is_source(const RawAddress& peer_address) { BtifAvPeer* peer = btif_av_sink_find_peer(peer_address); if (peer == nullptr) { - LOG_WARN("%s: No active peer found", __func__); + log::warn("No active peer found"); return false; } diff --git a/system/btif/src/btif_avrcp_audio_track.cc b/system/btif/src/btif_avrcp_audio_track.cc index 0ad2c0a6ee0..12252b45b61 100644 --- a/system/btif/src/btif_avrcp_audio_track.cc +++ b/system/btif/src/btif_avrcp_audio_track.cc @@ -25,6 +25,7 @@ #include <aaudio/AAudio.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <utils/StrongPointer.h> #include <algorithm> @@ -35,6 +36,7 @@ #include "os/log.h" using namespace android; +using namespace bluetooth; typedef struct { AAudioStream* stream; @@ -85,8 +87,8 @@ void BtifAvrcpAudioErrorHandle() { trackHolder->stream = stream; if (trackHolder != NULL && trackHolder->stream != NULL) { - LOG_DEBUG("%s AAudio Error handle: restart A2dp Sink AudioTrack", __func__); - AAudioStream_requestStart(trackHolder->stream); + log::debug("AAudio Error handle: restart A2dp Sink AudioTrack"); + AAudioStream_requestStart(trackHolder->stream); } s_AudioEngine.thread = nullptr; } @@ -101,8 +103,8 @@ void ErrorCallback(AAudioStream* stream, void* BtifAvrcpAudioTrackCreate(int trackFreq, int bitsPerSample, int channelCount) { - LOG_INFO("%s Track.cpp: btCreateTrack freq %d bps %d channel %d ", __func__, - trackFreq, bitsPerSample, channelCount); + log::info("Track.cpp: btCreateTrack freq {} bps {} channel {}", trackFreq, + bitsPerSample, channelCount); AAudioStreamBuilder* builder; AAudioStream* stream; @@ -140,36 +142,36 @@ void* BtifAvrcpAudioTrackCreate(int trackFreq, int bitsPerSample, void BtifAvrcpAudioTrackStart(void* handle) { if (handle == NULL) { - LOG_ERROR("%s: handle is null!", __func__); + log::error("handle is null!"); return; } BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle); CHECK(trackHolder != NULL); CHECK(trackHolder->stream != NULL); - LOG_VERBOSE("%s Track.cpp: btStartTrack", __func__); + log::verbose("Track.cpp: btStartTrack"); AAudioStream_requestStart(trackHolder->stream); } void BtifAvrcpAudioTrackStop(void* handle) { if (handle == NULL) { - LOG_INFO("%s handle is null.", __func__); + log::info("handle is null."); return; } BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle); if (trackHolder != NULL && trackHolder->stream != NULL) { - LOG_VERBOSE("%s Track.cpp: btStopTrack", __func__); + log::verbose("Track.cpp: btStopTrack"); AAudioStream_requestStop(trackHolder->stream); } } void BtifAvrcpAudioTrackDelete(void* handle) { if (handle == NULL) { - LOG_INFO("%s handle is null.", __func__); + log::info("handle is null."); return; } BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle); if (trackHolder != NULL && trackHolder->stream != NULL) { - LOG_VERBOSE("%s Track.cpp: btStartTrack", __func__); + log::verbose("Track.cpp: btStartTrack"); AAudioStream_close(trackHolder->stream); delete trackHolder->buffer; delete trackHolder; @@ -185,12 +187,12 @@ void BtifAvrcpAudioTrackDelete(void* handle) { void BtifAvrcpAudioTrackPause(void* handle) { if (handle == NULL) { - LOG_INFO("%s handle is null.", __func__); + log::info("handle is null."); return; } BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle); if (trackHolder != NULL && trackHolder->stream != NULL) { - LOG_VERBOSE("%s Track.cpp: btPauseTrack", __func__); + log::verbose("Track.cpp: btPauseTrack"); AAudioStream_requestPause(trackHolder->stream); AAudioStream_requestFlush(trackHolder->stream); } @@ -198,18 +200,18 @@ void BtifAvrcpAudioTrackPause(void* handle) { void BtifAvrcpSetAudioTrackGain(void* handle, float gain) { if (handle == NULL) { - LOG_INFO("%s handle is null.", __func__); + log::info("handle is null."); return; } BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle); if (trackHolder != NULL) { const float clampedGain = std::clamp(gain, kMinTrackGain, kMaxTrackGain); if (clampedGain != gain) { - LOG_WARN("Out of bounds gain set. Clamping the gain from :%f to %f", gain, - clampedGain); + log::warn("Out of bounds gain set. Clamping the gain from :{:f} to {:f}", + gain, clampedGain); } trackHolder->gain = clampedGain; - LOG_INFO("Avrcp audio track gain is set to %f", trackHolder->gain); + log::info("Avrcp audio track gain is set to {:f}", trackHolder->gain); } } @@ -294,8 +296,8 @@ int BtifAvrcpAudioTrackWriteData(void* handle, void* audioBuffer, trackHolder->stream, trackHolder->buffer, transcodedCount / (sampleSize * trackHolder->channelCount), kTimeoutNanos); - LOG_VERBOSE("%s Track.cpp: btWriteData len = %d ret = %d", __func__, - bufferLength, retval); + log::verbose("Track.cpp: btWriteData len = {} ret = {}", bufferLength, + retval); } while (transcodedCount < bufferLength); return transcodedCount; diff --git a/system/btif/src/btif_bqr.cc b/system/btif/src/btif_bqr.cc index 5ee7a9d44b8..63e667daea7 100644 --- a/system/btif/src/btif_bqr.cc +++ b/system/btif/src/btif_bqr.cc @@ -19,6 +19,7 @@ #ifdef __ANDROID__ #include <statslog_bt.h> #endif +#include <bluetooth/log.h> #include <stdio.h> #include <sys/stat.h> @@ -58,10 +59,10 @@ std::unique_ptr<BluetoothQualityReportInterface> bluetoothQualityReportInstance; void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length, const uint8_t* p_param_buf) { if (length < kLinkQualityParamTotalLen) { - LOG(FATAL) << __func__ - << ": Parameter total length: " << std::to_string(length) - << " is abnormal. It shall be not shorter than: " - << std::to_string(kLinkQualityParamTotalLen); + log::fatal( + "Parameter total length: {} is abnormal. It shall be not shorter than: " + "{}", + length, kLinkQualityParamTotalLen); return; } @@ -91,17 +92,13 @@ void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length, if (vendor_cap_supported_version >= kBqrVersion5_0) { if (length < kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen + kVersion5_0ParamsTotalLen) { - LOG(WARNING) << __func__ - << ": Parameter total length: " << std::to_string(length) - << " is abnormal. " - << "vendor_cap_supported_version: " - << vendor_cap_supported_version << " " - << " (>= " - << "kBqrVersion5_0=" << kBqrVersion5_0 << "), " - << "It should not be shorter than: " - << std::to_string(kLinkQualityParamTotalLen + - kISOLinkQualityParamTotalLen + - kVersion5_0ParamsTotalLen); + log::warn( + "Parameter total length: {} is abnormal. " + "vendor_cap_supported_version: {} (>= kBqrVersion5_0={}), It should " + "not be shorter than: {}", + length, vendor_cap_supported_version, kBqrVersion5_0, + kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen + + kVersion5_0ParamsTotalLen); } else { STREAM_TO_BDADDR(bqr_link_quality_event_.bdaddr, p_param_buf); STREAM_TO_UINT8(bqr_link_quality_event_.cal_failed_item_count, @@ -111,16 +108,12 @@ void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length, if (vendor_cap_supported_version >= kBqrIsoVersion) { if (length < kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen) { - LOG(WARNING) << __func__ - << ": Parameter total length: " << std::to_string(length) - << " is abnormal. " - << "vendor_cap_supported_version: " - << vendor_cap_supported_version << " " - << " (>= " - << "kBqrIsoVersion=" << kBqrIsoVersion << "), " - << "It should not be shorter than: " - << std::to_string(kLinkQualityParamTotalLen + - kISOLinkQualityParamTotalLen); + log::warn( + "Parameter total length: {} is abnormal. " + "vendor_cap_supported_version: {} (>= kBqrIsoVersion={}), It should " + "not be shorter than: {}", + length, vendor_cap_supported_version, kBqrIsoVersion, + kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen); } else { STREAM_TO_UINT32(bqr_link_quality_event_.tx_total_packets, p_param_buf); STREAM_TO_UINT32(bqr_link_quality_event_.tx_unacked_packets, p_param_buf); @@ -313,7 +306,7 @@ std::string PacketTypeToString(uint8_t packet_type) { } void EnableBtQualityReport(bool is_enable) { - LOG(INFO) << __func__ << ": is_enable: " << logbool(is_enable); + log::info("is_enable: {}", logbool(is_enable)); char bqr_prop_evtmask[PROPERTY_VALUE_MAX] = {0}; char bqr_prop_interval_ms[PROPERTY_VALUE_MAX] = {0}; @@ -325,9 +318,10 @@ void EnableBtQualityReport(bool is_enable) { osi_property_get(kpPropertyVndTraceMask, bqr_prop_vnd_trace_mask, ""); if (strlen(bqr_prop_evtmask) == 0 || strlen(bqr_prop_interval_ms) == 0) { - LOG(WARNING) << __func__ << ": Bluetooth Quality Report is disabled." - << " bqr_prop_evtmask: " << bqr_prop_evtmask - << ", bqr_prop_interval_ms: " << bqr_prop_interval_ms; + log::warn( + "Bluetooth Quality Report is disabled. bqr_prop_evtmask: {}, " + "bqr_prop_interval_ms: {}", + bqr_prop_evtmask, bqr_prop_interval_ms); return; } @@ -355,11 +349,10 @@ void EnableBtQualityReport(bool is_enable) { BTM_BleGetVendorCapabilities(&cmn_vsc_cb); vendor_cap_supported_version = cmn_vsc_cb.version_supported; - LOG(INFO) << __func__ - << ": Event Mask: " << loghex(bqr_config.quality_event_mask) - << ", Interval: " << bqr_config.minimum_report_interval_ms - << ", vendor_cap_supported_version: " - << vendor_cap_supported_version; + log::info("Event Mask: {}, Interval: {}, vendor_cap_supported_version: {}", + loghex(bqr_config.quality_event_mask), + bqr_config.minimum_report_interval_ms, + vendor_cap_supported_version); ConfigureBqr(bqr_config); } @@ -367,17 +360,16 @@ void ConfigureBqr(const BqrConfiguration& bqr_config) { if (bqr_config.report_action > REPORT_ACTION_CLEAR || bqr_config.quality_event_mask > kQualityEventMaskAll || bqr_config.minimum_report_interval_ms > kMinReportIntervalMaxMs) { - LOG(FATAL) << __func__ << ": Invalid Parameter" - << ", Action: " << bqr_config.report_action - << ", Mask: " << loghex(bqr_config.quality_event_mask) - << ", Interval: " << bqr_config.minimum_report_interval_ms; + log::fatal("Invalid Parameter, Action: {}, Mask: {}, Interval: {}", + bqr_config.report_action, loghex(bqr_config.quality_event_mask), + bqr_config.minimum_report_interval_ms); return; } - LOG(INFO) << __func__ << ": Action: " - << loghex(static_cast<uint8_t>(bqr_config.report_action)) - << ", Mask: " << loghex(bqr_config.quality_event_mask) - << ", Interval: " << bqr_config.minimum_report_interval_ms; + log::info("Action: {}, Mask: {}, Interval: {}", + loghex(static_cast<uint8_t>(bqr_config.report_action)), + loghex(bqr_config.quality_event_mask), + bqr_config.minimum_report_interval_ms); uint8_t param[sizeof(BqrConfiguration)]; uint8_t* p_param = param; @@ -395,8 +387,7 @@ void ConfigureBqr(const BqrConfiguration& bqr_config) { void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) { if (p_vsc_cmpl_params->param_len < 1) { - LOG(ERROR) << __func__ - << ": The length of returned parameters is less than 1"; + log::error("The length of returned parameters is less than 1"); return; } @@ -412,8 +403,7 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) { // Vendor_Specific_Trace_Mask | 4 octets | vendor trace bit mask setting STREAM_TO_UINT8(status, p_event_param_buf); if (status != HCI_SUCCESS) { - LOG(ERROR) << __func__ - << ": Fail to configure BQR. status: " << loghex(status); + log::error("Fail to configure BQR. status: {}", loghex(status)); return; } @@ -422,9 +412,8 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) { } if (p_vsc_cmpl_params->param_len != command_complete_param_len) { - LOG(FATAL) << __func__ - << ": The length of returned parameters is incorrect: " - << std::to_string(p_vsc_cmpl_params->param_len); + log::fatal("The length of returned parameters is incorrect: {}", + p_vsc_cmpl_params->param_len); return; } @@ -436,10 +425,9 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) { STREAM_TO_UINT32(current_vnd_trace_mask, p_event_param_buf); } - LOG(INFO) << __func__ - << ", current event mask: " << loghex(current_quality_event_mask) - << ", vendor quality: " << loghex(current_vnd_quality_mask) - << ", vendor trace: " << loghex(current_vnd_trace_mask); + log::info("current event mask: {}, vendor quality: {}, vendor trace: {}", + loghex(current_quality_event_mask), + loghex(current_vnd_quality_mask), loghex(current_vnd_trace_mask)); ConfigureBqrCmpl(current_quality_event_mask); } @@ -457,8 +445,8 @@ void ConfigBqrA2dpScoThreshold() { sscanf(bqr_prop_threshold, "%hu,%hu", &a2dp_choppy_threshold, &sco_choppy_threshold); - LOG_WARN("a2dp_choppy_threshold: %d, sco_choppy_threshold: %d", - a2dp_choppy_threshold, sco_choppy_threshold); + log::warn("a2dp_choppy_threshold: {}, sco_choppy_threshold: {}", + a2dp_choppy_threshold, sco_choppy_threshold); UINT8_TO_STREAM(p_param, sub_opcode); @@ -483,7 +471,7 @@ void ConfigBqrA2dpScoThreshold() { } void ConfigureBqrCmpl(uint32_t current_evt_mask) { - LOG(INFO) << __func__ << ": current_evt_mask: " << loghex(current_evt_mask); + log::info("current_evt_mask: {}", loghex(current_evt_mask)); // (Un)Register for VSE of Bluetooth Quality Report sub event tBTM_STATUS btm_status = BTM_BT_Quality_Report_VSE_Register( current_evt_mask > kQualityEventMaskAllOff, CategorizeBqrEvent); @@ -495,20 +483,20 @@ void ConfigureBqrCmpl(uint32_t current_evt_mask) { } if (btm_status != BTM_SUCCESS) { - LOG(ERROR) << __func__ << ": Fail to (un)register VSE of BQR sub event." - << " status: " << btm_status; + log::error("Fail to (un)register VSE of BQR sub event. status: {}", + btm_status); return; } if (LmpLlMessageTraceLogFd != INVALID_FD && (current_evt_mask & kQualityEventMaskLmpMessageTrace) == 0) { - LOG(INFO) << __func__ << ": Closing LMP/LL log file."; + log::info("Closing LMP/LL log file."); close(LmpLlMessageTraceLogFd); LmpLlMessageTraceLogFd = INVALID_FD; } if (BtSchedulingTraceLogFd != INVALID_FD && (current_evt_mask & kQualityEventMaskBtSchedulingTrace) == 0) { - LOG(INFO) << __func__ << ": Closing Scheduling log file."; + log::info("Closing Scheduling log file."); close(BtSchedulingTraceLogFd); BtSchedulingTraceLogFd = INVALID_FD; } @@ -516,7 +504,7 @@ void ConfigureBqrCmpl(uint32_t current_evt_mask) { void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) { if (length == 0) { - LOG(WARNING) << __func__ << ": Lengths of all of the parameters are zero."; + log::warn("Lengths of all of the parameters are zero."); return; } @@ -529,10 +517,10 @@ void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) { case QUALITY_REPORT_ID_LE_AUDIO_CHOPPY: case QUALITY_REPORT_ID_CONNECT_FAIL: if (length < kLinkQualityParamTotalLen) { - LOG(FATAL) << __func__ - << ": Parameter total length: " << std::to_string(length) - << " is abnormal. It shall be not shorter than: " - << std::to_string(kLinkQualityParamTotalLen); + log::fatal( + "Parameter total length: {} is abnormal. It shall be not shorter " + "than: {}", + length, kLinkQualityParamTotalLen); return; } @@ -547,12 +535,11 @@ void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) { case QUALITY_REPORT_ID_BT_SCHEDULING_TRACE: case QUALITY_REPORT_ID_CONTROLLER_DBG_INFO: case QUALITY_REPORT_ID_VENDOR_SPECIFIC_TRACE: - LOG(WARNING) << __func__ - << ": Unexpected ID: " << loghex(quality_report_id); + log::warn("Unexpected ID: {}", loghex(quality_report_id)); break; default: - LOG(WARNING) << __func__ << ": Unknown ID: " << loghex(quality_report_id); + log::warn("Unknown ID: {}", loghex(quality_report_id)); break; } } @@ -564,7 +551,7 @@ void AddLinkQualityEventToQueue(uint8_t length, p_bqr_event->ParseBqrLinkQualityEvt(length, p_link_quality_event); - LOG(WARNING) << *p_bqr_event; + log::warn("{}", *p_bqr_event); GetInterfaceToProfiles()->events->invoke_link_quality_report_cb( bluetooth::common::time_get_os_boottime_ms(), p_bqr_event->bqr_link_quality_event_.quality_report_id, @@ -597,8 +584,7 @@ void AddLinkQualityEventToQueue(uint8_t length, p_bqr_event->bqr_link_quality_event_.buffer_overflow_bytes, p_bqr_event->bqr_link_quality_event_.buffer_underflow_bytes); if (ret < 0) { - LOG(WARNING) << __func__ << ": failed to log BQR event to statsd, error " - << ret; + log::warn("failed to log BQR event to statsd, error {}", ret); } #else // TODO(abps) Metrics for non-Android build @@ -623,11 +609,10 @@ void AddLinkQualityEventToQueue(uint8_t length, bqrItf->bqr_delivery_event(bd_addr, (uint8_t*)p_link_quality_event, length); } else { - LOG(WARNING) << __func__ << ": failed to deliver BQR, " - << "bdaddr is empty"; + log::warn("failed to deliver BQR, bdaddr is empty"); } } else { - LOG(WARNING) << __func__ << ": failed to deliver BQR, bqrItf is NULL"; + log::warn("failed to deliver BQR, bqrItf is NULL"); } } @@ -650,9 +635,8 @@ void DumpLmpLlMessage(uint8_t length, const uint8_t* p_lmp_ll_message_event) { int OpenLmpLlTraceLogFile() { if (rename(kpLmpLlMessageTraceLogPath, kpLmpLlMessageTraceLastLogPath) != 0 && errno != ENOENT) { - LOG(ERROR) << __func__ << ": Unable to rename '" - << kpLmpLlMessageTraceLogPath << "' to '" - << kpLmpLlMessageTraceLastLogPath << "' : " << strerror(errno); + log::error("Unable to rename '{}' to '{}' : {}", kpLmpLlMessageTraceLogPath, + kpLmpLlMessageTraceLastLogPath, strerror(errno)); } mode_t prevmask = umask(0); @@ -661,8 +645,8 @@ int OpenLmpLlTraceLogFile() { S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); umask(prevmask); if (logfile_fd == INVALID_FD) { - LOG(ERROR) << __func__ << ": Unable to open '" << kpLmpLlMessageTraceLogPath - << "' : " << strerror(errno); + log::error("Unable to open '{}' : {}", kpLmpLlMessageTraceLogPath, + strerror(errno)); } else { LmpLlMessageTraceCounter = 0; } @@ -685,9 +669,8 @@ void DumpBtScheduling(uint8_t length, const uint8_t* p_bt_scheduling_event) { int OpenBtSchedulingTraceLogFile() { if (rename(kpBtSchedulingTraceLogPath, kpBtSchedulingTraceLastLogPath) != 0 && errno != ENOENT) { - LOG(ERROR) << __func__ << ": Unable to rename '" - << kpBtSchedulingTraceLogPath << "' to '" - << kpBtSchedulingTraceLastLogPath << "' : " << strerror(errno); + log::error("Unable to rename '{}' to '{}' : {}", kpBtSchedulingTraceLogPath, + kpBtSchedulingTraceLastLogPath, strerror(errno)); } mode_t prevmask = umask(0); @@ -696,8 +679,8 @@ int OpenBtSchedulingTraceLogFile() { S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); umask(prevmask); if (logfile_fd == INVALID_FD) { - LOG(ERROR) << __func__ << ": Unable to open '" << kpBtSchedulingTraceLogPath - << "' : " << strerror(errno); + log::error("Unable to open '{}' : {}", kpBtSchedulingTraceLogPath, + strerror(errno)); } else { BtSchedulingTraceCounter = 0; } @@ -767,7 +750,7 @@ class BluetoothQualityReportInterfaceImpl ~BluetoothQualityReportInterfaceImpl() override = default; void init(BluetoothQualityReportCallbacks* callbacks) override { - LOG_INFO("BluetoothQualityReportInterfaceImpl "); + log::info("BluetoothQualityReportInterfaceImpl"); this->callbacks = callbacks; } @@ -775,7 +758,7 @@ class BluetoothQualityReportInterfaceImpl const uint8_t* bqr_raw_data, uint32_t bqr_raw_data_len) override { if (bqr_raw_data == NULL) { - LOG_ERROR("bqr data is null"); + log::error("bqr data is null"); return; } @@ -800,13 +783,13 @@ class BluetoothQualityReportInterfaceImpl uint16_t manufacturer_id = 0; btif_get_remote_version(bd_addr, lmp_ver, manufacturer_id, lmp_subver); - LOG_INFO( - "len: %d, addr: %s, lmp_ver: %d, manufacturer_id: %d, lmp_subver: %d", + log::info( + "len: {}, addr: {}, lmp_ver: {}, manufacturer_id: {}, lmp_subver: {}", bqr_raw_data_len, ADDRESS_TO_LOGGABLE_CSTR(bd_addr), lmp_ver, manufacturer_id, lmp_subver); if (callbacks == nullptr) { - LOG_ERROR("callbacks is nullptr"); + log::error("callbacks is nullptr"); return; } diff --git a/system/btif/src/btif_config.cc b/system/btif/src/btif_config.cc index 9f304f8848f..b3ea4a63960 100644 --- a/system/btif/src/btif_config.cc +++ b/system/btif/src/btif_config.cc @@ -21,6 +21,7 @@ #include "btif_config.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <openssl/rand.h> #include <unistd.h> @@ -54,6 +55,7 @@ using bluetooth::bluetooth_keystore::BluetoothKeystoreInterface; using bluetooth::common::AddressObfuscator; using bluetooth::common::MetricIdAllocator; +using namespace bluetooth; // Key attestation static const std::string ENCRYPTED_STR = "encrypted"; @@ -84,25 +86,25 @@ static void read_or_set_metrics_salt() { if (!btif_config_get_bin(BTIF_STORAGE_SECTION_METRICS, BTIF_STORAGE_KEY_METRICS_SALT_256BIT, metrics_salt.data(), &metrics_salt_length)) { - LOG(WARNING) << __func__ << ": Failed to read metrics salt from config"; + log::warn("Failed to read metrics salt from config"); // Invalidate salt metrics_salt.fill(0); } if (metrics_salt_length != metrics_salt.size()) { - LOG(ERROR) << __func__ << ": Metrics salt length incorrect, " - << metrics_salt_length << " instead of " << metrics_salt.size(); + log::error("Metrics salt length incorrect, {} instead of {}", + metrics_salt_length, metrics_salt.size()); // Invalidate salt metrics_salt.fill(0); } if (!AddressObfuscator::IsSaltValid(metrics_salt)) { - LOG(INFO) << __func__ << ": Metrics salt is invalid, creating new one"; + log::info("Metrics salt is invalid, creating new one"); if (RAND_bytes(metrics_salt.data(), metrics_salt.size()) != 1) { - LOG(FATAL) << __func__ << "Failed to generate salt for metrics"; + log::fatal("Failed to generate salt for metrics"); } if (!btif_config_set_bin(BTIF_STORAGE_SECTION_METRICS, BTIF_STORAGE_KEY_METRICS_SALT_256BIT, metrics_salt.data(), metrics_salt.size())) { - LOG(FATAL) << __func__ << "Failed to write metrics salt to config"; + log::fatal("Failed to write metrics salt to config"); } } AddressObfuscator::GetInstance()->Initialize(metrics_salt); @@ -152,7 +154,7 @@ static void init_metric_id_allocator() { if (!init_metric_id_allocator(paired_device_map, std::move(save_device_callback), std::move(forget_device_callback))) { - LOG(FATAL) << __func__ << "Failed to initialize MetricIdAllocator"; + log::fatal("Failed to initialize MetricIdAllocator"); } // Add device_without_id @@ -205,8 +207,7 @@ bool btif_get_device_clockoffset(const RawAddress& bda, int* p_clock_offset) { p_clock_offset)) return false; - LOG_DEBUG("%s: Device [%s] clock_offset %d", __func__, bd_addr_str, - *p_clock_offset); + log::debug("Device [{}] clock_offset {}", bd_addr_str, *p_clock_offset); return true; } @@ -219,8 +220,7 @@ bool btif_set_device_clockoffset(const RawAddress& bda, int clock_offset) { clock_offset)) return false; - LOG_DEBUG("%s: Device [%s] clock_offset %d", __func__, bd_addr_str, - clock_offset); + log::debug("Device [{}] clock_offset {}", bd_addr_str, clock_offset); return true; } diff --git a/system/btif/src/btif_config_cache.cc b/system/btif/src/btif_config_cache.cc index c8f03cda716..05b1beca393 100644 --- a/system/btif/src/btif_config_cache.cc +++ b/system/btif/src/btif_config_cache.cc @@ -17,6 +17,7 @@ #include "btif_config_cache.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <limits> #include <unordered_set> @@ -25,6 +26,8 @@ #include "storage/config_keys.h" #include "types/raw_address.h" +using namespace bluetooth; + namespace { const std::unordered_set<std::string> kLinkKeyTypes = { @@ -67,7 +70,7 @@ bool trim_new_line(std::string& value) { BtifConfigCache::BtifConfigCache(size_t capacity) : unpaired_devices_cache_(capacity, "bt_config_cache") { - LOG(INFO) << __func__ << ", capacity: " << capacity; + log::info("capacity: {}", capacity); } BtifConfigCache::~BtifConfigCache() { Clear(); } @@ -178,11 +181,11 @@ void BtifConfigCache::SetString(std::string section_name, std::string key, trim_new_line(key); trim_new_line(value); if (section_name.empty()) { - LOG(FATAL) << "Empty section not allowed"; + log::fatal("Empty section not allowed"); return; } if (key.empty()) { - LOG(FATAL) << "Empty key not allowed"; + log::fatal("Empty key not allowed"); return; } if (!paired_devices_list_.Has(section_name)) { @@ -214,7 +217,7 @@ void BtifConfigCache::SetString(std::string section_name, std::string key, // already have section in paired device list, add key-value entry. auto section_found = paired_devices_list_.Find(section_name); if (section_found == paired_devices_list_.sections.end()) { - LOG(WARNING) << __func__ << " , section_found not found!"; + log::warn("section_found not found!"); return; } section_found->Set(key, value); @@ -258,13 +261,14 @@ std::optional<int> BtifConfigCache::GetInt(const std::string& section_name, char* endptr; long ret_long = strtol(value->c_str(), &endptr, 0); if (*endptr != '\0') { - LOG(WARNING) << "Failed to parse value to long for section " << section_name - << ", key " << key; + log::warn("Failed to parse value to long for section {}, key {}", + section_name, key); return std::nullopt; } if (ret_long >= std::numeric_limits<int>::max()) { - LOG(WARNING) << "Integer overflow when parsing value to int for section " - << section_name << ", key " << key; + log::warn( + "Integer overflow when parsing value to int for section {}, key {}", + section_name, key); return std::nullopt; } return static_cast<int>(ret_long); @@ -284,8 +288,8 @@ std::optional<uint64_t> BtifConfigCache::GetUint64( char* endptr; uint64_t ret = strtoull(value->c_str(), &endptr, 0); if (*endptr != '\0') { - LOG(WARNING) << "Failed to parse value to uint64 for section " - << section_name << ", key " << key; + log::warn("Failed to parse value to uint64 for section {}, key {}", + section_name, key); return std::nullopt; } return ret; @@ -308,7 +312,7 @@ std::optional<bool> BtifConfigCache::GetBool(const std::string& section_name, if (*value == "false") { return false; } - LOG(WARNING) << "Failed to parse value to boolean for section " - << section_name << ", key " << key; + log::warn("Failed to parse value to boolean for section {}, key {}", + section_name, key); return std::nullopt; } diff --git a/system/btif/src/btif_core.cc b/system/btif/src/btif_core.cc index 349722007b2..56ffd20f1ec 100644 --- a/system/btif/src/btif_core.cc +++ b/system/btif/src/btif_core.cc @@ -32,6 +32,7 @@ #include <base/functional/bind.h> #include <base/logging.h> #include <base/threading/platform_thread.h> +#include <bluetooth/log.h> #include <signal.h> #include <sys/types.h> @@ -68,6 +69,7 @@ using base::PlatformThread; using bluetooth::Uuid; using bluetooth::common::MessageLoopThread; +using namespace bluetooth; /******************************************************************************* * Constants & Macros @@ -154,11 +156,11 @@ void btif_init_ok() { * ******************************************************************************/ bt_status_t btif_init_bluetooth() { - LOG_INFO("%s entered", __func__); + log::info("entered"); exit_manager = new base::AtExitManager(); jni_thread_startup(); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(ASSOCIATE_JVM); - LOG_INFO("%s finished", __func__); + log::info("finished"); return BT_STATUS_SUCCESS; } @@ -190,8 +192,8 @@ void btif_enable_bluetooth_evt() { strcmp(bdstr.c_str(), val) != 0) { // We failed to get an address or the one in the config file does not match // the address given by the controller interface. Update the config cache - LOG_INFO("Storing '%s' into the config file", - ADDRESS_TO_LOGGABLE_CSTR(local_bd_addr)); + log::info("Storing '{}' into the config file", + ADDRESS_TO_LOGGABLE_CSTR(local_bd_addr)); btif_config_set_str(BTIF_STORAGE_SECTION_ADAPTER, BTIF_STORAGE_KEY_ADDRESS, bdstr.c_str()); @@ -220,7 +222,7 @@ void btif_enable_bluetooth_evt() { btif_dm_load_local_oob(); future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS); - LOG_INFO("Bluetooth enable event completed"); + log::info("Bluetooth enable event completed"); } /******************************************************************************* @@ -234,7 +236,7 @@ void btif_enable_bluetooth_evt() { ******************************************************************************/ bt_status_t btif_cleanup_bluetooth() { - LOG_INFO("%s entered", __func__); + log::info("entered"); btif_dm_cleanup(); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(DISASSOCIATE_JVM); btif_queue_release(); @@ -242,7 +244,7 @@ bt_status_t btif_cleanup_bluetooth() { delete exit_manager; exit_manager = nullptr; btif_dut_mode = 0; - LOG_INFO("%s finished", __func__); + log::info("finished"); return BT_STATUS_SUCCESS; } @@ -255,7 +257,7 @@ bt_status_t btif_cleanup_bluetooth() { * ******************************************************************************/ void btif_dut_mode_configure(uint8_t enable) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_dut_mode = enable; if (enable == 1) { @@ -274,7 +276,7 @@ void btif_dut_mode_configure(uint8_t enable) { * ******************************************************************************/ void btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); /* For now nothing to be done. */ BTM_VendorSpecificCommand(opcode, len, buf, [](tBTM_VSC_CMPL*) {}); } @@ -401,7 +403,8 @@ static bt_status_t btif_in_get_remote_device_properties(RawAddress* bd_addr) { } static void btif_core_storage_adapter_write(bt_property_t* prop) { - LOG_VERBOSE("type: %d, len %d, 0x%p", prop->type, prop->len, prop->val); + log::verbose("type: {}, len {}, {}", prop->type, prop->len, + fmt::ptr(prop->val)); bt_status_t status = btif_storage_set_adapter_property(prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1, prop); @@ -427,7 +430,7 @@ void btif_remote_properties_evt(bt_status_t status, RawAddress* remote_addr, ******************************************************************************/ void btif_get_adapter_properties(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_in_get_adapter_properties(); } @@ -441,7 +444,7 @@ void btif_get_adapter_properties(void) { ******************************************************************************/ void btif_get_adapter_property(bt_property_type_t type) { - LOG_VERBOSE("%s %d", __func__, type); + log::verbose("{}", type); bt_status_t status = BT_STATUS_SUCCESS; char buf[512]; @@ -518,7 +521,7 @@ void btif_get_adapter_property(bt_property_type_t type) { prop.len = sizeof(bt_dynamic_audio_buffer_item_t); if (GetInterfaceToProfiles()->config->isA2DPOffloadEnabled() == false) { - LOG_VERBOSE("%s Get buffer millis for A2DP software encoding", __func__); + log::verbose("Get buffer millis for A2DP software encoding"); for (int i = 0; i < CODEC_TYPE_NUMBER; i++) { dynamic_audio_buffer_item.dab_item[i] = { .default_buffer_time = DEFAULT_BUFFER_TIME, @@ -528,7 +531,7 @@ void btif_get_adapter_property(bt_property_type_t type) { memcpy(prop.val, &dynamic_audio_buffer_item, prop.len); } else { if (cmn_vsc_cb.dynamic_audio_buffer_support != 0) { - LOG_VERBOSE("%s Get buffer millis for A2DP Offload", __func__); + log::verbose("Get buffer millis for A2DP Offload"); tBTM_BT_DYNAMIC_AUDIO_BUFFER_CB bt_dynamic_audio_buffer_cb[CODEC_TYPE_NUMBER]; BTM_BleGetDynamicAudioBuffer(bt_dynamic_audio_buffer_cb); @@ -544,7 +547,7 @@ void btif_get_adapter_property(bt_property_type_t type) { } memcpy(prop.val, &dynamic_audio_buffer_item, prop.len); } else { - LOG_VERBOSE("%s Don't support Dynamic Audio Buffer", __func__); + log::verbose("Don't support Dynamic Audio Buffer"); } } } else { @@ -576,8 +579,8 @@ bt_property_t* property_deep_copy(const bt_property_t* prop) { ******************************************************************************/ void btif_set_adapter_property(bt_property_t* property) { - LOG_VERBOSE("btif_set_adapter_property type: %d, len %d, 0x%p", - property->type, property->len, property->val); + log::verbose("btif_set_adapter_property type: {}, len {}, {}", property->type, + property->len, fmt::ptr(property->val)); switch (property->type) { case BT_PROPERTY_BDNAME: { @@ -588,7 +591,7 @@ void btif_set_adapter_property(bt_property_t* property) { memcpy(bd_name, property->val, name_len); bd_name[name_len] = '\0'; - LOG_VERBOSE("set property name : %s", (char*)bd_name); + log::verbose("set property name : {}", (char*)bd_name); BTA_DmSetDeviceName((const char*)bd_name); @@ -597,7 +600,7 @@ void btif_set_adapter_property(bt_property_t* property) { case BT_PROPERTY_ADAPTER_SCAN_MODE: { bt_scan_mode_t mode = *(bt_scan_mode_t*)property->val; - LOG_VERBOSE("set property scan mode : %x", mode); + log::verbose("set property scan mode : {:x}", mode); if (BTA_DmSetVisibility(mode)) { btif_core_storage_adapter_write(property); @@ -692,7 +695,7 @@ tBTA_SERVICE_MASK btif_get_enabled_services_mask(void) { void btif_enable_service(tBTA_SERVICE_ID service_id) { btif_enabled_services |= (1 << service_id); - LOG_VERBOSE("%s: current services:0x%x", __func__, btif_enabled_services); + log::verbose("current services:0x{:x}", btif_enabled_services); if (btif_is_enabled()) { btif_dm_enable_service(service_id, true); @@ -710,7 +713,7 @@ void btif_enable_service(tBTA_SERVICE_ID service_id) { void btif_disable_service(tBTA_SERVICE_ID service_id) { btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id)); - LOG_VERBOSE("%s: Current Services:0x%x", __func__, btif_enabled_services); + log::verbose("Current Services:0x{:x}", btif_enabled_services); if (btif_is_enabled()) { btif_dm_enable_service(service_id, false); @@ -718,24 +721,23 @@ void btif_disable_service(tBTA_SERVICE_ID service_id) { } bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); tBTM_BLE_VSC_CB cmn_vsc_cb; BTM_BleGetVendorCapabilities(&cmn_vsc_cb); if (!GetInterfaceToProfiles()->config->isA2DPOffloadEnabled()) { - LOG_VERBOSE("%s Set buffer size (%d) for A2DP software encoding", __func__, - size); + log::verbose("Set buffer size ({}) for A2DP software encoding", size); GetInterfaceToProfiles() ->profileSpecific_HACK->btif_av_set_dynamic_audio_buffer_size( uint8_t(size)); } else { if (cmn_vsc_cb.dynamic_audio_buffer_support != 0) { - LOG_VERBOSE("%s Set buffer size (%d) for A2DP offload", __func__, size); + log::verbose("Set buffer size ({}) for A2DP offload", size); uint16_t firmware_tx_buffer_length_byte; firmware_tx_buffer_length_byte = static_cast<uint16_t>(size); - LOG(INFO) << __func__ << "firmware_tx_buffer_length_byte: " - << firmware_tx_buffer_length_byte; + log::info("firmware_tx_buffer_length_byte: {}", + firmware_tx_buffer_length_byte); bluetooth::shim::GetController()->SetDabAudioBufferTime( firmware_tx_buffer_length_byte); } diff --git a/system/btif/src/btif_csis_client.cc b/system/btif/src/btif_csis_client.cc index 70271286d12..387a8c2d1fc 100644 --- a/system/btif/src/btif_csis_client.cc +++ b/system/btif/src/btif_csis_client.cc @@ -18,6 +18,7 @@ #include <base/functional/bind.h> #include <base/location.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_csis.h> @@ -37,6 +38,7 @@ using bluetooth::csis::CsisClientInterface; using bluetooth::csis::CsisGroupLockStatus; using bluetooth::csis::CsisClient; +using namespace bluetooth; namespace { std::unique_ptr<CsisClientInterface> csis_client_instance; @@ -62,9 +64,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface, void Connect(const RawAddress& addr) override { if (!initialized || !CsisClient::IsCsisClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -74,9 +76,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface, void Disconnect(const RawAddress& addr) override { if (!initialized || !CsisClient::IsCsisClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -86,9 +88,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface, void RemoveDevice(const RawAddress& addr) override { if (!initialized || !CsisClient::IsCsisClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not ready"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not ready"); /* Clear storage */ do_in_jni_thread(FROM_HERE, Bind(&btif_storage_remove_csis_device, addr)); @@ -103,9 +105,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface, void LockGroup(int group_id, bool lock) override { if (!initialized || !CsisClient::IsCsisClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -116,9 +118,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface, void Cleanup(void) override { if (!initialized || !CsisClient::IsCsisClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc index 324c77c379a..4c4a5a46933 100644 --- a/system/btif/src/btif_dm.cc +++ b/system/btif/src/btif_dm.cc @@ -26,7 +26,6 @@ * ******************************************************************************/ -#include "bt_dev_class.h" #define LOG_TAG "bt_btif_dm" #include "btif_dm.h" @@ -35,6 +34,7 @@ #include <base/functional/bind.h> #include <base/logging.h> #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <bluetooth/uuid.h> #include <hardware/bluetooth.h> #include <hardware/bt_csis.h> @@ -53,6 +53,7 @@ #include <optional> #include "advertise_data_parser.h" +#include "bt_dev_class.h" #include "bta/dm/bta_dm_disc.h" #include "bta/include/bta_api.h" #include "btif/include/stack_manager_t.h" @@ -106,6 +107,7 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type); using bluetooth::Uuid; +using namespace bluetooth; namespace { constexpr char kBtmLogTag[] = "API"; @@ -177,6 +179,12 @@ struct btif_dm_pairing_cb_t { ServiceDiscoveryState sdp_over_classic; }; +namespace fmt { +template <> +struct formatter<btif_dm_pairing_cb_t::ServiceDiscoveryState> + : enum_formatter<btif_dm_pairing_cb_t::ServiceDiscoveryState> {}; +} // namespace fmt + // TODO(jpawlowski): unify ? // btif_dm_local_key_id_t == tBTM_BLE_LOCAL_ID_KEYS == tBTA_BLE_LOCAL_ID_KEYS typedef struct { @@ -318,7 +326,7 @@ void btif_dm_cleanup(void) { bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id, bool b_enable) { - LOG_VERBOSE("service_id:%d", service_id); + log::verbose("service_id:{}", service_id); if (service_id == BTA_SDP_SERVICE_ID) { btif_sdp_execute_service(b_enable); @@ -359,15 +367,15 @@ static void get_asha_service_data(const tBTA_DM_INQ_RES& inq_res, STREAM_TO_UINT16(uuid, p_uuid); if (uuid == 0xfdf0 /* ASHA service*/) { - LOG_INFO("ASHA found in %s", ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); + log::info("ASHA found in {}", ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); // ASHA advertisement service data length should be at least 8 if (service_data_len < 8) { - LOG_WARN("ASHA device service_data_len too short"); + log::warn("ASHA device service_data_len too short"); } else { // It is intended to save ASHA capability byte to int16_t asha_capability = p_service_data[3]; - LOG_INFO("asha_capability: %d", asha_capability); + log::info("asha_capability: {}", asha_capability); const uint8_t* p_truncated_hisyncid = &(p_service_data[4]); STREAM_TO_UINT32(asha_truncated_hi_sync_id, p_truncated_hisyncid); @@ -495,7 +503,7 @@ static uint32_t get_cod(const RawAddress* remote_bdaddr) { sizeof(uint32_t), &remote_cod); if (btif_storage_get_remote_device_property( (RawAddress*)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) { - LOG_INFO("remote_cod=0x%08x", remote_cod); + log::info("remote_cod=0x{:08x}", remote_cod); return remote_cod; } @@ -580,9 +588,9 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, state = BT_BOND_STATE_NONE; } - LOG_INFO( - "Bond state changed to state=%d[0:none, 1:bonding, 2:bonded]," - "prev_state=%d, sdp_attempts=%d", + log::info( + "Bond state changed to state={}[0:none, 1:bonding, " + "2:bonded],prev_state={}, sdp_attempts={}", state, pairing_cb.state, pairing_cb.sdp_attempts); if (state == BT_BOND_STATE_NONE) { @@ -597,8 +605,8 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, } else if (state == BT_BOND_STATE_BONDED) { allocate_metric_id_from_metric_id_allocator(bd_addr); if (!save_metric_id_from_metric_id_allocator(bd_addr)) { - LOG_ERROR("Fail to save metric id for device:%s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::error("Fail to save metric id for device:{}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } } BTM_LogHistory( @@ -613,8 +621,10 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, if ((state == BT_BOND_STATE_NONE) && (pairing_cb.bd_addr != bd_addr) && is_bonding_or_sdp()) { - LOG_WARN("Ignoring bond state changed for unexpected device: %s pairing: %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), ADDRESS_TO_LOGGABLE_CSTR(pairing_cb.bd_addr)); + log::warn( + "Ignoring bond state changed for unexpected device: {} pairing: {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), + ADDRESS_TO_LOGGABLE_CSTR(pairing_cb.bd_addr)); return; } @@ -627,7 +637,7 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, pairing_cb.state = state; pairing_cb.bd_addr = bd_addr; } else { - LOG_DEBUG("clearing btif pairing_cb"); + log::debug("clearing btif pairing_cb"); pairing_cb = {}; } } @@ -647,9 +657,9 @@ static void btif_update_remote_version_property(RawAddress* p_bd) { const bool version_info_valid = BTM_ReadRemoteVersion(*p_bd, &lmp_ver, &mfct_set, &lmp_subver); - LOG_INFO("Remote version info valid:%s [%s]:0x%x,0x%x,0x%x", - logbool(version_info_valid).c_str(), - ADDRESS_TO_LOGGABLE_CSTR((*p_bd)), lmp_ver, mfct_set, lmp_subver); + log::info("Remote version info valid:{} [{}]:0x{:x},0x{:x},0x{:x}", + logbool(version_info_valid), ADDRESS_TO_LOGGABLE_CSTR((*p_bd)), + lmp_ver, mfct_set, lmp_subver); if (version_info_valid) { // Always update cache to ensure we have availability whenever BTM API is @@ -691,18 +701,18 @@ static void btif_update_remote_properties(const RawAddress& bdaddr, cod = devclass2uint(dev_class); if ((cod == 0) || (cod == COD_UNCLASSIFIED)) { /* Try to retrieve cod from storage */ - LOG_VERBOSE("class of device (cod) is unclassified, checking storage"); + log::verbose("class of device (cod) is unclassified, checking storage"); BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); status = btif_storage_get_remote_device_property( &bdaddr, &properties[num_properties]); - LOG_VERBOSE("cod retrieved from storage is 0x%06x", cod); + log::verbose("cod retrieved from storage is 0x{:06x}", cod); if (cod == 0) { - LOG_INFO("cod from storage is also unclassified"); + log::info("cod from storage is also unclassified"); cod = COD_UNCLASSIFIED; } } else { - LOG_INFO("class of device (cod) is 0x%06x", cod); + log::info("class of device (cod) is 0x{:06x}", cod); } BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], @@ -817,7 +827,7 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr, bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); if (transport == BT_TRANSPORT_AUTO && is_device_le_audio_capable(bd_addr)) { - LOG_DEBUG("LE Audio capable, forcing LE transport for Bonding"); + log::debug("LE Audio capable, forcing LE transport for Bonding"); transport = BT_TRANSPORT_LE; } @@ -910,8 +920,8 @@ uint16_t btif_dm_get_connection_state(const RawAddress& bd_addr) { rc |= ENCRYPTED_LE; } } else { - LOG_INFO("Acl is not connected to peer:%s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("Acl is not connected to peer:{}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } BTM_LogHistory( @@ -1006,7 +1016,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) { if (pairing_cb.state == BT_BOND_STATE_BONDING && bd_addr != pairing_cb.bd_addr) { - LOG_WARN("already in bonding state, reject request"); + log::warn("already in bonding state, reject request"); return; } @@ -1015,7 +1025,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) { cod = devclass2uint(p_pin_req->dev_class); if (cod == 0) { - LOG_WARN("cod is 0, set as unclassified"); + log::warn("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } @@ -1032,7 +1042,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) { !interop_match_name(INTEROP_DISABLE_AUTO_PAIRING, (const char*)bd_name.name) && (pairing_cb.autopair_attempts == 0)) { - LOG_DEBUG("Attempting auto pair w/ IOP"); + log::debug("Attempting auto pair w/ IOP"); pin_code.pin[0] = 0x30; pin_code.pin[1] = 0x30; pin_code.pin[2] = 0x30; @@ -1047,7 +1057,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) { if ((interop_match_addr(INTEROP_KEYBOARD_REQUIRES_FIXED_PIN, &bd_addr) == true) && (pairing_cb.autopair_attempts == 0)) { - LOG_DEBUG("Attempting auto pair w/ IOP"); + log::debug("Attempting auto pair w/ IOP"); pin_code.pin[0] = 0x30; pin_code.pin[1] = 0x30; pin_code.pin[2] = 0x30; @@ -1082,10 +1092,10 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) { uint32_t cod; int dev_type; - LOG_VERBOSE("addr:%s, just_works:%d, loc_auth_req=%d, rmt_auth_req=%d", - ADDRESS_TO_LOGGABLE_CSTR(p_ssp_cfm_req->bd_addr), - p_ssp_cfm_req->just_works, p_ssp_cfm_req->loc_auth_req, - p_ssp_cfm_req->rmt_auth_req); + log::verbose("addr:{}, just_works:{}, loc_auth_req={}, rmt_auth_req={}", + ADDRESS_TO_LOGGABLE_CSTR(p_ssp_cfm_req->bd_addr), + p_ssp_cfm_req->just_works, p_ssp_cfm_req->loc_auth_req, + p_ssp_cfm_req->rmt_auth_req); /* Remote properties update */ if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_cfm_req->bd_addr) == BT_DEVICE_TYPE_DUMO) { @@ -1103,7 +1113,7 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) { if (pairing_cb.state == BT_BOND_STATE_BONDING && bd_addr != pairing_cb.bd_addr) { - LOG_WARN("already in bonding state, reject request"); + log::warn("already in bonding state, reject request"); btif_dm_ssp_reply(bd_addr, BT_SSP_VARIANT_PASSKEY_CONFIRMATION, 0); return; } @@ -1131,7 +1141,8 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) { * Incoming temporary pairing is detected */ if (is_incoming && pairing_cb.bond_type == BOND_TYPE_TEMPORARY) { - LOG_DEBUG("Auto-accept JustWorks incoming pairing for temporary bonding"); + log::debug( + "Auto-accept JustWorks incoming pairing for temporary bonding"); btif_dm_ssp_reply(bd_addr, BT_SSP_VARIANT_CONSENT, true); return; } @@ -1140,7 +1151,7 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) { cod = devclass2uint(p_ssp_cfm_req->dev_class); if (cod == 0) { - LOG_WARN("cod is 0, set as unclassified"); + log::warn("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } @@ -1162,7 +1173,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) { uint32_t cod; int dev_type; - LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr)); + log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr)); /* Remote properties update */ if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_key_notif->bd_addr) == @@ -1185,7 +1196,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) { cod = devclass2uint(p_ssp_key_notif->dev_class); if (cod == 0) { - LOG_WARN("cod is 0, set as unclassified"); + log::warn("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } @@ -1212,8 +1223,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bt_bond_state_t state = BT_BOND_STATE_NONE; bool skip_sdp = false; - LOG_INFO("bond state=%d, success=%d, key_present=%d", pairing_cb.state, - p_auth_cmpl->success, p_auth_cmpl->key_present); + log::info("bond state={}, success={}, key_present={}", pairing_cb.state, + p_auth_cmpl->success, p_auth_cmpl->key_present); pairing_cb.fail_reason = p_auth_cmpl->fail_reason; @@ -1228,21 +1239,21 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bt_status_t ret; if (!bd_addr.IsEmpty()) { - LOG_DEBUG("Storing link key. key_type=0x%x, bond_type=%d", - p_auth_cmpl->key_type, pairing_cb.bond_type); + log::debug("Storing link key. key_type=0x{:x}, bond_type={}", + p_auth_cmpl->key_type, pairing_cb.bond_type); ret = btif_storage_add_bonded_device(&bd_addr, p_auth_cmpl->key, p_auth_cmpl->key_type, pairing_cb.pin_code_len); } else { - LOG_WARN("bd_addr is empty"); + log::warn("bd_addr is empty"); ret = BT_STATUS_FAIL; } ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret); } else { - LOG_DEBUG("Temporary key. Not storing. key_type=0x%x, bond_type=%d", - p_auth_cmpl->key_type, pairing_cb.bond_type); + log::debug("Temporary key. Not storing. key_type=0x{:x}, bond_type={}", + p_auth_cmpl->key_type, pairing_cb.bond_type); if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY) { - LOG_DEBUG("sending BT_BOND_STATE_NONE for Temp pairing"); + log::debug("sending BT_BOND_STATE_NONE for Temp pairing"); btif_storage_remove_bonded_device(&bd_addr); bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_NONE); return; @@ -1263,8 +1274,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { // the derived link key. if (p_auth_cmpl->bd_addr != pairing_cb.bd_addr && (!pairing_cb.ble.is_penc_key_rcvd)) { - LOG_WARN("skipping SDP for unknown device %s", - ADDRESS_TO_LOGGABLE_CSTR(p_auth_cmpl->bd_addr)); + log::warn("skipping SDP for unknown device {}", + ADDRESS_TO_LOGGABLE_CSTR(p_auth_cmpl->bd_addr)); return; } @@ -1279,7 +1290,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bool is_crosskey = false; if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->is_ctkd) { - LOG_DEBUG("bonding initiated due to cross key pairing"); + log::debug("bonding initiated due to cross key pairing"); is_crosskey = true; } @@ -1294,13 +1305,13 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bd_addr = p_auth_cmpl->bd_addr; if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr)) { - LOG_WARN("skip SDP"); + log::warn("skip SDP"); skip_sdp = true; } if (!pairing_cb.is_local_initiated && skip_sdp) { bond_state_changed(status, bd_addr, state); - LOG_WARN("Incoming HID Connection"); + log::warn("Incoming HID Connection"); bt_property_t prop; Uuid uuid = Uuid::From16Bit(UUID_SERVCLASS_HUMAN_INTERFACE); @@ -1313,7 +1324,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { } else { /* If bonded due to cross-key, save the static address too*/ if (is_crosskey) { - LOG_DEBUG("bonding initiated due to cross key, adding static address"); + log::debug("bonding initiated due to cross key, adding static address"); pairing_cb.static_bdaddr = bd_addr; } if (!is_crosskey || @@ -1339,7 +1350,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { if (pairing_cb.sdp_over_classic == btif_dm_pairing_cb_t::ServiceDiscoveryState::NOT_STARTED) { - LOG_INFO("scheduling SDP for %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("scheduling SDP for {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); pairing_cb.sdp_over_classic = btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED; btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_BR_EDR); @@ -1349,8 +1360,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { // Do not call bond_state_changed_cb yet. Wait until remote service // discovery is complete } else { - LOG_WARN("Bonding failed with failure reason:%s", - hci_reason_code_text(p_auth_cmpl->fail_reason).c_str()); + log::warn("Bonding failed with failure reason:{}", + hci_reason_code_text(p_auth_cmpl->fail_reason)); bool is_bonded_device_removed = false; // Map the HCI fail reason to bt status switch (p_auth_cmpl->fail_reason) { @@ -1358,8 +1369,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { case HCI_ERR_LMP_RESPONSE_TIMEOUT: if (interop_match_addr(INTEROP_AUTO_RETRY_PAIRING, &bd_addr) && pairing_cb.timeout_retries) { - LOG_WARN("Pairing timeout; retrying (%d) ...", - pairing_cb.timeout_retries); + log::warn("Pairing timeout; retrying ({}) ...", + pairing_cb.timeout_retries); --pairing_cb.timeout_retries; if (addr_type == BLE_ADDR_RANDOM) { btif_dm_cb_create_bond_le(bd_addr, addr_type); @@ -1390,11 +1401,11 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { case HCI_ERR_INSUFFCIENT_SECURITY: case HCI_ERR_PEER_USER: case HCI_ERR_UNSPECIFIED: - LOG_WARN("Authentication fail:%s", - hci_reason_code_text(p_auth_cmpl->fail_reason).c_str()); + log::warn("Authentication fail:{}", + hci_reason_code_text(p_auth_cmpl->fail_reason)); if (pairing_cb.autopair_attempts == 1) { /* Create the Bond once again */ - LOG_WARN("auto pair failed. Reinitiate Bond"); + log::warn("auto pair failed. Reinitiate Bond"); if (addr_type == BLE_ADDR_RANDOM) { btif_dm_cb_create_bond_le(bd_addr, addr_type); } else { @@ -1413,7 +1424,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { /* Special Handling for HID Devices */ if (check_cod_hid_major(bd_addr, COD_HID_POINTING)) { /* Remove Device as bonded in nvram as authentication failed */ - LOG_VERBOSE("removing hid pointing device from nvram"); + log::verbose("removing hid pointing device from nvram"); is_bonded_device_removed = false; } // Report bond state change to java only if we are bonding to a device or @@ -1435,7 +1446,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { *****************************************************************************/ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_search_data) { - LOG_VERBOSE("event=%s", dump_dm_search_event(event)); + log::verbose("event={}", dump_dm_search_event(event)); switch (event) { case BTA_DM_NAME_READ_EVT: { @@ -1463,20 +1474,21 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, BTIF_STORAGE_FILL_PROPERTY(&properties[2], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(uint32_t), &cod); if (btif_storage_get_remote_device_property( &bdaddr, &properties[2]) == BT_STATUS_SUCCESS) { - LOG_VERBOSE("BTA_DM_NAME_READ_EVT, cod in storage=0x%08x", cod); + log::verbose("BTA_DM_NAME_READ_EVT, cod in storage=0x{:08x}", cod); } else { - LOG_INFO("BTA_DM_NAME_READ_EVT, no cod in storage"); + log::info("BTA_DM_NAME_READ_EVT, no cod in storage"); cod = 0; } if (cod != 0) { BTIF_STORAGE_FILL_PROPERTY(&properties[1], BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr); BTIF_STORAGE_FILL_PROPERTY(&properties[2], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(uint32_t), &cod); - LOG_DEBUG("report new device to JNI"); + log::debug("report new device to JNI"); GetInterfaceToProfiles()->events->invoke_device_found_cb(3, properties); } else { - LOG_INFO("Skipping RNR callback because cod is zero addr:%s name:%s", - ADDRESS_TO_LOGGABLE_CSTR(bdaddr), - PRIVATE_NAME(p_search_data->disc_res.bd_name)); + log::info("Skipping RNR callback because cod is zero addr:{} name:{}", + ADDRESS_TO_LOGGABLE_CSTR(bdaddr), + PRIVATE_NAME(reinterpret_cast<char const*>( + p_search_data->disc_res.bd_name))); } /** @} */ } @@ -1496,8 +1508,9 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, } RawAddress& bdaddr = p_search_data->inq_res.bd_addr; - LOG_VERBOSE("addr:%s device_type=0x%x", ADDRESS_TO_LOGGABLE_CSTR(bdaddr), - p_search_data->inq_res.device_type); + log::verbose("addr:{} device_type=0x{:x}", + ADDRESS_TO_LOGGABLE_CSTR(bdaddr), + p_search_data->inq_res.device_type); bdname.name[0] = 0; if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len)) @@ -1533,7 +1546,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, /* DEV_CLASS */ uint32_t cod = devclass2uint(p_search_data->inq_res.dev_class); - LOG_VERBOSE("cod is 0x%06x", cod); + log::verbose("cod is 0x{:06x}", cod); if (cod != 0) { BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), @@ -1541,8 +1554,8 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, num_properties++; } - LOG_VERBOSE("clock_offset is 0x%x", - p_search_data->inq_res.clock_offset); + log::verbose("clock_offset is 0x{:x}", + p_search_data->inq_res.clock_offset); if (p_search_data->inq_res.clock_offset & BTM_CLOCK_OFFSET_VALID) { btif_set_device_clockoffset(bdaddr, (int)p_search_data->inq_res.clock_offset); } @@ -1623,10 +1636,10 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, auto triple = eir_uuids_cache.try_emplace(bdaddr, std::set<Uuid>{}); uuid_iter = std::get<0>(triple); } - LOG_INFO("EIR UUIDs for %s:", ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); + log::info("EIR UUIDs for {}:", ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); for (int i = 0; i < num_uuids; ++i) { Uuid uuid = Uuid::From16Bit(p_uuid16[i]); - LOG_INFO(" %s", uuid.ToString().c_str()); + log::info("{}", uuid.ToString()); uuid_iter->second.insert(uuid); } @@ -1667,8 +1680,8 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, if (restrict_report && p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE && !(p_search_data->inq_res.ble_evt_type & BTM_BLE_CONNECTABLE_MASK)) { - LOG_DEBUG("Ble device %s is not connectable", - ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); + log::debug("Ble device {} is not connectable", + ADDRESS_TO_LOGGABLE_CSTR(bdaddr)); break; } @@ -1704,7 +1717,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, case BTA_DM_DID_RES_EVT: case BTA_DM_GATT_OVER_SDP_RES_EVT: default: - LOG_WARN("Unhandled event:%s", bta_dm_search_evt_text(event).c_str()); + log::warn("Unhandled event:{}", bta_dm_search_evt_text(event)); break; } } @@ -1735,9 +1748,10 @@ static bool btif_is_gatt_service_discovery_post_pairing(const RawAddress bd_addr if (bd_addr == pairing_cb.bd_addr || bd_addr == pairing_cb.static_bdaddr) { if (pairing_cb.gatt_over_le != btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED) { - LOG_ERROR("gatt_over_le should be SCHEDULED, did someone clear the " - "control block for %s ?", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::error( + "gatt_over_le should be SCHEDULED, did someone clear the control " + "block for {} ?", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } return true; @@ -1773,14 +1787,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, RawAddress& bd_addr = p_data->disc_res.bd_addr; - LOG_VERBOSE("result=0x%x, services 0x%x", p_data->disc_res.result, - p_data->disc_res.services); + log::verbose("result=0x{:x}, services 0x{:x}", p_data->disc_res.result, + p_data->disc_res.services); if (p_data->disc_res.result != BTA_SUCCESS && pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) { if (pairing_cb.sdp_attempts) { - LOG_WARN("SDP failed after bonding re-attempting for %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::warn("SDP failed after bonding re-attempting for {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); pairing_cb.sdp_attempts++; if (IS_FLAG_ENABLED(force_bredr_for_sdp_retry)) { btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_BR_EDR); @@ -1788,14 +1802,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_AUTO); } } else { - LOG_WARN("SDP triggered by someone failed when bonding"); + log::warn("SDP triggered by someone failed when bonding"); } return; } if ((bd_addr == pairing_cb.bd_addr || bd_addr == pairing_cb.static_bdaddr)) { - LOG_INFO("SDP finished for %s:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("SDP finished for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); pairing_cb.sdp_over_classic = btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED; } @@ -1804,13 +1818,13 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, prop.len = 0; if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) { - LOG_INFO("New UUIDs for %s:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("New UUIDs for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); for (i = 0; i < p_data->disc_res.num_uuids; i++) { auto uuid = p_data->disc_res.p_uuid_list + i; if (btif_should_ignore_uuid(*uuid)) { continue; } - LOG_INFO("index:%d uuid:%s", i, uuid->ToString().c_str()); + log::info("index:{} uuid:{}", i, uuid->ToString()); uuids.insert(*uuid); } @@ -1823,8 +1837,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, continue; } if (btif_is_interesting_le_service(uuid)) { - LOG_INFO("interesting le service %s insert", - uuid.ToString().c_str()); + log::info("interesting le service {} insert", uuid.ToString()); uuids.insert(uuid); } } @@ -1860,7 +1873,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts && (p_data->disc_res.bd_addr == pairing_cb.bd_addr || p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) { - LOG_INFO("SDP search done for %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("SDP search done for {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); pairing_cb.sdp_attempts = 0; // Send UUIDs discovered through EIR to Java to unblock pairing intent @@ -1869,8 +1882,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, auto uuids_iter = eir_uuids_cache.find(bd_addr); if (uuids_iter != eir_uuids_cache.end()) { num_eir_uuids = uuids_iter->second.size(); - LOG_INFO("SDP failed, send %zu EIR UUIDs to unblock bonding %s", - num_eir_uuids, ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("SDP failed, send {} EIR UUIDs to unblock bonding {}", + num_eir_uuids, ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); for (auto eir_uuid : uuids_iter->second) { auto uuid_128bit = eir_uuid.To128BitBE(); property_value.insert(property_value.end(), uuid_128bit.begin(), @@ -1882,7 +1895,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, prop.val = (void*)property_value.data(); prop.len = num_eir_uuids * Uuid::kNumBytes128; } else { - LOG_WARN("SDP failed and we have no EIR UUIDs to report either"); + log::warn("SDP failed and we have no EIR UUIDs to report either"); prop.val = &uuid; prop.len = Uuid::kNumBytes128; } @@ -1892,7 +1905,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, // Both SDP and bonding are done, clear pairing control block in case // it is not already cleared pairing_cb = {}; - LOG_DEBUG("clearing btif pairing_cb"); + log::debug("clearing btif pairing_cb"); } } @@ -1911,9 +1924,9 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, ret); if (skip_reporting_wait_for_le) { - LOG_INFO( - "Bonding LE Audio sink - must wait for le services discovery " - "to pass all services to java %s", + log::info( + "Bonding LE Audio sink - must wait for le services discovery to " + "pass all services to java {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); /* For LE Audio capable devices, we care more about passing GATT LE * services than about just finishing pairing. Service discovery @@ -1948,8 +1961,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, is_le_audio_capable_during_service_discovery(bd_addr); if (event == BTA_DM_GATT_OVER_LE_RES_EVT) { - LOG_INFO("New GATT over LE UUIDs for %s:", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("New GATT over LE UUIDs for {}:", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); BTM_LogHistory(kBtmLogTag, bd_addr, "Discovered GATT services using LE transport"); if (btif_is_gatt_service_discovery_post_pairing(bd_addr)) { @@ -1960,15 +1973,15 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED) { // Both SDP and bonding are either done, or not scheduled, // we are safe to clear the service discovery part of CB. - LOG_DEBUG("clearing pairing_cb"); + log::debug("clearing pairing_cb"); pairing_cb = {}; } if (IS_FLAG_ENABLED(le_audio_fast_bond_params) && lea_supported) { /* LE Audio profile should relax parameters when it connects. If * profile is not enabled, relax parameters after timeout. */ - LOG_DEBUG("Scheduling conn params unlock for %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::debug("Scheduling conn params unlock for {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); do_in_main_thread_delayed( FROM_HERE, base::BindOnce( @@ -1981,8 +1994,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, } } } else { - LOG_DEBUG("New GATT over SDP UUIDs for %s:", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::debug("New GATT over SDP UUIDs for {}:", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); BTM_LogHistory(kBtmLogTag, bd_addr, "Discovered GATT services using SDP transport"); } @@ -1992,14 +2005,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, if (btif_should_ignore_uuid(uuid)) { continue; } - LOG_INFO("index:%d uuid:%s", static_cast<int>(uuids.size()), - uuid.ToString().c_str()); + log::info("index:{} uuid:{}", static_cast<int>(uuids.size()), + uuid.ToString()); uuids.insert(uuid); } } if (uuids.empty()) { - LOG_INFO("No well known GATT services discovered"); + log::info("No well known GATT services discovered"); /* If services were returned as part of SDP discovery, we will * immediately send them with rest of SDP results in BTA_DM_DISC_RES_EVT @@ -2011,18 +2024,18 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, if (lea_supported) { if (bluetooth::common::init_flags:: sdp_return_classic_services_when_le_discovery_fails_is_enabled()) { - LOG_INFO( + log::info( "Will return Classic SDP results, if done, to unblock bonding"); } else { // LEA device w/o this flag // TODO: we might want to remove bond or do some action on // half-discovered device - LOG_WARN("No GATT service found for the LE Audio device %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::warn("No GATT service found for the LE Audio device {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); return; } } else { - LOG_INFO("LE audio not supported, no need to report any UUIDs"); + log::info("LE audio not supported, no need to report any UUIDs"); return; } } @@ -2034,8 +2047,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, btif_get_existing_uuids(&bd_addr, existing_uuids); if (existing_lookup_result != BT_STATUS_FAIL) { - LOG_INFO("Got some existing UUIDs by address %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("Got some existing UUIDs by address {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); for (int i = 0; i < BT_MAX_NUM_UUIDS; i++) { Uuid uuid = existing_uuids[i]; @@ -2051,8 +2064,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, existing_lookup_result = btif_get_existing_uuids(&static_addr_copy, existing_uuids); if (existing_lookup_result != BT_STATUS_FAIL) { - LOG_INFO("Got some existing UUIDs by static address %s", - ADDRESS_TO_LOGGABLE_CSTR(static_addr_copy)); + log::info("Got some existing UUIDs by static address {}", + ADDRESS_TO_LOGGABLE_CSTR(static_addr_copy)); for (int i = 0; i < BT_MAX_NUM_UUIDS; i++) { Uuid uuid = existing_uuids[i]; if (uuid.IsEmpty()) { @@ -2129,14 +2142,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, if (IS_FLAG_ENABLED(rnr_present_during_service_discovery)) { const tBTA_DM_DISC_RES& disc_res = p_data->disc_res; if (disc_res.hci_status != HCI_SUCCESS) { - LOG_WARN("Received RNR event with bad status addr:%s hci_status:%s", - ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr), - hci_error_code_text(disc_res.hci_status).c_str()); + log::warn("Received RNR event with bad status addr:{} hci_status:{}", + ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr), + hci_error_code_text(disc_res.hci_status)); break; } if (disc_res.bd_name[0] == '\0') { - LOG_WARN("Received RNR event without valid name addr:%s", - ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr)); + log::warn("Received RNR event without valid name addr:{}", + ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr)); break; } bt_property_t properties[] = {{ @@ -2152,11 +2165,12 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, const size_t num_props = sizeof(properties) / sizeof(bt_property_t); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( status, disc_res.bd_addr, (int)num_props, properties); - LOG_INFO("Callback for read name event addr:%s name:%s", - ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr), - PRIVATE_NAME(disc_res.bd_name)); + log::info( + "Callback for read name event addr:{} name:{}", + ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr), + PRIVATE_NAME(reinterpret_cast<char const*>(disc_res.bd_name))); } else { - LOG_INFO("Skipping name read event - called on bad callback."); + log::info("Skipping name read event - called on bad callback."); } } break; @@ -2171,14 +2185,14 @@ static void btif_dm_update_allowlisted_media_players() { bt_property_t wlplayers_prop; list_t* wl_players = list_new(nullptr); if (!wl_players) { - LOG_ERROR("Unable to allocate space for allowlist players"); + log::error("Unable to allocate space for allowlist players"); return; } - LOG_DEBUG("btif_dm_update_allowlisted_media_players"); + log::debug("btif_dm_update_allowlisted_media_players"); wlplayers_prop.len = 0; if (!interop_get_allowlisted_media_players_list(wl_players)) { - LOG_DEBUG("Allowlisted media players not found"); + log::debug("Allowlisted media players not found"); list_free(wl_players); return; } @@ -2241,7 +2255,7 @@ void BTIF_dm_enable() { bool ble_privacy_enabled = osi_property_get_bool(PROPERTY_BLE_PRIVACY_ENABLED, /*default=*/true); - LOG_INFO("Local BLE Privacy enabled:%d", ble_privacy_enabled); + log::info("Local BLE Privacy enabled:{}", ble_privacy_enabled); BTA_DmBleConfigLocalPrivacy(ble_privacy_enabled); /* for each of the enabled services in the mask, trigger the profile @@ -2278,7 +2292,7 @@ void BTIF_dm_disable() { } } bluetooth::bqr::EnableBtQualityReport(false); - LOG_INFO("Stack device manager shutdown finished"); + log::info("Stack device manager shutdown finished"); future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS); } @@ -2294,7 +2308,7 @@ void BTIF_dm_disable() { void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { RawAddress bd_addr; - LOG_VERBOSE("ev:%s", dump_dm_event(event)); + log::verbose("ev:{}", dump_dm_event(event)); switch (event) { case BTA_DM_PIN_REQ_EVT: @@ -2331,8 +2345,8 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { break; case BTA_DM_BLE_KEY_EVT: - LOG_VERBOSE("BTA_DM_BLE_KEY_EVT key_type=0x%02x ", - p_data->ble_key.key_type); + log::verbose("BTA_DM_BLE_KEY_EVT key_type=0x{:02x}", + p_data->ble_key.key_type); /* If this pairing is by-product of local initiated GATT client Read or Write, @@ -2341,93 +2355,94 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { have setup properly. Setup pairing_cb and notify App about Bonding state now*/ if (pairing_cb.state != BT_BOND_STATE_BONDING) { - LOG_VERBOSE("Bond state not sent to App so far.Notify the app now"); + log::verbose("Bond state not sent to App so far.Notify the app now"); bond_state_changed(BT_STATUS_SUCCESS, p_data->ble_key.bd_addr, BT_BOND_STATE_BONDING); } else if (pairing_cb.bd_addr != p_data->ble_key.bd_addr) { - LOG_ERROR("BD mismatch discard BLE key_type=%d ", - p_data->ble_key.key_type); + log::error("BD mismatch discard BLE key_type={}", + p_data->ble_key.key_type); break; } switch (p_data->ble_key.key_type) { case BTM_LE_KEY_PENC: - LOG_VERBOSE("Rcv BTM_LE_KEY_PENC"); + log::verbose("Rcv BTM_LE_KEY_PENC"); pairing_cb.ble.is_penc_key_rcvd = true; pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key; break; case BTM_LE_KEY_PID: - LOG_VERBOSE("Rcv BTM_LE_KEY_PID"); + log::verbose("Rcv BTM_LE_KEY_PID"); pairing_cb.ble.is_pid_key_rcvd = true; pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key; break; case BTM_LE_KEY_PCSRK: - LOG_VERBOSE("Rcv BTM_LE_KEY_PCSRK"); + log::verbose("Rcv BTM_LE_KEY_PCSRK"); pairing_cb.ble.is_pcsrk_key_rcvd = true; pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key; break; case BTM_LE_KEY_LENC: - LOG_VERBOSE("Rcv BTM_LE_KEY_LENC"); + log::verbose("Rcv BTM_LE_KEY_LENC"); pairing_cb.ble.is_lenc_key_rcvd = true; pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key; break; case BTM_LE_KEY_LCSRK: - LOG_VERBOSE("Rcv BTM_LE_KEY_LCSRK"); + log::verbose("Rcv BTM_LE_KEY_LCSRK"); pairing_cb.ble.is_lcsrk_key_rcvd = true; pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key; break; case BTM_LE_KEY_LID: - LOG_VERBOSE("Rcv BTM_LE_KEY_LID"); + log::verbose("Rcv BTM_LE_KEY_LID"); pairing_cb.ble.is_lidk_key_rcvd = true; break; default: - LOG_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type); + log::error("unknown BLE key type (0x{:02x})", + p_data->ble_key.key_type); break; } break; case BTA_DM_BLE_CONSENT_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_CONSENT_REQ_EVT"); + log::verbose("BTA_DM_BLE_CONSENT_REQ_EVT"); btif_dm_ble_sec_req_evt(&p_data->ble_req, true); break; case BTA_DM_BLE_SEC_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_SEC_REQ_EVT"); + log::verbose("BTA_DM_BLE_SEC_REQ_EVT"); btif_dm_ble_sec_req_evt(&p_data->ble_req, false); break; case BTA_DM_BLE_PASSKEY_NOTIF_EVT: - LOG_VERBOSE("BTA_DM_BLE_PASSKEY_NOTIF_EVT"); + log::verbose("BTA_DM_BLE_PASSKEY_NOTIF_EVT"); btif_dm_ble_key_notif_evt(&p_data->key_notif); break; case BTA_DM_BLE_PASSKEY_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_PASSKEY_REQ_EVT"); + log::verbose("BTA_DM_BLE_PASSKEY_REQ_EVT"); btif_dm_ble_passkey_req_evt(&p_data->pin_req); break; case BTA_DM_BLE_NC_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_PASSKEY_REQ_EVT"); + log::verbose("BTA_DM_BLE_PASSKEY_REQ_EVT"); btif_dm_ble_key_nc_req_evt(&p_data->key_notif); break; case BTA_DM_BLE_OOB_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_OOB_REQ_EVT"); + log::verbose("BTA_DM_BLE_OOB_REQ_EVT"); btif_dm_ble_oob_req_evt(&p_data->rmt_oob); break; case BTA_DM_BLE_SC_OOB_REQ_EVT: - LOG_VERBOSE("BTA_DM_BLE_SC_OOB_REQ_EVT"); + log::verbose("BTA_DM_BLE_SC_OOB_REQ_EVT"); btif_dm_ble_sc_oob_req_evt(&p_data->rmt_oob); break; case BTA_DM_BLE_SC_CR_LOC_OOB_EVT: - LOG_VERBOSE("BTA_DM_BLE_SC_CR_LOC_OOB_EVT"); + log::verbose("BTA_DM_BLE_SC_CR_LOC_OOB_EVT"); btif_dm_proc_loc_oob(BT_TRANSPORT_LE, true, p_data->local_oob_data.local_oob_c, p_data->local_oob_data.local_oob_r); break; case BTA_DM_BLE_LOCAL_IR_EVT: - LOG_VERBOSE("BTA_DM_BLE_LOCAL_IR_EVT"); + log::verbose("BTA_DM_BLE_LOCAL_IR_EVT"); ble_local_key_cb.is_id_keys_rcvd = true; ble_local_key_cb.id_keys.irk = p_data->ble_id_keys.irk; ble_local_key_cb.id_keys.ir = p_data->ble_id_keys.ir; @@ -2440,7 +2455,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { BTIF_DM_LE_LOCAL_KEY_DHK); break; case BTA_DM_BLE_LOCAL_ER_EVT: - LOG_VERBOSE("BTA_DM_BLE_LOCAL_ER_EVT"); + log::verbose("BTA_DM_BLE_LOCAL_ER_EVT"); ble_local_key_cb.is_er_rcvd = true; ble_local_key_cb.er = p_data->ble_er; btif_storage_add_ble_local_key(ble_local_key_cb.er, @@ -2448,7 +2463,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { break; case BTA_DM_BLE_AUTH_CMPL_EVT: - LOG_VERBOSE("BTA_DM_BLE_AUTH_CMPL_EVT"); + log::verbose("BTA_DM_BLE_AUTH_CMPL_EVT"); btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl); break; @@ -2468,7 +2483,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) { break; default: - LOG_WARN("unhandled event(%d)", event); + log::warn("unhandled event({})", event); break; } } @@ -2488,7 +2503,7 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) { switch (event) { case BTA_DM_LINK_UP_EVT: bd_addr = p_data->link_up.bd_addr; - LOG_VERBOSE("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED"); + log::verbose("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED"); btif_update_remote_version_property(&bd_addr); @@ -2543,13 +2558,12 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) { (int)p_data->link_down.transport_link_type, static_cast<bt_hci_error_code_t>(btm_get_acl_disc_reason_code()), direction, INVALID_ACL_HANDLE); - LOG_DEBUG( + log::debug( "Sent BT_ACL_STATE_DISCONNECTED upward as ACL link down event " - "device:%s reason:%s", + "device:{} reason:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), hci_reason_code_text( - static_cast<tHCI_REASON>(btm_get_acl_disc_reason_code())) - .c_str()); + static_cast<tHCI_REASON>(btm_get_acl_disc_reason_code()))); } break; case BTA_DM_LE_FEATURES_READ: btif_get_adapter_property(BT_PROPERTY_LOCAL_LE_FEATURES); @@ -2557,7 +2571,7 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) { default: { - LOG_ERROR("Unexpected tBTA_DM_ACL_EVT:%d", event); + log::error("Unexpected tBTA_DM_ACL_EVT:{}", event); } break; } @@ -2578,9 +2592,9 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time, tBTM_BLE_ENERGY_USED energy_used, tBTM_CONTRL_STATE ctrl_state, tBTA_STATUS status) { - LOG_VERBOSE( - "energy_info_cb-Status:%d,state=%d,tx_t=%u, rx_t=%u, " - "idle_time=%u,used=%u", + log::verbose( + "energy_info_cb-Status:{},state={},tx_t={}, rx_t={}, " + "idle_time={},used={}", status, ctrl_state, tx_time, rx_time, idle_time, energy_used); if (uid_set != nullptr) { @@ -2595,7 +2609,7 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time, bt_uid_traffic_t* data = uid_set_read_and_clear(uid_set); GetInterfaceToProfiles()->events->invoke_energy_info_cb(energy_info, data); } else { - LOG_WARN("Energy info event dropped as module is inactive"); + log::warn("Energy info event dropped as module is inactive"); } } @@ -2613,7 +2627,7 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time, * ******************************************************************************/ void btif_dm_start_discovery(void) { - LOG_VERBOSE("start device discover/inquiry"); + log::verbose("start device discover/inquiry"); BTM_LogHistory( kBtmLogTag, RawAddress::kEmpty, "Device discovery", @@ -2622,7 +2636,7 @@ void btif_dm_start_discovery(void) { /* no race here because we're guaranteed to be in the main thread */ if (bta_dm_is_search_request_queued()) { - LOG_INFO("skipping start discovery because a request is queued"); + log::info("skipping start discovery because a request is queued"); return; } @@ -2641,7 +2655,7 @@ void btif_dm_start_discovery(void) { * ******************************************************************************/ void btif_dm_cancel_discovery(void) { - LOG_INFO("Cancel search"); + log::info("Cancel search"); BTM_LogHistory(kBtmLogTag, RawAddress::kEmpty, "Cancel discovery"); BTA_DmSearchCancel(); @@ -2659,8 +2673,8 @@ bool btif_dm_pairing_is_busy() { * ******************************************************************************/ void btif_dm_create_bond(const RawAddress bd_addr, int transport) { - LOG_VERBOSE("bd_addr=%s, transport=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), - transport); + log::verbose("bd_addr={}, transport={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), + transport); BTM_LogHistory( kBtmLogTag, bd_addr, "Create bond", @@ -2682,8 +2696,8 @@ void btif_dm_create_bond(const RawAddress bd_addr, int transport) { ******************************************************************************/ void btif_dm_create_bond_le(const RawAddress bd_addr, tBLE_ADDR_TYPE addr_type) { - LOG_VERBOSE("bd_addr=%s, addr_type=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), - addr_type); + log::verbose("bd_addr={}, addr_type={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), + addr_type); const tBLE_BD_ADDR ble_bd_addr{ .type = addr_type, .bda = bd_addr, @@ -2747,13 +2761,13 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, // The controller only supports P192 switch (oob_cb.data_present) { case BTM_OOB_PRESENT_192_AND_256: - LOG_INFO("Have both P192 and P256"); + log::info("Have both P192 and P256"); [[fallthrough]]; case BTM_OOB_PRESENT_192: - LOG_INFO("Using P192"); + log::info("Using P192"); break; case BTM_OOB_PRESENT_256: - LOG_INFO("Using P256"); + log::info("Using P256"); // TODO(181889116): // Upgrade to support p256 (for now we just ignore P256) // because the controllers do not yet support it. @@ -2761,27 +2775,27 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, BT_BOND_STATE_NONE); return; default: - LOG_ERROR("Invalid data present for controller:%d", - oob_cb.data_present); + log::error("Invalid data present for controller:{}", + oob_cb.data_present); bond_state_changed(BT_STATUS_PARM_INVALID, bd_addr, BT_BOND_STATE_NONE); return; } pairing_cb.is_local_initiated = true; - LOG_ERROR("Classic not implemented yet"); + log::error("Classic not implemented yet"); bond_state_changed(BT_STATUS_UNSUPPORTED, bd_addr, BT_BOND_STATE_NONE); return; case BT_TRANSPORT_LE: { // Guess default RANDOM for address type for LE tBLE_ADDR_TYPE address_type = BLE_ADDR_RANDOM; - LOG_INFO("Using LE Transport"); + log::info("Using LE Transport"); switch (oob_cb.data_present) { case BTM_OOB_PRESENT_192_AND_256: - LOG_INFO("Have both P192 and P256"); + log::info("Have both P192 and P256"); [[fallthrough]]; // Always prefer 256 for LE case BTM_OOB_PRESENT_256: - LOG_INFO("Using P256"); + log::info("Using P256"); // If we have an address, lets get the type if (memcmp(p256_data.address, empty, 7) != 0) { /* byte no 7 is address type in LE Bluetooth Address OOB data */ @@ -2789,7 +2803,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, } break; case BTM_OOB_PRESENT_192: - LOG_INFO("Using P192"); + log::info("Using P192"); // If we have an address, lets get the type if (memcmp(p192_data.address, empty, 7) != 0) { /* byte no 7 is address type in LE Bluetooth Address OOB data */ @@ -2804,7 +2818,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, break; } default: - LOG_ERROR("Invalid transport: %d", transport); + log::error("Invalid transport: {}", transport); bond_state_changed(BT_STATUS_PARM_INVALID, bd_addr, BT_BOND_STATE_NONE); return; } @@ -2818,7 +2832,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, * ******************************************************************************/ void btif_dm_cancel_bond(const RawAddress bd_addr) { - LOG_VERBOSE("bd_addr=%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("bd_addr={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); BTM_LogHistory(kBtmLogTag, bd_addr, "Cancel bond"); @@ -2877,7 +2891,7 @@ void btif_dm_hh_open_failed(RawAddress* bdaddr) { ******************************************************************************/ void btif_dm_remove_bond(const RawAddress bd_addr) { - LOG_VERBOSE("bd_addr=%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("bd_addr={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); BTM_LogHistory(kBtmLogTag, bd_addr, "Remove bond"); @@ -2898,7 +2912,7 @@ void btif_dm_remove_bond(const RawAddress bd_addr) { &link_spec) != BT_STATUS_SUCCESS) #endif { - LOG_DEBUG("Removing HH device"); + log::debug("Removing HH device"); BTA_DmRemoveDevice(bd_addr); } } @@ -2913,7 +2927,7 @@ void btif_dm_remove_bond(const RawAddress bd_addr) { void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, uint8_t pin_len, bt_pin_code_t pin_code) { - LOG_VERBOSE("accept=%d", accept); + log::verbose("accept={}", accept); if (pairing_cb.is_le_only) { int i; @@ -2924,7 +2938,7 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, } // TODO: // FIXME: should we hide part of passkey here? - LOG_VERBOSE("btif_dm_pin_reply: passkey: %d", passkey); + log::verbose("btif_dm_pin_reply: passkey: {}", passkey); BTA_DmBlePasskeyReply(bd_addr, accept, passkey); } else { @@ -2943,7 +2957,7 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, ******************************************************************************/ void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, uint8_t accept) { - LOG_VERBOSE("accept=%d", accept); + log::verbose("accept={}", accept); BTM_LogHistory( kBtmLogTag, bd_addr, "Ssp reply", base::StringPrintf( @@ -2991,7 +3005,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() { // If the property is empty, use the default if (prop_cod[0] == '\0') { - LOG_ERROR("COD property is empty"); + log::error("COD property is empty"); return kDevClassUnclassified; } @@ -3008,7 +3022,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() { prop_cod[i] != '\0') { char c = prop_cod[i++]; if (!std::isdigit(c)) { - LOG_ERROR("COD malformed, '%c' is a non-digit", c); + log::error("COD malformed, '{:c}' is a non-digit", c); return kDevClassUnclassified; } value += c; @@ -3016,20 +3030,20 @@ DEV_CLASS btif_dm_get_local_class_of_device() { // If we hit the end and it wasn't null terminated then return the default if (i == PROPERTY_VALUE_MAX && prop_cod[PROPERTY_VALUE_MAX - 1] != '\0') { - LOG_ERROR("COD malformed, value was truncated"); + log::error("COD malformed, value was truncated"); return kDevClassUnclassified; } // Each number in the list must be one byte, meaning 0 (0x00) -> 255 (0xFF) if (value.size() > 3 || value.size() == 0) { - LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str()); + log::error("COD malformed, '{}' must be between [0, 255]", value); return kDevClassUnclassified; } // Grab the value. If it's too large, then return the default uint32_t uint32_val = static_cast<uint32_t>(std::stoul(value.c_str())); if (uint32_val > 0xFF) { - LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str()); + log::error("COD malformed, '{}' must be between [0, 255]", value); return kDevClassUnclassified; } @@ -3039,7 +3053,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() { // If we've reached 3 numbers then make sure we're at a null terminator if (j >= 3) { if (prop_cod[i] != '\0') { - LOG_ERROR("COD malformed, more than three numbers"); + log::error("COD malformed, more than three numbers"); return kDevClassUnclassified; } break; @@ -3061,11 +3075,12 @@ DEV_CLASS btif_dm_get_local_class_of_device() { device_class[1] = temp_device_class[1]; device_class[2] = temp_device_class[2]; } else { - LOG_ERROR("COD malformed, fewer than three numbers"); + log::error("COD malformed, fewer than three numbers"); } - LOG_DEBUG("Using class of device '0x%x, 0x%x, 0x%x' from CoD system property", - device_class[0], device_class[1], device_class[2]); + log::debug( + "Using class of device '0x{:x}, 0x{:x}, 0x{:x}' from CoD system property", + device_class[0], device_class[1], device_class[2]); #ifdef __ANDROID__ // Per BAP 1.0.1, 8.2.3. Device discovery, the stack needs to set Class of @@ -3084,9 +3099,9 @@ DEV_CLASS btif_dm_get_local_class_of_device() { } else { device_class[1] &= ~(0x01 << 6); } - LOG_DEBUG( - "Check LE audio enabled status, update class of device to '0x%x, 0x%x, " - "0x%x'", + log::debug( + "Check LE audio enabled status, update class of device to '0x{:x}, " + "0x{:x}, 0x{:x}'", device_class[0], device_class[1], device_class[2]); #endif return device_class; @@ -3102,7 +3117,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() { * ******************************************************************************/ bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) { - LOG_VERBOSE("type=0x%x", prop->type); + log::verbose("type=0x{:x}", prop->type); switch (prop->type) { case BT_PROPERTY_BDNAME: { bt_bdname_t* bd_name = (bt_bdname_t*)prop->val; @@ -3153,9 +3168,8 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) { * ******************************************************************************/ void btif_dm_get_remote_services(RawAddress remote_addr, const int transport) { - LOG_VERBOSE("transport=%s, remote_addr=%s", - bt_transport_text(transport).c_str(), - ADDRESS_TO_LOGGABLE_CSTR(remote_addr)); + log::verbose("transport={}, remote_addr={}", bt_transport_text(transport), + ADDRESS_TO_LOGGABLE_CSTR(remote_addr)); BTM_LogHistory( kBtmLogTag, remote_addr, "Service discovery", @@ -3191,7 +3205,7 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) { ** as a fallback set MITM+GB if peer had MITM set */ - LOG_VERBOSE("original p_auth_req=%d", *p_auth_req); + log::verbose("original p_auth_req={}", *p_auth_req); if (pairing_cb.is_local_initiated) { /* if initing/responding to a dedicated bonding, use dedicate bonding bit */ *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES; @@ -3199,8 +3213,8 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) { /* peer initiated paring. They probably know what they want. ** Copy the mitm from peer device. */ - LOG_DEBUG("peer initiated, setting p_auth_req to peer's: %d", - pairing_cb.auth_req); + log::debug("peer initiated, setting p_auth_req to peer's: {}", + pairing_cb.auth_req); *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS); /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, @@ -3211,13 +3225,13 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) { /* set the general bonding bit for stored device */ *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit; } - LOG_VERBOSE("updated p_auth_req=%d", *p_auth_req); + log::verbose("updated p_auth_req={}", *p_auth_req); } void btif_dm_proc_io_rsp(const RawAddress& /* bd_addr */, tBTM_IO_CAP io_cap, tBTM_OOB_DATA /* oob_data */, tBTM_AUTH_REQ auth_req) { if (auth_req & BTA_AUTH_BONDS) { - LOG_DEBUG("auth_req:%d", auth_req); + log::debug("auth_req:{}", auth_req); pairing_cb.auth_req = auth_req; pairing_cb.io_cap = io_cap; } @@ -3229,7 +3243,7 @@ void btif_dm_set_oob_for_io_req(tBTM_OOB_DATA* p_has_oob_data) { } else { *p_has_oob_data = true; } - LOG_VERBOSE("*p_has_oob_data=%d", *p_has_oob_data); + log::verbose("*p_has_oob_data={}", *p_has_oob_data); } void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, @@ -3237,11 +3251,11 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, tBTM_LE_AUTH_REQ* p_auth_req) { switch (oob_cb.data_present) { case BTM_OOB_PRESENT_192_AND_256: - LOG_INFO("Have both P192 and P256"); + log::info("Have both P192 and P256"); [[fallthrough]]; // Always prefer 256 for LE case BTM_OOB_PRESENT_256: - LOG_INFO("Using P256"); + log::info("Using P256"); if (!is_empty_128bit(oob_cb.p256_data.c) && !is_empty_128bit(oob_cb.p256_data.r)) { /* make sure OOB data is for this particular device */ @@ -3250,7 +3264,7 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, *p_has_oob_data = true; } else { *p_has_oob_data = false; - LOG_WARN("P256-1: Remote address didn't match OOB data address"); + log::warn("P256-1: Remote address didn't match OOB data address"); } } else if (!is_empty_128bit(oob_cb.p256_data.sm_tk)) { /* We have security manager TK */ @@ -3263,14 +3277,14 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, *p_has_oob_data = true; } else { *p_has_oob_data = false; - LOG_WARN("P256-2: Remote address didn't match OOB data address"); + log::warn("P256-2: Remote address didn't match OOB data address"); } } else { *p_has_oob_data = false; } break; case BTM_OOB_PRESENT_192: - LOG_INFO("Using P192"); + log::info("Using P192"); if (!is_empty_128bit(oob_cb.p192_data.c) && !is_empty_128bit(oob_cb.p192_data.r)) { /* make sure OOB data is for this particular device */ @@ -3279,7 +3293,7 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, *p_has_oob_data = true; } else { *p_has_oob_data = false; - LOG_WARN("P192-1: Remote address didn't match OOB data address"); + log::warn("P192-1: Remote address didn't match OOB data address"); } } else if (!is_empty_128bit(oob_cb.p192_data.sm_tk)) { /* We have security manager TK */ @@ -3292,23 +3306,23 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr, *p_has_oob_data = true; } else { *p_has_oob_data = false; - LOG_WARN("P192-2: Remote address didn't match OOB data address"); + log::warn("P192-2: Remote address didn't match OOB data address"); } } else { *p_has_oob_data = false; } break; } - LOG_VERBOSE("*p_has_oob_data=%d", *p_has_oob_data); + log::verbose("*p_has_oob_data={}", *p_has_oob_data); } void btif_dm_load_local_oob(void) { char prop_oob[PROPERTY_VALUE_MAX]; osi_property_get("service.brcm.bt.oob", prop_oob, "3"); - LOG_VERBOSE("prop_oob = %s", prop_oob); + log::verbose("prop_oob = {}", prop_oob); if (prop_oob[0] != '3') { if (is_empty_128bit(oob_cb.p192_data.c)) { - LOG_VERBOSE("read OOB, call BTA_DmLocalOob()"); + log::verbose("read OOB, call BTA_DmLocalOob()"); BTA_DmLocalOob(); } } @@ -3318,7 +3332,7 @@ static bool waiting_on_oob_advertiser_start = false; static std::optional<uint8_t> oob_advertiser_id_; static void stop_oob_advertiser() { // For chasing an advertising bug b/237023051 - LOG_DEBUG("oob_advertiser_id: %d", oob_advertiser_id_.value()); + log::debug("oob_advertiser_id: {}", oob_advertiser_id_.value()); auto advertiser = bluetooth::shim::get_ble_advertiser_instance(); advertiser->Unregister(oob_advertiser_id_.value()); oob_advertiser_id_ = {}; @@ -3334,7 +3348,7 @@ static void stop_oob_advertiser() { * ******************************************************************************/ void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) { - LOG_DEBUG("Transport %s", bt_transport_text(transport).c_str()); + log::debug("Transport {}", bt_transport_text(transport)); if (transport == BT_TRANSPORT_BR_EDR) { BTM_ReadLocalOobData(); } else if (transport == BT_TRANSPORT_LE) { @@ -3343,7 +3357,7 @@ void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) { // advertising then request the address. if (!waiting_on_oob_advertiser_start) { // For chasing an advertising bug b/237023051 - LOG_DEBUG("oob_advertiser_id: %d", oob_advertiser_id_.value_or(255)); + log::debug("oob_advertiser_id: {}", oob_advertiser_id_.value_or(255)); if (oob_advertiser_id_.has_value()) { stop_oob_advertiser(); } @@ -3374,7 +3388,7 @@ static void start_advertising_callback(uint8_t id, tBT_TRANSPORT transport, bool is_valid, const Octet16& c, const Octet16& r, tBTM_STATUS status) { if (status != 0) { - LOG_INFO("OOB get advertiser ID failed with status %hhd", status); + log::info("OOB get advertiser ID failed with status {}", status); GetInterfaceToProfiles()->events->invoke_oob_data_request_cb( transport, false, c, r, RawAddress{}, 0x00); SMP_ClearLocScOobData(); @@ -3382,15 +3396,14 @@ static void start_advertising_callback(uint8_t id, tBT_TRANSPORT transport, oob_advertiser_id_ = {}; return; } - LOG_DEBUG("OOB advertiser with id %hhd", id); + log::debug("OOB advertiser with id {}", id); auto advertiser = bluetooth::shim::get_ble_advertiser_instance(); advertiser->GetOwnAddress( id, base::Bind(&get_address_callback, transport, is_valid, c, r)); } static void timeout_cb(uint8_t id, tBTM_STATUS status) { - LOG_INFO("OOB advertiser with id %hhd timed out with status %hhd", id, - status); + log::info("OOB advertiser with id {} timed out with status {}", id, status); auto advertiser = bluetooth::shim::get_ble_advertiser_instance(); advertiser->Unregister(id); SMP_ClearLocScOobData(); @@ -3403,7 +3416,7 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid, const Octet16& c, const Octet16& r, uint8_t id, tBTM_STATUS status) { if (status != 0) { - LOG_INFO("OOB get advertiser ID failed with status %hhd", status); + log::info("OOB get advertiser ID failed with status {}", status); GetInterfaceToProfiles()->events->invoke_oob_data_request_cb( transport, false, c, r, RawAddress{}, 0x00); SMP_ClearLocScOobData(); @@ -3413,7 +3426,7 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid, } oob_advertiser_id_ = id; - LOG_INFO("oob_advertiser_id: %d", id); + log::info("oob_advertiser_id: {}", id); auto advertiser = bluetooth::shim::get_ble_advertiser_instance(); AdvertiseParameters parameters{}; @@ -3485,7 +3498,7 @@ void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid, bool btif_dm_get_smp_config(tBTE_APPL_CFG* p_cfg) { const std::string* recv = stack_config_get_interface()->get_pts_smp_options(); if (!recv) { - LOG_WARN("SMP pairing options not found in stack configuration"); + log::warn("SMP pairing options not found in stack configuration"); return false; } @@ -3536,23 +3549,23 @@ bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c, const char* path = NULL; char prop_oob[PROPERTY_VALUE_MAX]; osi_property_get("service.brcm.bt.oob", prop_oob, "3"); - LOG_DEBUG("prop_oob = %s", prop_oob); + log::debug("prop_oob = {}", prop_oob); if (prop_oob[0] == '1') path = path_b; else if (prop_oob[0] == '2') path = path_a; if (!path) { - LOG_DEBUG("can't open path!"); + log::debug("can't open path!"); return false; } FILE* fp = fopen(path, "rb"); if (fp == NULL) { - LOG_DEBUG("failed to read OOB keys from %s", path); + log::debug("failed to read OOB keys from {}", path); return false; } - LOG_VERBOSE("read OOB data from %s", path); + log::verbose("read OOB data from {}", path); (void)fread(p_c->data(), 1, OCTET16_LEN, fp); (void)fread(p_r->data(), 1, OCTET16_LEN, fp); fclose(fp); @@ -3567,7 +3580,7 @@ static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) { uint32_t cod; int dev_type; - LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr)); + log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr)); /* Remote name update */ if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) { @@ -3639,7 +3652,7 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { /* Test for temporary bonding */ if (btif_dm_ble_is_temp_pairing(bd_addr, p_auth_cmpl->is_ctkd)) { - LOG_DEBUG("sending BT_BOND_STATE_NONE for Temp pairing"); + log::debug("sending BT_BOND_STATE_NONE for Temp pairing"); btif_storage_remove_bonded_device(&bd_addr); state = BT_BOND_STATE_NONE; } else { @@ -3647,15 +3660,15 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { if (pairing_cb.gatt_over_le == btif_dm_pairing_cb_t::ServiceDiscoveryState::NOT_STARTED) { - LOG_INFO("scheduling GATT discovery over LE for %s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::info("scheduling GATT discovery over LE for {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); pairing_cb.gatt_over_le = btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED; btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_LE); } else { - LOG_INFO( + log::info( "skipping GATT discovery over LE - was already scheduled or " - "finished for %s, state: %d", + "finished for {}, state: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), pairing_cb.gatt_over_le); } } @@ -3663,8 +3676,8 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { /* Map the HCI fail reason to bt status */ // TODO This is not a proper use of the type uint8_t fail_reason = static_cast<uint8_t>(p_auth_cmpl->fail_reason); - LOG_ERROR("LE authentication for %s failed with reason %d", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), p_auth_cmpl->fail_reason); + log::error("LE authentication for {} failed with reason {}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), p_auth_cmpl->fail_reason); switch (fail_reason) { case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL: case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL: @@ -3675,15 +3688,15 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { case BTA_DM_AUTH_SMP_CONN_TOUT: { if (!p_auth_cmpl->is_ctkd && btm_sec_is_a_bonded_dev(bd_addr)) { - LOG_WARN( - "Bonded device addr=%s, timed out - will not remove the keys", + log::warn( + "Bonded device addr={}, timed out - will not remove the keys", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); // Don't send state change to upper layers - otherwise Java think we // unbonded, and will disconnect HID profile. return; } - LOG_INFO( - "Removing ble bonding keys on SMP_CONN_TOUT during crosskey: %d", + log::info( + "Removing ble bonding keys on SMP_CONN_TOUT during crosskey: {}", p_auth_cmpl->is_ctkd); btif_dm_remove_ble_bonding_keys(); status = BT_STATUS_AUTH_FAILURE; @@ -3714,7 +3727,7 @@ void btif_dm_load_ble_local_keys(void) { if (btif_storage_get_ble_local_key( BTIF_DM_LE_LOCAL_KEY_ER, &ble_local_key_cb.er) == BT_STATUS_SUCCESS) { ble_local_key_cb.is_er_rcvd = true; - LOG_VERBOSE("BLE ER key loaded"); + log::verbose("BLE ER key loaded"); } if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR, @@ -3727,7 +3740,7 @@ void btif_dm_load_ble_local_keys(void) { &ble_local_key_cb.id_keys.dhk) == BT_STATUS_SUCCESS)) { ble_local_key_cb.is_id_keys_rcvd = true; - LOG_VERBOSE("BLE ID keys loaded"); + log::verbose("BLE ID keys loaded"); } } void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask, @@ -3747,14 +3760,14 @@ void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask, p_id_keys->dhk = ble_local_key_cb.id_keys.dhk; *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID; } - LOG_VERBOSE("*p_key_mask=0x%02x", *p_key_mask); + log::verbose("*p_key_mask=0x{:02x}", *p_key_mask); } static void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr) { - LOG_VERBOSE("%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); if (bd_addr.IsEmpty()) { - LOG_WARN("bd_addr is empty"); + log::warn("bd_addr is empty"); return; } @@ -3795,7 +3808,7 @@ static void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr) { } static void btif_dm_remove_ble_bonding_keys(void) { - LOG_VERBOSE("removing ble bonding keys"); + log::verbose("removing ble bonding keys"); RawAddress bd_addr = pairing_cb.bd_addr; btif_storage_remove_ble_bonding_keys(&bd_addr); @@ -3816,10 +3829,10 @@ static void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ* p_ble_req, uint32_t cod; int dev_type; - LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ble_req->bd_addr)); + log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ble_req->bd_addr)); if (!is_consent && pairing_cb.state == BT_BOND_STATE_BONDING) { - LOG_WARN("Discard security request"); + log::warn("Discard security request"); return; } @@ -3892,7 +3905,7 @@ static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ* p_pin_req) { } static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) { /* TODO implement key notification for numeric comparison */ - LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_notif_req->bd_addr)); + log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_notif_req->bd_addr)); /* Remote name update */ btif_update_remote_properties(p_notif_req->bd_addr, p_notif_req->bd_name, @@ -3920,7 +3933,7 @@ static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) { } static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) { - LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(req_oob_type->bd_addr)); + log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(req_oob_type->bd_addr)); RawAddress bd_addr = req_oob_type->bd_addr; /* We already checked if OOB data is present in @@ -3933,7 +3946,7 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) { /* make sure OOB data is for this particular device */ if (req_oob_type->bd_addr != oob_cb.bdaddr) { - LOG_WARN("remote address didn't match OOB data address"); + log::warn("remote address didn't match OOB data address"); return; } @@ -3951,12 +3964,12 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) { static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) { RawAddress bd_addr = req_oob_type->bd_addr; - LOG_VERBOSE("bd_addr: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); - LOG_VERBOSE("oob_cb.bdaddr: %s", ADDRESS_TO_LOGGABLE_CSTR(oob_cb.bdaddr)); + log::verbose("bd_addr: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("oob_cb.bdaddr: {}", ADDRESS_TO_LOGGABLE_CSTR(oob_cb.bdaddr)); /* make sure OOB data is for this particular device */ if (req_oob_type->bd_addr != oob_cb.bdaddr) { - LOG_ERROR("remote address didn't match OOB data address"); + log::error("remote address didn't match OOB data address"); return; } @@ -3967,23 +3980,23 @@ static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) { bt_oob_data_t oob_data_to_use = {}; switch (oob_cb.data_present) { case BTM_OOB_PRESENT_192_AND_256: - LOG_INFO("Have both P192 and P256"); + log::info("Have both P192 and P256"); [[fallthrough]]; // Always prefer 256 for LE case BTM_OOB_PRESENT_256: - LOG_INFO("Using P256"); + log::info("Using P256"); if (is_empty_128bit(oob_cb.p256_data.c) && is_empty_128bit(oob_cb.p256_data.r)) { - LOG_WARN("P256 LE SC OOB data is empty"); + log::warn("P256 LE SC OOB data is empty"); return; } oob_data_to_use = oob_cb.p256_data; break; case BTM_OOB_PRESENT_192: - LOG_INFO("Using P192"); + log::info("Using P192"); if (is_empty_128bit(oob_cb.p192_data.c) && is_empty_128bit(oob_cb.p192_data.r)) { - LOG_WARN("P192 LE SC OOB data is empty"); + log::warn("P192 LE SC OOB data is empty"); return; } oob_data_to_use = oob_cb.p192_data; @@ -4051,7 +4064,7 @@ void btif_ble_test_end() { BTM_BleTestEnd(btif_dm_ble_test_end_cback); } void btif_dm_on_disable() { /* cancel any pending pairing requests */ if (is_bonding_or_sdp()) { - LOG_VERBOSE("Cancel pending pairing request"); + log::verbose("Cancel pending pairing request"); btif_dm_cancel_bond(pairing_cb.bd_addr); } } @@ -4200,8 +4213,8 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type) { p_device_type)) return false; tBT_DEVICE_TYPE device_type = static_cast<tBT_DEVICE_TYPE>(*p_device_type); - LOG_DEBUG("bd_addr:%s device_type:%s", ADDRESS_TO_LOGGABLE_CSTR(bda), - DeviceTypeText(device_type).c_str()); + log::debug("bd_addr:{} device_type:{}", ADDRESS_TO_LOGGABLE_CSTR(bda), + DeviceTypeText(device_type)); return true; } @@ -4216,8 +4229,8 @@ bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type) { if (!btif_config_get_int(bd_addr_str, BTIF_STORAGE_KEY_ADDR_TYPE, &val)) return false; *p_addr_type = static_cast<tBLE_ADDR_TYPE>(val); - LOG_DEBUG("bd_addr:%s[%s]", ADDRESS_TO_LOGGABLE_CSTR(bda), - AddressTypeText(*p_addr_type).c_str()); + log::debug("bd_addr:{}[{}]", ADDRESS_TO_LOGGABLE_CSTR(bda), + AddressTypeText(*p_addr_type)); return true; } @@ -4265,7 +4278,8 @@ void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key, static const int METADATA_LE_AUDIO = 26; /* If METADATA_LE_AUDIO is present, device is LE Audio capable */ if (key == METADATA_LE_AUDIO) { - LOG_INFO("Device is LE Audio Capable %s", ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); + log::info("Device is LE Audio Capable {}", + ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); metadata_cb.le_audio_cache.insert_or_assign(remote_bd_addr, value); } } diff --git a/system/btif/src/btif_gatt_client.cc b/system/btif/src/btif_gatt_client.cc index 6796db048a2..73bf14975df 100644 --- a/system/btif/src/btif_gatt_client.cc +++ b/system/btif/src/btif_gatt_client.cc @@ -30,6 +30,7 @@ #include <base/functional/bind.h> #include <base/logging.h> #include <base/threading/thread.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_gatt.h> #include <hardware/bt_gatt_types.h> @@ -60,6 +61,7 @@ using base::Bind; using base::Owned; using bluetooth::Uuid; using std::vector; +using namespace bluetooth; bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type); bool btif_get_device_type(const RawAddress& bda, int* p_device_type); @@ -74,7 +76,7 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks; #define CLI_CBACK_WRAP_IN_JNI(P_CBACK, P_CBACK_WRAP) \ do { \ if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \ - LOG_VERBOSE("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \ + log::verbose("HAL bt_gatt_callbacks->client->{}", #P_CBACK); \ do_in_jni_thread(P_CBACK_WRAP); \ } else { \ ASSERTC(0, "Callback is NULL", 0); \ @@ -84,21 +86,21 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks; #define CLI_CBACK_IN_JNI(P_CBACK, ...) \ do { \ if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \ - LOG_VERBOSE("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \ + log::verbose("HAL bt_gatt_callbacks->client->{}", #P_CBACK); \ do_in_jni_thread(Bind(bt_gatt_callbacks->client->P_CBACK, __VA_ARGS__)); \ } else { \ ASSERTC(0, "Callback is NULL", 0); \ } \ } while (0) -#define CHECK_BTGATT_INIT() \ - do { \ - if (bt_gatt_callbacks == NULL) { \ - LOG_WARN("%s: BTGATT not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } else { \ - LOG_DEBUG("%s", __func__); \ - } \ +#define CHECK_BTGATT_INIT() \ + do { \ + if (bt_gatt_callbacks == NULL) { \ + log::warn("BTGATT not initialized"); \ + return BT_STATUS_NOT_READY; \ + } else { \ + log::debug(""); \ + } \ } while (0) namespace { @@ -106,9 +108,8 @@ namespace { uint8_t rssi_request_client_if; static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { - LOG_DEBUG("Event %s [%d]", - gatt_client_event_text(static_cast<tBTA_GATTC_EVT>(event)).c_str(), - event); + log::debug("Event {} [{}]", + gatt_client_event_text(static_cast<tBTA_GATTC_EVT>(event)), event); tBTA_GATTC* p_data = (tBTA_GATTC*)p_param; switch (event) { @@ -144,8 +145,8 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { } case BTA_GATTC_OPEN_EVT: { - LOG_DEBUG("BTA_GATTC_OPEN_EVT %s", - ADDRESS_TO_LOGGABLE_CSTR(p_data->open.remote_bda)); + log::debug("BTA_GATTC_OPEN_EVT {}", + ADDRESS_TO_LOGGABLE_CSTR(p_data->open.remote_bda)); HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id, p_data->open.status, p_data->open.client_if, p_data->open.remote_bda); @@ -173,7 +174,7 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { case BTA_GATTC_SEARCH_RES_EVT: case BTA_GATTC_CANCEL_OPEN_EVT: case BTA_GATTC_SRVC_DISC_DONE_EVT: - LOG_DEBUG("Ignoring event (%d)", event); + log::debug("Ignoring event ({})", event); break; case BTA_GATTC_CFG_MTU_EVT: { @@ -214,14 +215,14 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { break; default: - LOG_ERROR("Unhandled event (%d)!", event); + log::error("Unhandled event ({})!", event); break; } } static void bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { - LOG_DEBUG(" gatt client callback event:%s [%d]", - gatt_client_event_text(event).c_str(), event); + log::debug("gatt client callback event:{} [{}]", + gatt_client_event_text(event), event); bt_status_t status = btif_transfer_context(btif_gattc_upstreams_evt, (uint16_t)event, (char*)p_data, sizeof(tBTA_GATTC), NULL); @@ -330,14 +331,14 @@ void btif_gattc_open_impl(int client_if, RawAddress address, transport = BT_TRANSPORT_BR_EDR; break; default: - LOG_ERROR("Unknown device type %d", +device_type); + log::error("Unknown device type {}", device_type); break; } } // Connect! - LOG_INFO("Transport=%d, device type=%d, address type =%d, phy=%d", transport, - device_type, addr_type, initiating_phys); + log::info("Transport={}, device type={}, address type ={}, phy={}", transport, + device_type, addr_type, initiating_phys); tBTM_BLE_CONN_TYPE type = is_direct ? BTM_BLE_DIRECT_CONNECTION : BTM_BLE_BKG_CONNECT_ALLOW_LIST; BTA_GATTC_Open(client_if, address, addr_type, type, transport, opportunistic, @@ -356,8 +357,8 @@ static bt_status_t btif_gattc_open(int client_if, const RawAddress& bd_addr, } void btif_gattc_close_impl(int client_if, RawAddress address, int conn_id) { - LOG_INFO("client_if=%d, conn_id=%d, address=%s", client_if, conn_id, - ADDRESS_TO_LOGGABLE_CSTR(address)); + log::info("client_if={}, conn_id={}, address={}", client_if, conn_id, + ADDRESS_TO_LOGGABLE_CSTR(address)); // Disconnect established connections if (conn_id != 0) { BTA_GATTC_Close(conn_id); diff --git a/system/btif/src/btif_gatt_server.cc b/system/btif/src/btif_gatt_server.cc index 7f4ecdb58f1..8b5fe9d016a 100644 --- a/system/btif/src/btif_gatt_server.cc +++ b/system/btif/src/btif_gatt_server.cc @@ -27,6 +27,7 @@ #define LOG_TAG "bt_btif_gatt" #include <base/functional/bind.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_gatt.h> #include <hardware/bt_gatt_types.h> @@ -53,19 +54,20 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type); using base::Bind; using bluetooth::Uuid; using std::vector; +using namespace bluetooth; /******************************************************************************* * Constants & Macros ******************************************************************************/ -#define CHECK_BTGATT_INIT() \ - do { \ - if (bt_gatt_callbacks == NULL) { \ - LOG_WARN("%s: BTGATT not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } else { \ - LOG_VERBOSE("%s", __func__); \ - } \ +#define CHECK_BTGATT_INIT() \ + do { \ + if (bt_gatt_callbacks == NULL) { \ + log::warn("BTGATT not initialized"); \ + return BT_STATUS_NOT_READY; \ + } else { \ + log::verbose(""); \ + } \ } while (0) /******************************************************************************* @@ -124,7 +126,7 @@ static void btapp_gatts_free_req_data(uint16_t event, tBTA_GATTS* p_data) { } static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { - LOG_VERBOSE("%s: Event %d", __func__, event); + log::verbose("Event {}", event); tBTA_GATTS* p_data = (tBTA_GATTS*)p_param; switch (event) { @@ -229,7 +231,7 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { case BTA_GATTS_OPEN_EVT: case BTA_GATTS_CANCEL_OPEN_EVT: case BTA_GATTS_CLOSE_EVT: - LOG_INFO("%s: Empty event (%d)!", __func__, event); + log::info("Empty event ({})!", event); break; case BTA_GATTS_PHY_UPDATE_EVT: @@ -253,7 +255,7 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { break; default: - LOG_ERROR("%s: Unhandled event (%d)!", __func__, event); + log::error("Unhandled event ({})!", event); break; } @@ -362,7 +364,7 @@ static void add_service_impl(int server_if, // refactored, and one can distinguish stack-internal aps from external apps if (service[0].uuid == Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER) || service[0].uuid == Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER)) { - LOG_ERROR("%s: Attept to register restricted service", __func__); + log::error("Attept to register restricted service"); HAL_CBACK(bt_gatt_callbacks, server->service_added_cb, BT_STATUS_FAIL, server_if, service.data(), service.size()); return; diff --git a/system/btif/src/btif_gatt_test.cc b/system/btif/src/btif_gatt_test.cc index ce5446310ae..e8ac0276c81 100644 --- a/system/btif/src/btif_gatt_test.cc +++ b/system/btif/src/btif_gatt_test.cc @@ -18,6 +18,7 @@ #define LOG_TAG "bt_btif_gatt" +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_gatt.h> #include <stdio.h> @@ -33,6 +34,8 @@ #include "types/raw_address.h" using bluetooth::Uuid; +using namespace bluetooth; + /******************************************************************************* * Typedefs & Macros ******************************************************************************/ @@ -62,15 +65,15 @@ static btif_test_cb_t test_cb; static void btif_test_connect_cback(tGATT_IF, const RawAddress&, uint16_t conn_id, bool connected, tGATT_DISCONN_REASON, tBT_TRANSPORT) { - LOG_INFO("%s: conn_id=%d, connected=%d", __func__, conn_id, connected); + log::info("conn_id={}, connected={}", conn_id, connected); test_cb.conn_id = connected ? conn_id : 0; } static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { - LOG_INFO("%s: op_code=0x%02x, conn_id=0x%x. status=0x%x", __func__, op, - conn_id, status); + log::info("op_code=0x{:02x}, conn_id=0x{:x}. status=0x{:x}", op, conn_id, + status); switch (op) { case GATTC_OPTYPE_READ: @@ -85,7 +88,7 @@ static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op, break; default: - LOG_INFO("%s: Unknown op_code (0x%02x)", __func__, op); + log::info("Unknown op_code (0x{:02x})", op); break; } } @@ -93,61 +96,59 @@ static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op, static void btif_test_discovery_result_cback(uint16_t /* conn_id */, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data) { - LOG_INFO("------ GATT Discovery result %-22s -------", disc_name[disc_type]); - LOG_INFO(" Attribute handle: 0x%04x (%d)", p_data->handle, - p_data->handle); + log::info("------ GATT Discovery result {:<22s} -------", + disc_name[disc_type]); + log::info("Attribute handle: 0x{:04x} ({})", p_data->handle, p_data->handle); if (disc_type != GATT_DISC_CHAR_DSCPT) { - LOG_INFO(" Attribute type: %s", p_data->type.ToString().c_str()); + log::info("Attribute type: {}", p_data->type.ToString()); } switch (disc_type) { case GATT_DISC_SRVC_ALL: - LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", - p_data->handle, p_data->value.group_value.e_handle, - p_data->handle, p_data->value.group_value.e_handle); - LOG_INFO(" Service UUID: %s", - p_data->value.group_value.service_type.ToString().c_str()); + log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})", p_data->handle, + p_data->value.group_value.e_handle, p_data->handle, + p_data->value.group_value.e_handle); + log::info("Service UUID: {}", + p_data->value.group_value.service_type.ToString()); break; case GATT_DISC_SRVC_BY_UUID: - LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", - p_data->handle, p_data->value.handle, p_data->handle, - p_data->value.handle); + log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})", p_data->handle, + p_data->value.handle, p_data->handle, p_data->value.handle); break; case GATT_DISC_INC_SRVC: - LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", - p_data->value.incl_service.s_handle, - p_data->value.incl_service.e_handle, - p_data->value.incl_service.s_handle, - p_data->value.incl_service.e_handle); - LOG_INFO(" Service UUID: %s", - p_data->value.incl_service.service_type.ToString().c_str()); + log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})", + p_data->value.incl_service.s_handle, + p_data->value.incl_service.e_handle, + p_data->value.incl_service.s_handle, + p_data->value.incl_service.e_handle); + log::info("Service UUID: {}", + p_data->value.incl_service.service_type.ToString()); break; case GATT_DISC_CHAR: - LOG_INFO(" Properties: 0x%02x", - p_data->value.dclr_value.char_prop); - LOG_INFO(" Characteristic UUID: %s", - p_data->value.dclr_value.char_uuid.ToString().c_str()); + log::info("Properties: 0x{:02x}", p_data->value.dclr_value.char_prop); + log::info("Characteristic UUID: {}", + p_data->value.dclr_value.char_uuid.ToString()); break; case GATT_DISC_CHAR_DSCPT: - LOG_INFO(" Descriptor UUID: %s", p_data->type.ToString().c_str()); + log::info("Descriptor UUID: {}", p_data->type.ToString()); break; case GATT_DISC_MAX: - LOG_ERROR(" Unknown discovery item"); + log::error("Unknown discovery item"); break; } - LOG_INFO("-----------------------------------------------------------"); + log::info("-----------------------------------------------------------"); } static void btif_test_discovery_complete_cback(uint16_t /* conn_id */, tGATT_DISC_TYPE /* disc_type */, tGATT_STATUS status) { - LOG_INFO("%s: status=%d", __func__, status); + log::info("status={}", status); } static tGATT_CBACK btif_test_callbacks = { @@ -172,7 +173,7 @@ bt_status_t btif_gattc_test_command_impl(int command, switch (command) { case 0x01: /* Enable */ { - LOG_INFO("%s: ENABLE - enable=%d", __func__, params->u1); + log::info("ENABLE - enable={}", params->u1); if (params->u1) { std::array<uint8_t, Uuid::kNumBytes128> tmp; tmp.fill(0xAE); @@ -189,8 +190,9 @@ bt_status_t btif_gattc_test_command_impl(int command, case 0x02: /* Connect */ { - LOG_INFO("%s: CONNECT - device=%s (dev_type=%d, addr_type=%d)", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*params->bda1), params->u1, params->u2); + log::info("CONNECT - device={} (dev_type={}, addr_type={})", + ADDRESS_TO_LOGGABLE_CSTR(*params->bda1), params->u1, + params->u2); if (params->u1 == BT_DEVICE_TYPE_BLE) BTM_SecAddBleDevice(*params->bda1, BT_DEVICE_TYPE_BLE, @@ -198,14 +200,14 @@ bt_status_t btif_gattc_test_command_impl(int command, if (!GATT_Connect(test_cb.gatt_if, *params->bda1, BTM_BLE_DIRECT_CONNECTION, BT_TRANSPORT_LE, false)) { - LOG_ERROR("%s: GATT_Connect failed!", __func__); + log::error("GATT_Connect failed!"); } break; } case 0x03: /* Disconnect */ { - LOG_INFO("%s: DISCONNECT - conn_id=%d", __func__, test_cb.conn_id); + log::info("DISCONNECT - conn_id={}", test_cb.conn_id); GATT_Disconnect(test_cb.conn_id); break; } @@ -213,22 +215,21 @@ bt_status_t btif_gattc_test_command_impl(int command, case 0x04: /* Discover */ { if (params->u1 >= GATT_DISC_MAX) { - LOG_ERROR("%s: DISCOVER - Invalid type (%d)!", __func__, params->u1); + log::error("DISCOVER - Invalid type ({})!", params->u1); return (bt_status_t)0; } - LOG_INFO("%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x", - __func__, disc_name[params->u1], test_cb.conn_id, - params->uuid1->ToString().c_str(), params->u2, params->u3); + log::info("DISCOVER ({}), conn_id={}, uuid={}, handles=0x{:04x}-0x{:04x}", + disc_name[params->u1], test_cb.conn_id, + params->uuid1->ToString(), params->u2, params->u3); GATTC_Discover(test_cb.conn_id, static_cast<tGATT_DISC_TYPE>(params->u1), params->u2, params->u3, *params->uuid1); break; } case 0xF0: /* Pairing configuration */ - LOG_INFO("%s: Setting pairing config auth=%d, iocaps=%d, keys=%d/%d/%d", - __func__, params->u1, params->u2, params->u3, params->u4, - params->u5); + log::info("Setting pairing config auth={}, iocaps={}, keys={}/{}/{}", + params->u1, params->u2, params->u3, params->u4, params->u5); bte_appl_cfg.ble_auth_req = params->u1; bte_appl_cfg.ble_io_cap = params->u2; @@ -238,7 +239,7 @@ bt_status_t btif_gattc_test_command_impl(int command, break; default: - LOG_ERROR("%s: UNKNOWN TEST COMMAND 0x%02x", __func__, command); + log::error("UNKNOWN TEST COMMAND 0x{:02x}", command); break; } return (bt_status_t)0; diff --git a/system/btif/src/btif_gatt_util.cc b/system/btif/src/btif_gatt_util.cc index a054bc8fc1f..858876d04ab 100644 --- a/system/btif/src/btif_gatt_util.cc +++ b/system/btif/src/btif_gatt_util.cc @@ -20,6 +20,7 @@ #include "btif_gatt_util.h" +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_gatt.h> #include <stdio.h> @@ -41,6 +42,7 @@ #include "types/raw_address.h" using bluetooth::Uuid; +using namespace bluetooth; /******************************************************************************* * BTIF -> BTA conversion functions @@ -66,7 +68,7 @@ static void btif_gatt_set_encryption_cb(const RawAddress& /* bd_addr */, tBT_TRANSPORT /* transport */, tBTA_STATUS result) { if (result != BTA_SUCCESS && result != BTA_BUSY) { - LOG_WARN("%s() - Encryption failed (%d)", __func__, result); + log::warn("Encryption failed ({})", result); } } @@ -77,14 +79,14 @@ void btif_gatt_check_encrypted_link(RawAddress bd_addr, BTM_ReadConnectionAddr(bd_addr, raw_local_addr, &local_addr_type); tBLE_BD_ADDR local_addr{local_addr_type, raw_local_addr}; if (!local_addr.IsPublic() && !local_addr.IsAddressResolvable()) { - LOG_DEBUG("Not establishing encryption since address type is NRPA"); + log::debug("Not establishing encryption since address type is NRPA"); return; } static const bool check_encrypted = bluetooth::os::GetSystemPropertyBool( "bluetooth.gatt.check_encrypted_link.enabled", true); if (!check_encrypted) { - LOG_DEBUG("Check skipped due to system config"); + log::debug("Check skipped due to system config"); return; } tBTM_LE_PENC_KEYS key; @@ -92,9 +94,9 @@ void btif_gatt_check_encrypted_link(RawAddress bd_addr, bd_addr, BTM_LE_KEY_PENC, (uint8_t*)&key, sizeof(tBTM_LE_PENC_KEYS)) == BT_STATUS_SUCCESS) && !btif_gatt_is_link_encrypted(bd_addr)) { - LOG_DEBUG("Checking gatt link peer:%s transport:%s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), - bt_transport_text(transport_link).c_str()); + log::debug("Checking gatt link peer:{} transport:{}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), + bt_transport_text(transport_link)); BTA_DmSetEncryption(bd_addr, transport_link, &btif_gatt_set_encryption_cb, BTM_BLE_SEC_ENCRYPT); } diff --git a/system/btif/src/btif_hd.cc b/system/btif/src/btif_hd.cc index f2f93cfe5d2..4112c16061a 100644 --- a/system/btif/src/btif_hd.cc +++ b/system/btif/src/btif_hd.cc @@ -29,6 +29,8 @@ #include "btif/include/btif_hd.h" +#include <bluetooth/log.h> + #include <cstdint> #include "bta/include/bta_hd_api.h" @@ -54,6 +56,8 @@ #define COD_HID_COMBO 0x05C0 #define COD_HID_MAJOR 0x0500 +using namespace bluetooth; + bool bta_dm_check_if_only_hd_connected(const RawAddress& peer_addr); bool check_cod_hid(const RawAddress* remote_bdaddr); bool check_cod_hid(const RawAddress& bd_addr); @@ -142,11 +146,11 @@ void btif_hd_remove_device(RawAddress bd_addr) { static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { tBTA_HD* p_data = (tBTA_HD*)p_param; - LOG_VERBOSE("%s: event=%s", __func__, dump_hd_event(event)); + log::verbose("event={}", dump_hd_event(event)); switch (event) { case BTA_HD_ENABLE_EVT: - LOG_VERBOSE("%s: status=%d", __func__, p_data->status); + log::verbose("status={}", p_data->status); if (p_data->status == BTA_HD_OK) { btif_storage_load_hidd(); btif_hd_cb.status = BTIF_HD_ENABLED; @@ -157,16 +161,16 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { } } else { btif_hd_cb.status = BTIF_HD_DISABLED; - LOG_WARN("Failed to enable BT-HD, status=%d", p_data->status); + log::warn("Failed to enable BT-HD, status={}", p_data->status); } break; case BTA_HD_DISABLE_EVT: - LOG_VERBOSE("%s: status=%d", __func__, p_data->status); + log::verbose("status={}", p_data->status); btif_hd_cb.status = BTIF_HD_DISABLED; if (btif_hd_cb.service_dereg_active) { bta_sys_deregister(BTA_ID_HD); - LOG_WARN("registering hid host now"); + log::warn("registering hid host now"); btif_hh_service_registration(TRUE); btif_hd_cb.service_dereg_active = FALSE; } @@ -174,7 +178,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { if (p_data->status == BTA_HD_OK) memset(&btif_hd_cb, 0, sizeof(btif_hd_cb)); else - LOG_WARN("Failed to disable BT-HD, status=%d", p_data->status); + log::warn("Failed to disable BT-HD, status={}", p_data->status); break; case BTA_HD_REGISTER_APP_EVT: { @@ -184,7 +188,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { addr = NULL; } - LOG_INFO("Registering HID device app"); + log::info("Registering HID device app"); btif_hd_cb.app_registered = TRUE; HAL_CBACK(bt_hd_callbacks, application_state_cb, addr, BTHD_APP_STATE_REGISTERED); @@ -195,7 +199,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { HAL_CBACK(bt_hd_callbacks, application_state_cb, NULL, BTHD_APP_STATE_NOT_REGISTERED); if (btif_hd_cb.service_dereg_active) { - LOG_WARN("disabling hid device service now"); + log::warn("disabling hid device service now"); if (!bluetooth::common::init_flags:: delay_hidh_cleanup_until_hidh_ready_start_is_enabled()) { btif_hd_free_buf(); @@ -206,11 +210,11 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { case BTA_HD_OPEN_EVT: { RawAddress* addr = (RawAddress*)&p_data->conn.bda; - LOG_WARN("BTA_HD_OPEN_EVT, address=%s", ADDRESS_TO_LOGGABLE_CSTR(*addr)); + log::warn("BTA_HD_OPEN_EVT, address={}", ADDRESS_TO_LOGGABLE_CSTR(*addr)); /* Check if the connection is from hid host and not hid device */ if (check_cod_hid(addr)) { /* Incoming connection from hid device, reject it */ - LOG_WARN("remote device is not hid host, disconnecting"); + log::warn("remote device is not hid host, disconnecting"); btif_hd_cb.forced_disc = TRUE; BTA_HdDisconnect(); break; @@ -224,7 +228,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { case BTA_HD_CLOSE_EVT: if (btif_hd_cb.forced_disc) { RawAddress* addr = (RawAddress*)&p_data->conn.bda; - LOG_WARN("remote device was forcefully disconnected"); + log::warn("remote device was forcefully disconnected"); btif_hd_remove_device(*addr); btif_hd_cb.forced_disc = FALSE; break; @@ -257,15 +261,11 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { HAL_CBACK(bt_hd_callbacks, connection_state_cb, (RawAddress*)&p_data->conn.bda, BTHD_CONN_STATE_DISCONNECTED); if (bta_dm_check_if_only_hd_connected(p_data->conn.bda)) { - LOG_VERBOSE("%s: Removing bonding as only HID profile connected", - __func__); + log::verbose("Removing bonding as only HID profile connected"); BTA_DmRemoveDevice(p_data->conn.bda); } else { RawAddress* bd_addr = (RawAddress*)&p_data->conn.bda; - LOG_VERBOSE( - "%s: Only removing HID data as some other profiles " - "connected", - __func__); + log::verbose("Only removing HID data as some other profiles connected"); btif_hd_remove_device(*bd_addr); } HAL_CBACK(bt_hd_callbacks, vc_unplug_cb); @@ -278,7 +278,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) { break; default: - LOG_WARN("%s: unknown event (%d)", __func__, event); + log::warn("unknown event ({})", event); break; } } @@ -298,7 +298,7 @@ static void bte_hd_evt(tBTA_HD_EVT event, tBTA_HD* p_data) { int param_len = 0; tBTIF_COPY_CBACK* p_copy_cback = NULL; - LOG_VERBOSE("%s event=%d", __func__, event); + log::verbose("event={}", event); switch (event) { case BTA_HD_ENABLE_EVT: @@ -353,7 +353,7 @@ static void bte_hd_evt(tBTA_HD_EVT event, tBTA_HD* p_data) { * ******************************************************************************/ static bt_status_t init(bthd_callbacks_t* callbacks) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); bt_hd_callbacks = callbacks; memset(&btif_hd_cb, 0, sizeof(btif_hd_cb)); @@ -373,7 +373,7 @@ static bt_status_t init(bthd_callbacks_t* callbacks) { * ******************************************************************************/ static void cleanup(void) { - LOG_VERBOSE("hd:%s", __func__); + log::verbose(""); if (bt_hd_callbacks) { /* update flag, not to enable hid host service now as BT is switching off */ @@ -395,10 +395,10 @@ static void cleanup(void) { static bt_status_t register_app(bthd_app_param_t* p_app_param, bthd_qos_param_t* p_in_qos, bthd_qos_param_t* p_out_qos) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (btif_hd_cb.app_registered) { - LOG_WARN("%s: application already registered", __func__); + log::warn("application already registered"); return BT_STATUS_DONE; } @@ -447,20 +447,20 @@ static bt_status_t register_app(bthd_app_param_t* p_app_param, * ******************************************************************************/ static bt_status_t unregister_app(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } if (btif_hd_cb.service_dereg_active) { - LOG_WARN("%s: BT-HD deregistering in progress", __func__); + log::warn("BT-HD deregistering in progress"); return BT_STATUS_BUSY; } @@ -480,15 +480,15 @@ static bt_status_t unregister_app(void) { * ******************************************************************************/ static bt_status_t connect(RawAddress* bd_addr) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } @@ -507,15 +507,15 @@ static bt_status_t connect(RawAddress* bd_addr) { * ******************************************************************************/ static bt_status_t disconnect(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } @@ -537,15 +537,15 @@ static bt_status_t send_report(bthd_report_type_t type, uint8_t id, uint16_t len, uint8_t* p_data) { tBTA_HD_REPORT report; - LOG_VERBOSE("%s: type=%d id=%d len=%d", __func__, type, id, len); + log::verbose("type={} id={} len={}", type, id, len); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } @@ -576,15 +576,15 @@ static bt_status_t send_report(bthd_report_type_t type, uint8_t id, * ******************************************************************************/ static bt_status_t report_error(uint8_t error) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } @@ -603,15 +603,15 @@ static bt_status_t report_error(uint8_t error) { * ******************************************************************************/ static bt_status_t virtual_cable_unplug(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (!btif_hd_cb.app_registered) { - LOG_WARN("%s: application not yet registered", __func__); + log::warn("application not yet registered"); return BT_STATUS_NOT_READY; } if (btif_hd_cb.status != BTIF_HD_ENABLED) { - LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status); + log::warn("BT-HD not enabled, status={}", btif_hd_cb.status); return BT_STATUS_NOT_READY; } @@ -643,7 +643,7 @@ static const bthd_interface_t bthdInterface = { * ******************************************************************************/ bt_status_t btif_hd_execute_service(bool b_enable) { - LOG_VERBOSE("%s: b_enable=%d", __func__, b_enable); + log::verbose("b_enable={}", b_enable); if (!b_enable) BTA_HdDisable(); @@ -660,7 +660,7 @@ bt_status_t btif_hd_execute_service(bool b_enable) { * ******************************************************************************/ const bthd_interface_t* btif_hd_get_interface() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &bthdInterface; } @@ -674,7 +674,7 @@ const bthd_interface_t* btif_hd_get_interface() { * ******************************************************************************/ void btif_hd_service_registration() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); /* enable HD */ if (bt_hd_callbacks != NULL) { BTA_HdEnable(bte_hd_evt); diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc index 84cfb6c3634..6539d66df7b 100644 --- a/system/btif/src/btif_hf.cc +++ b/system/btif/src/btif_hf.cc @@ -31,6 +31,7 @@ #include <android_bluetooth_sysprop.h> #include <base/functional/callback.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h> #include <cstdint> @@ -94,14 +95,14 @@ static RawAddress active_bda = {}; ******************************************************************************/ static Callbacks* bt_hf_callbacks = nullptr; -#define CHECK_BTHF_INIT() \ - do { \ - if (!bt_hf_callbacks) { \ - LOG_WARN("BTHF: %s: BTHF not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } else { \ - LOG_VERBOSE("BTHF: %s", __func__); \ - } \ +#define CHECK_BTHF_INIT() \ + do { \ + if (!bt_hf_callbacks) { \ + log::warn("BTHF not initialized"); \ + return BT_STATUS_NOT_READY; \ + } else { \ + log::verbose("BTHF ok"); \ + } \ } while (false) /* BTIF-HF control block to map bdaddr to BTA handle */ @@ -285,13 +286,13 @@ static void reset_control_block(btif_hf_cb_t* hf_cb) { */ static bool IsSlcConnected(RawAddress* bd_addr) { if (!bd_addr) { - LOG(WARNING) << __func__ << ": bd_addr is null"; + log::warn("bd_addr is null"); return false; } int idx = btif_hf_idx_by_bdaddr(bd_addr); if (idx < 0 || idx > BTA_AG_MAX_NUM_CLIENTS) { - LOG(WARNING) << __func__ << ": invalid index " << idx << " for " - << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::warn("invalid index {} for {}", idx, + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return false; } return btif_hf_cb[idx].state == BTHF_CONNECTION_STATE_SLC_CONNECTED; @@ -308,32 +309,32 @@ static bool IsSlcConnected(RawAddress* bd_addr) { ******************************************************************************/ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { if (event == BTA_AG_ENABLE_EVT || event == BTA_AG_DISABLE_EVT) { - LOG(INFO) << __func__ << ": AG enable/disable event " << event; + log::info("AG enable/disable event {}", event); return; } if (p_param == nullptr) { - LOG(ERROR) << __func__ << ": parameter is null"; + log::error("parameter is null"); return; } tBTA_AG* p_data = (tBTA_AG*)p_param; int idx = p_data->hdr.handle - 1; - LOG_DEBUG("HF Upstream event:%s", dump_hf_event(event)); + log::debug("HF Upstream event:{}", dump_hf_event(event)); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s Invalid client index:%d", dump_hf_event(event), idx); + log::error("{} Invalid client index:{}", dump_hf_event(event), idx); return; } if (!bt_hf_callbacks) { - LOG_ERROR("%s Headset callback is not set", dump_hf_event(event)); + log::error("{} Headset callback is not set", dump_hf_event(event)); return; } switch (event) { case BTA_AG_REGISTER_EVT: btif_hf_cb[idx].handle = p_data->reg.hdr.handle; - LOG_DEBUG("%s idx:%d btif_hf_cb.handle = %d", dump_hf_event(event), idx, - btif_hf_cb[idx].handle); + log::debug("{} idx:{} btif_hf_cb.handle = {}", dump_hf_event(event), idx, + btif_hf_cb[idx].handle); break; // RFCOMM connected or failed to connect case BTA_AG_OPEN_EVT: @@ -349,22 +350,21 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { // Check if the incoming open event and the outgoing connection are // for the same device. if (p_data->open.bd_addr == btif_hf_cb[idx].connected_bda) { - LOG(WARNING) << __func__ << ": btif_hf_cb state[" - << p_data->open.status - << "] is not expected, possible connection collision, " - "ignoring AG open " - "failure event for the same device " - << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr); + log::warn( + "btif_hf_cb state[{}] is not expected, possible connection " + "collision, ignoring AG open failure event for the same device " + "{}", + p_data->open.status, + ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)); } else { - LOG(WARNING) << __func__ << ": btif_hf_cb state[" - << p_data->open.status - << "] is not expected, possible connection collision, " - "ignoring AG open failure " - "event for the different devices btif_hf_cb bda: " - << btif_hf_cb[idx].connected_bda - << ", p_data bda: " - << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr) - << ", report disconnect state for p_data bda."; + log::warn( + "btif_hf_cb state[{}] is not expected, possible connection " + "collision, ignoring AG open failure event for the different " + "devices btif_hf_cb bda: {}, p_data bda: {}, report disconnect " + "state for p_data bda.", + p_data->open.status, + ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda), + ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)); bt_hf_callbacks->ConnectionStateCallback( BTHF_CONNECTION_STATE_DISCONNECTED, &(p_data->open.bd_addr)); log_counter_metrics_btif( @@ -384,14 +384,12 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { // Check if the incoming open event and the outgoing connection are // for the same device. if (btif_hf_cb[idx].connected_bda != p_data->open.bd_addr) { - LOG(WARNING) << __func__ - << ": possible connection collision, ignore the " - "outgoing connection for the " - "different devices btif_hf_cb bda: " - << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda) - << ", p_data bda: " - << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr) - << ", report disconnect state for btif_hf_cb bda."; + log::warn( + "possible connection collision, ignore the outgoing connection " + "for the different devices btif_hf_cb bda: {}, p_data bda: {}, " + "report disconnect state for btif_hf_cb bda.", + ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda), + ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)); bt_hf_callbacks->ConnectionStateCallback( BTHF_CONNECTION_STATE_DISCONNECTED, &(btif_hf_cb[idx].connected_bda)); @@ -425,16 +423,14 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { } else { if (!btif_hf_cb[idx].is_initiator) { // Ignore remote initiated open failures - LOG(WARNING) << __func__ << ": Unexpected AG open failure " - << std::to_string(p_data->open.status) << " for " - << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr) - << " is ignored"; + log::warn("Unexpected AG open failure {} for {} is ignored", + p_data->open.status, + ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)); break; } - LOG(ERROR) << __func__ << ": self initiated AG open failed for " - << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda) - << ", status " - << std::to_string(p_data->open.status); + log::error("self initiated AG open failed for {}, status {}", + ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda), + p_data->open.status); RawAddress connected_bda = btif_hf_cb[idx].connected_bda; reset_control_block(&btif_hf_cb[idx]); bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, @@ -448,9 +444,9 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { } break; case BTA_AG_CLOSE_EVT: { - LOG_DEBUG( - "SLC and RFCOMM both disconnected event:%s idx:%d" - " btif_hf_cb.handle:%d", + log::debug( + "SLC and RFCOMM both disconnected event:{} idx:{} " + "btif_hf_cb.handle:{}", dump_hf_event(event), idx, btif_hf_cb[idx].handle); RawAddress connected_bda = btif_hf_cb[idx].connected_bda; bt_hf_callbacks->ConnectionStateCallback( @@ -465,7 +461,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, &connected_bda); if (failed_to_setup_slc) { - LOG(ERROR) << __func__ << ": failed to setup SLC for " << connected_bda; + log::error("failed to setup SLC for {}", + ADDRESS_TO_LOGGABLE_STR(connected_bda)); log_counter_metrics_btif( android::bluetooth::CodePathCounterKeyEnum::HFP_SLC_SETUP_FAILED, 1); @@ -486,7 +483,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { btif_hf_cb[idx].connected_bda, IOT_CONF_KEY_HFP_FEATURES, p_data->conn.peer_feat, IOT_CONF_BYTE_NUM_2); - LOG_DEBUG("SLC connected event:%s idx:%d", dump_hf_event(event), idx); + log::debug("SLC connected event:{} idx:{}", dump_hf_event(event), idx); btif_hf_cb[idx].peer_feat = p_data->conn.peer_feat; btif_hf_cb[idx].state = BTHF_CONNECTION_STATE_SLC_CONNECTED; bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state, @@ -497,13 +494,13 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_AG_AUDIO_OPEN_EVT: - LOG_DEBUG("Audio open event:%s", dump_hf_event(event)); + log::debug("Audio open event:{}", dump_hf_event(event)); bt_hf_callbacks->AudioStateCallback(BTHF_AUDIO_STATE_CONNECTED, &btif_hf_cb[idx].connected_bda); break; case BTA_AG_AUDIO_CLOSE_EVT: - LOG_DEBUG("Audio close event:%s", dump_hf_event(event)); + log::debug("Audio close event:{}", dump_hf_event(event)); DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(btif_hf_cb[idx].connected_bda, IOT_CONF_KEY_HFP_SCO_CONN_FAIL_COUNT); @@ -514,8 +511,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { case BTA_AG_SPK_EVT: case BTA_AG_MIC_EVT: - LOG_DEBUG("BTA auto-responds, silently discard event:%s", - dump_hf_event(event)); + log::debug("BTA auto-responds, silently discard event:{}", + dump_hf_event(event)); bt_hf_callbacks->VolumeControlCallback( (event == BTA_AG_SPK_EVT) ? BTHF_VOLUME_TYPE_SPK : BTHF_VOLUME_TYPE_MIC, @@ -569,8 +566,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_AG_CODEC_EVT: - LOG_VERBOSE( - "BTA_AG_CODEC_EVT Set codec status %d codec %d 1=CVSD 2=MSBC 4=LC3", + log::verbose( + "BTA_AG_CODEC_EVT Set codec status {} codec {} 1=CVSD 2=MSBC 4=LC3", p_data->val.hdr.status, p_data->val.num); if (p_data->val.num == BTM_SCO_CODEC_CVSD) { bt_hf_callbacks->WbsCallback(BTHF_WBS_NO, @@ -597,8 +594,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { if (is_hfp_aptx_voice_enabled()) { codec = BTHF_SWB_CODEC_VENDOR_APTX; - LOG_VERBOSE( - "AG final selected SWB codec is 0x%02x 0=Q0 4=Q1 6=Q2 7=Q3", + log::verbose( + "AG final selected SWB codec is 0x{:02x} 0=Q0 4=Q1 6=Q2 7=Q3", p_data->val.num); if (p_data->val.num == BTA_AG_SCO_APTX_SWB_SETTINGS_Q0 || p_data->val.num == BTA_AG_SCO_APTX_SWB_SETTINGS_Q1 || @@ -644,27 +641,27 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { send_at_result(BTA_AG_OK_ERROR, BTA_AG_ERR_OP_NOT_SUPPORTED, idx); break; case BTA_AG_AT_BAC_EVT: - LOG_VERBOSE("AG Bitmap of peer-codecs %d", p_data->val.num); + log::verbose("AG Bitmap of peer-codecs {}", p_data->val.num); /* If the peer supports mSBC and the BTIF preferred codec is also mSBC, * then we should set the BTA AG Codec to mSBC. This would trigger a +BCS * to mSBC at the time of SCO connection establishment */ if (hfp_hal_interface::get_swb_supported() && (p_data->val.num & BTM_SCO_CODEC_LC3)) { - LOG_VERBOSE("%s: btif_hf override-Preferred Codec to LC3", __func__); + log::verbose("btif_hf override-Preferred Codec to LC3"); BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_LC3); } else if (hfp_hal_interface::get_wbs_supported() && (p_data->val.num & BTM_SCO_CODEC_MSBC)) { - LOG_VERBOSE("%s: btif_hf override-Preferred Codec to mSBC", __func__); + log::verbose("btif_hf override-Preferred Codec to mSBC"); BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_MSBC); } else { - LOG_VERBOSE("%s btif_hf override-Preferred Codec to CVSD", __func__); + log::verbose("btif_hf override-Preferred Codec to CVSD"); BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_CVSD); } break; case BTA_AG_AT_BCS_EVT: - LOG_VERBOSE("AG final selected codec is 0x%02x 1=CVSD 2=MSBC", - p_data->val.num); + log::verbose("AG final selected codec is 0x{:02x} 1=CVSD 2=MSBC", + p_data->val.num); /* No BTHF_WBS_NONE case, because HF1.6 supported device can send BCS */ /* Only CVSD is considered narrow band speech */ bt_hf_callbacks->WbsCallback( @@ -704,13 +701,12 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { case BTA_AG_AT_QCS_EVT: if (!is_hfp_aptx_voice_enabled()) { - LOG(WARNING) << __func__ << ": unhandled event " << event - << ". Aptx codec is not enabled"; + log::warn("unhandled event {}. Aptx codec is not enabled", event); break; } - LOG_INFO("AG final selected SWB codec is %#02x 0=Q0 4=Q1 6=Q2 7=Q3", - p_data->val.num); + log::info("AG final selected SWB codec is {:#02x} 0=Q0 4=Q1 6=Q2 7=Q3", + p_data->val.num); bt_hf_callbacks->SwbCallback( BTHF_SWB_CODEC_VENDOR_APTX, p_data->val.num <= BTA_AG_SCO_APTX_SWB_SETTINGS_Q3 ? BTHF_SWB_YES @@ -719,7 +715,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) { break; default: - LOG(WARNING) << __func__ << ": unhandled event " << event; + log::warn("unhandled event {}", event); break; } } @@ -773,8 +769,8 @@ static void bte_hf_evt(tBTA_AG_EVT event, tBTA_AG* p_data) { static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) { CHECK_BTHF_INIT(); if (is_connected(bd_addr)) { - LOG_WARN("%s: device %s is already connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::warn("device {} is already connected", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_DONE; } btif_hf_cb_t* hf_cb = nullptr; @@ -787,15 +783,14 @@ static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) { // control block should be in connecting state // Crash here to prevent future code changes from breaking this mechanism if (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_CONNECTING) { - LOG(FATAL) << __func__ << ": " - << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[i].connected_bda) - << ", handle " << btif_hf_cb[i].handle - << ", is still in connecting state " << btif_hf_cb[i].state; + log::fatal("{}, handle {}, is still in connecting state {}", + ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[i].connected_bda), + btif_hf_cb[i].handle, btif_hf_cb[i].state); } } if (hf_cb == nullptr) { - LOG_WARN("%s: Cannot connect %s: maximum %d clients already connected", - __func__, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), btif_max_hf_clients); + log::warn("Cannot connect {}: maximum {} clients already connected", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), btif_max_hf_clients); return BT_STATUS_BUSY; } hf_cb->state = BTHF_CONNECTION_STATE_CONNECTING; @@ -901,10 +896,9 @@ bt_status_t HeadsetInterface::Init(Callbacks* callbacks, int max_hf_clients, " maximum is " << BTA_AG_MAX_NUM_CLIENTS << " was given " << max_hf_clients; btif_max_hf_clients = max_hf_clients; - LOG_VERBOSE("%s: btif_hf_features=%" PRIu32 - ", max_hf_clients=%d, inband_ringing_enabled=%d", - __func__, btif_hf_features, btif_max_hf_clients, - inband_ringing_enabled); + log::verbose( + "btif_hf_features={}, max_hf_clients={}, inband_ringing_enabled={}", + btif_hf_features, btif_max_hf_clients, inband_ringing_enabled); bt_hf_callbacks = callbacks; for (btif_hf_cb_t& hf_cb : btif_hf_cb) { reset_control_block(&hf_cb); @@ -931,12 +925,11 @@ bt_status_t HeadsetInterface::Disconnect(RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } BTA_AgClose(btif_hf_cb[idx].handle); @@ -948,13 +941,12 @@ bt_status_t HeadsetInterface::ConnectAudio(RawAddress* bd_addr, CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } /* Check if SLC is connected */ if (!IsSlcConnected(bd_addr)) { - LOG(ERROR) << ": SLC not connected for " - << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::error("SLC not connected for {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_NOT_READY; } do_in_jni_thread(base::BindOnce(&Callbacks::AudioStateCallback, @@ -973,12 +965,11 @@ bt_status_t HeadsetInterface::DisconnectAudio(RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } BTA_AgAudioClose(btif_hf_cb[idx].handle); @@ -989,7 +980,7 @@ bt_status_t HeadsetInterface::isNoiseReductionSupported(RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_ECNR)) { @@ -1002,7 +993,7 @@ bt_status_t HeadsetInterface::isVoiceRecognitionSupported(RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) { @@ -1015,17 +1006,16 @@ bt_status_t HeadsetInterface::StartVoiceRecognition(RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_NOT_READY; } if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) { - LOG_ERROR("%s: voice recognition not supported, features=0x%x", __func__, - btif_hf_cb[idx].peer_feat); + log::error("voice recognition not supported, features=0x{:x}", + btif_hf_cb[idx].peer_feat); return BT_STATUS_UNSUPPORTED; } tBTA_AG_RES_DATA ag_res = {}; @@ -1039,17 +1029,16 @@ bt_status_t HeadsetInterface::StopVoiceRecognition(RawAddress* bd_addr) { int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_NOT_READY; } if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) { - LOG_ERROR("%s: voice recognition not supported, features=0x%x", __func__, - btif_hf_cb[idx].peer_feat); + log::error("voice recognition not supported, features=0x{:x}", + btif_hf_cb[idx].peer_feat); return BT_STATUS_UNSUPPORTED; } tBTA_AG_RES_DATA ag_res = {}; @@ -1063,12 +1052,11 @@ bt_status_t HeadsetInterface::VolumeControl(bthf_volume_type_t type, int volume, CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } tBTA_AG_RES_DATA ag_res = {}; @@ -1084,13 +1072,13 @@ bt_status_t HeadsetInterface::DeviceStatusNotification( int batt_chg, RawAddress* bd_addr) { CHECK_BTHF_INIT(); if (!bd_addr) { - LOG_WARN("%s: bd_addr is null", __func__); + log::warn("bd_addr is null"); return BT_STATUS_FAIL; } int idx = btif_hf_idx_by_bdaddr(bd_addr); if (idx < 0 || idx > BTA_AG_MAX_NUM_CLIENTS) { - LOG_WARN("%s: invalid index %d for %s", __func__, idx, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::warn("invalid index {} for {}", idx, + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } const btif_hf_cb_t& control_block = btif_hf_cb[idx]; @@ -1113,12 +1101,11 @@ bt_status_t HeadsetInterface::CopsResponse(const char* cops, CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } tBTA_AG_RES_DATA ag_res = {}; @@ -1137,12 +1124,11 @@ bt_status_t HeadsetInterface::CindResponse(int svc, int num_active, CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } tBTA_AG_RES_DATA ag_res = {}; @@ -1167,12 +1153,11 @@ bt_status_t HeadsetInterface::FormattedAtResponse(const char* rsp, tBTA_AG_RES_DATA ag_res = {}; int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } /* Format the response and send */ @@ -1186,12 +1171,11 @@ bt_status_t HeadsetInterface::AtResponse(bthf_at_response_t response_code, CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } send_at_result( @@ -1207,12 +1191,11 @@ bt_status_t HeadsetInterface::ClccResponse( CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d", __func__, idx); + log::error("Invalid index {}", idx); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s is not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } tBTA_AG_RES_DATA ag_res = {}; @@ -1221,8 +1204,8 @@ bt_status_t HeadsetInterface::ClccResponse( ag_res.ok_flag = BTA_AG_OK_DONE; } else { std::string cell_number(number ? number : ""); - LOG_VERBOSE( - "clcc_response: [%d] dir %d state %d mode %d number = %s type = %d", + log::verbose( + "clcc_response: [{}] dir {} state {} mode {} number = {} type = {}", index, dir, state, mode, PRIVATE_CELL(cell_number), type); int res_strlen = snprintf(ag_res.str, sizeof(ag_res.str), "%d,%d,%d,%d,%d", index, dir, state, mode, mpty); @@ -1259,38 +1242,37 @@ bt_status_t HeadsetInterface::PhoneStateChange( RawAddress* bd_addr) { CHECK_BTHF_INIT(); if (bd_addr == nullptr) { - LOG_WARN("bd_addr is null"); + log::warn("bd_addr is null"); return BT_STATUS_FAIL; } const RawAddress raw_address(*bd_addr); int idx = btif_hf_idx_by_bdaddr(bd_addr); if (idx < 0 || idx >= BTA_AG_MAX_NUM_CLIENTS) { - LOG_WARN("Invalid index %d for %s", idx, ADDRESS_TO_LOGGABLE_CSTR(raw_address)); + log::warn("Invalid index {} for {}", idx, + ADDRESS_TO_LOGGABLE_CSTR(raw_address)); return BT_STATUS_FAIL; } const btif_hf_cb_t& control_block = btif_hf_cb[idx]; if (!IsSlcConnected(bd_addr)) { - LOG(WARNING) << ": SLC not connected for " - << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::warn("SLC not connected for {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_NOT_READY; } if (call_setup_state == BTHF_CALL_STATE_DISCONNECTED) { // HFP spec does not handle cases when a call is being disconnected. // Since DISCONNECTED state must lead to IDLE state, ignoring it here.s - LOG(INFO) << __func__ - << ": Ignore call state change to DISCONNECTED, idx=" << idx - << ", addr=" - << ADDRESS_TO_LOGGABLE_STR(*bd_addr) - << ", num_active=" << num_active - << ", num_held=" << num_held; + log::info( + "Ignore call state change to DISCONNECTED, idx={}, addr={}, " + "num_active={}, num_held={}", + idx, ADDRESS_TO_LOGGABLE_STR(*bd_addr), num_active, num_held); return BT_STATUS_SUCCESS; } - LOG_DEBUG( - "bd_addr:%s active_bda:%s num_active:%u prev_num_active:%u num_held:%u " - "prev_num_held:%u call_state:%s prev_call_state:%s", - ADDRESS_TO_LOGGABLE_CSTR((*bd_addr)), ADDRESS_TO_LOGGABLE_CSTR(active_bda), num_active, + log::debug( + "bd_addr:{} active_bda:{} num_active:{} prev_num_active:{} num_held:{} " + "prev_num_held:{} call_state:{} prev_call_state:{}", + ADDRESS_TO_LOGGABLE_CSTR((*bd_addr)), + ADDRESS_TO_LOGGABLE_CSTR(active_bda), num_active, control_block.num_active, num_held, control_block.num_held, dump_hf_call_state(call_setup_state), dump_hf_call_state(control_block.call_setup_state)); @@ -1329,10 +1311,8 @@ bt_status_t HeadsetInterface::PhoneStateChange( (control_block.num_held == 0) && (control_block.call_setup_state == BTHF_CALL_STATE_IDLE)) { tBTA_AG_RES_DATA ag_res = {}; - LOG_VERBOSE( - "%s: Active/Held call notification received without call setup " - "update", - __func__); + log::verbose( + "Active/Held call notification received without call setup update"); ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE; // Addition call setup with the Active call @@ -1351,9 +1331,9 @@ bt_status_t HeadsetInterface::PhoneStateChange( if (call_setup_state != control_block.call_setup_state) { tBTA_AG_RES_DATA ag_res = {}; ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE; - LOG_VERBOSE("%s: Call setup states changed. old: %s new: %s", __func__, - dump_hf_call_state(control_block.call_setup_state), - dump_hf_call_state(call_setup_state)); + log::verbose("Call setup states changed. old: {} new: {}", + dump_hf_call_state(control_block.call_setup_state), + dump_hf_call_state(call_setup_state)); switch (call_setup_state) { case BTHF_CALL_STATE_IDLE: { switch (control_block.call_setup_state) { @@ -1376,8 +1356,8 @@ bt_status_t HeadsetInterface::PhoneStateChange( res = BTA_AG_CALL_CANCEL_RES; break; default: - LOG_ERROR("%s: Incorrect call state prev=%d, now=%d", __func__, - control_block.call_setup_state, call_setup_state); + log::error("Incorrect call state prev={}, now={}", + control_block.call_setup_state, call_setup_state); status = BT_STATUS_PARM_INVALID; break; } @@ -1464,13 +1444,13 @@ bt_status_t HeadsetInterface::PhoneStateChange( res = BTA_AG_OUT_CALL_ALERT_RES; break; default: - LOG_ERROR("%s: Incorrect call state prev=%d, now=%d", __func__, - control_block.call_setup_state, call_setup_state); + log::error("Incorrect call state prev={}, now={}", + control_block.call_setup_state, call_setup_state); status = BT_STATUS_PARM_INVALID; break; } - LOG_VERBOSE("%s: Call setup state changed. res=%d, audio_handle=%d", - __func__, res, ag_res.audio_handle); + log::verbose("Call setup state changed. res={}, audio_handle={}", res, + ag_res.audio_handle); if (res != 0xFF) { BTA_AgResult(control_block.handle, res, ag_res); @@ -1500,9 +1480,9 @@ bt_status_t HeadsetInterface::PhoneStateChange( if (!active_call_updated && ((num_active + num_held) != (control_block.num_active + control_block.num_held))) { - VLOG(1) << __func__ << ": in progress call states changed, active=[" - << control_block.num_active << "->" << num_active << "], held=[" - << control_block.num_held << "->" << num_held; + log::verbose( + "in progress call states changed, active=[{}->{}], held=[{}->{}]", + control_block.num_active, num_active, control_block.num_held, num_held); send_indicator_update(control_block, BTA_AG_IND_CALL, ((num_active + num_held) > 0) ? BTA_AG_CALL_ACTIVE : BTA_AG_CALL_INACTIVE); @@ -1511,8 +1491,8 @@ bt_status_t HeadsetInterface::PhoneStateChange( /* Held Changed? */ if (num_held != control_block.num_held || ((num_active == 0) && ((num_held + control_block.num_held) > 1))) { - LOG_VERBOSE("%s: Held call states changed. old: %d new: %d", __func__, - control_block.num_held, num_held); + log::verbose("Held call states changed. old: {} new: {}", + control_block.num_held, num_held); send_indicator_update(control_block, BTA_AG_IND_CALLHELD, ((num_held == 0) ? 0 : ((num_active == 0) ? 2 : 1))); } @@ -1521,7 +1501,7 @@ bt_status_t HeadsetInterface::PhoneStateChange( if ((call_setup_state == control_block.call_setup_state) && (num_active && num_held) && (num_active == control_block.num_active) && (num_held == control_block.num_held)) { - LOG_VERBOSE("%s: Calls swapped", __func__); + log::verbose("Calls swapped"); send_indicator_update(control_block, BTA_AG_IND_CALLHELD, 1); } @@ -1548,7 +1528,7 @@ bt_status_t HeadsetInterface::PhoneStateChange( } void HeadsetInterface::Cleanup() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE); @@ -1583,13 +1563,12 @@ bt_status_t HeadsetInterface::SendBsir(bool value, RawAddress* bd_addr) { CHECK_BTHF_INIT(); int idx = btif_hf_idx_by_bdaddr(bd_addr); if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) { - LOG_ERROR("%s: Invalid index %d for %s", __func__, idx, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Invalid index {} for {}", idx, + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } if (!is_connected(bd_addr)) { - LOG_ERROR("%s: %s not connected", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("{} not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } tBTA_AG_RES_DATA ag_result = {}; @@ -1628,7 +1607,7 @@ bt_status_t HeadsetInterface::DebugDump() { * ******************************************************************************/ bt_status_t ExecuteService(bool b_enable) { - LOG_INFO("service starts to: %s", b_enable ? "Initialize" : "Shutdown"); + log::info("service starts to: {}", b_enable ? "Initialize" : "Shutdown"); const char* service_names_raw[] = BTIF_HF_SERVICE_NAMES; std::vector<std::string> service_names; for (const char* service_name_raw : service_names_raw) { @@ -1664,7 +1643,7 @@ bt_status_t ExecuteService(bool b_enable) { * ******************************************************************************/ Interface* GetInterface() { - VLOG(0) << __func__; + log::verbose(""); return HeadsetInterface::GetInstance(); } diff --git a/system/btif/src/btif_hf_client.cc b/system/btif/src/btif_hf_client.cc index c46f85e5c9b..b66b48b2e38 100644 --- a/system/btif/src/btif_hf_client.cc +++ b/system/btif/src/btif_hf_client.cc @@ -47,6 +47,7 @@ #endif #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_hf_client.h> #include <string.h> @@ -68,6 +69,8 @@ #define BTIF_HF_CLIENT_SERVICE_NAME ("Handsfree") #endif +using namespace bluetooth; + /******************************************************************************* * Local type definitions ******************************************************************************/ @@ -112,28 +115,28 @@ static const char* dump_hf_client_conn_state(uint16_t event) { } } -#define CHECK_BTHF_CLIENT_INIT() \ - do { \ - if (bt_hf_client_callbacks == NULL) { \ - LOG_WARN("BTHF CLIENT: %s: not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } else { \ - LOG_VERBOSE("BTHF CLIENT: %s", __func__); \ - } \ +#define CHECK_BTHF_CLIENT_INIT() \ + do { \ + if (bt_hf_client_callbacks == NULL) { \ + log::warn("BTHF CLIENT: not initialized"); \ + return BT_STATUS_NOT_READY; \ + } else { \ + log::verbose("BTHF CLIENT: ok"); \ + } \ } while (0) -#define CHECK_BTHF_CLIENT_SLC_CONNECTED(cb) \ - do { \ - if (bt_hf_client_callbacks == NULL) { \ - LOG_WARN("BTHF CLIENT: %s: not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } else if ((cb)->state != BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \ - LOG_WARN("BTHF CLIENT: %s: SLC connection not up. state=%s", __func__, \ - dump_hf_client_conn_state((cb)->state)); \ - return BT_STATUS_NOT_READY; \ - } else { \ - LOG_VERBOSE("BTHF CLIENT: %s", __func__); \ - } \ +#define CHECK_BTHF_CLIENT_SLC_CONNECTED(cb) \ + do { \ + if (bt_hf_client_callbacks == NULL) { \ + log::warn("BTHF CLIENT: not initialized"); \ + return BT_STATUS_NOT_READY; \ + } else if ((cb)->state != BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \ + log::warn("BTHF CLIENT: SLC connection not up. state={}", \ + dump_hf_client_conn_state((cb)->state)); \ + return BT_STATUS_NOT_READY; \ + } else { \ + log::verbose("BTHF CLIENT: ok"); \ + } \ } while (0) static btif_hf_client_cb_arr_t btif_hf_client_cb_arr; @@ -155,22 +158,22 @@ static btif_hf_client_cb_arr_t btif_hf_client_cb_arr; ******************************************************************************/ constexpr uint16_t BTIF_HF_CLIENT_CB_AUDIO_CONNECTING = 0x8501; static void btif_in_hf_client_generic_evt(uint16_t event, char* p_param) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); RawAddress* bd_addr = (RawAddress*)p_param; btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(*bd_addr); if (cb == NULL || !is_connected(cb)) { - LOG_ERROR("%s: failed to find block for bda", __func__); + log::error("failed to find block for bda"); return; } - LOG_VERBOSE("%s: event=%d", __func__, event); + log::verbose("event={}", event); switch (event) { case BTIF_HF_CLIENT_CB_AUDIO_CONNECTING: { HAL_CBACK(bt_hf_client_callbacks, audio_state_cb, &cb->peer_bda, (bthf_client_audio_state_t)BTHF_CLIENT_AUDIO_STATE_CONNECTING); } break; default: { - LOG_WARN("%s: : Unknown event 0x%x", __func__, event); + log::warn(": Unknown event 0x{:x}", event); } break; } } @@ -183,7 +186,7 @@ bool is_connected(const btif_hf_client_cb_t* cb) { (cb->state == BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED)) return true; - LOG_ERROR("%s: not connected!", __func__); + log::error("not connected!"); return false; } @@ -197,7 +200,7 @@ bool is_connected(const btif_hf_client_cb_t* cb) { * ******************************************************************************/ btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) { - LOG_VERBOSE("%s: cb by handle %d", __func__, handle); + log::verbose("cb by handle {}", handle); for (int i = 0; i < HF_CLIENT_MAX_DEVICES; i++) { // Block is valid only if it is allocated i.e. state is not DISCONNECTED if (btif_hf_client_cb_arr.cb[i].state != @@ -206,7 +209,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) { return &btif_hf_client_cb_arr.cb[i]; } } - LOG_ERROR("%s: could not find block for handle %d", __func__, handle); + log::error("could not find block for handle {}", handle); return NULL; } @@ -220,7 +223,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) { * ******************************************************************************/ btif_hf_client_cb_t* btif_hf_client_get_cb_by_bda(const RawAddress& bd_addr) { - VLOG(1) << __func__ << " incoming addr " << ADDRESS_TO_LOGGABLE_CSTR(bd_addr); + log::verbose("incoming addr {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); for (int i = 0; i < HF_CLIENT_MAX_DEVICES; i++) { // Block is valid only if it is allocated i.e. state is not DISCONNECTED @@ -230,7 +233,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_bda(const RawAddress& bd_addr) { return &btif_hf_client_cb_arr.cb[i]; } } - LOG_ERROR("%s: could not find block for bdaddr", __func__); + log::error("could not find block for bdaddr"); return NULL; } @@ -250,7 +253,7 @@ btif_hf_client_cb_t* btif_hf_client_allocate_cb() { return cb; } } - LOG_ERROR("%s: unable to allocate control block", __func__); + log::error("unable to allocate control block"); return NULL; } @@ -270,7 +273,7 @@ btif_hf_client_cb_t* btif_hf_client_allocate_cb() { * ******************************************************************************/ static bt_status_t init(bthf_client_callbacks_t* callbacks) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); bt_hf_client_callbacks = callbacks; @@ -293,7 +296,7 @@ static bt_status_t init(bthf_client_callbacks_t* callbacks) { static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) { btif_hf_client_cb_t* cb = btif_hf_client_allocate_cb(); if (cb == NULL) { - LOG_ERROR("%s: could not allocate block!", __func__); + log::error("could not allocate block!"); return BT_STATUS_BUSY; } @@ -311,7 +314,7 @@ static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) { } static bt_status_t connect(const RawAddress* bd_addr) { - LOG_VERBOSE("HFP Client version is %s", btif_hf_client_version); + log::verbose("HFP Client version is {}", btif_hf_client_version); CHECK_BTHF_CLIENT_INIT(); return btif_queue_connect(UUID_SERVCLASS_HF_HANDSFREE, bd_addr, connect_int); } @@ -704,7 +707,7 @@ static bt_status_t request_last_voice_tag_number(const RawAddress* bd_addr) { * ******************************************************************************/ static void cleanup(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_queue_cleanup(UUID_SERVCLASS_HF_HANDSFREE); if (bt_hf_client_callbacks) { @@ -729,8 +732,8 @@ static bt_status_t send_at_cmd(const RawAddress* bd_addr, int cmd, int val1, CHECK_BTHF_CLIENT_SLC_CONNECTED(cb); - LOG_VERBOSE("%s: Cmd %d val1 %d val2 %d arg %s", __func__, cmd, val1, val2, - (arg != NULL) ? arg : "<null>"); + log::verbose("Cmd {} val1 {} val2 {} arg {}", cmd, val1, val2, + (arg != NULL) ? arg : "<null>"); BTA_HfClientSendAT(cb->handle, cmd, val1, val2, arg); return BT_STATUS_SUCCESS; @@ -751,7 +754,7 @@ static bt_status_t send_android_at(const RawAddress* bd_addr, const char* arg) { CHECK_BTHF_CLIENT_SLC_CONNECTED(cb); - LOG_VERBOSE("%s: val1 %s", __func__, arg); + log::verbose("val1 {}", arg); BTA_HfClientSendAT(cb->handle, BTA_HF_CLIENT_AT_CMD_ANDROID, 0, 0, arg); return BT_STATUS_SUCCESS; @@ -781,7 +784,7 @@ static const bthf_client_interface_t bthfClientInterface = { }; static void process_ind_evt(tBTA_HF_CLIENT_IND* ind) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(ind->bd_addr); if (cb == NULL || !is_connected(cb)) return; @@ -840,23 +843,20 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(p_data->bd_addr); if (cb == NULL && event == BTA_HF_CLIENT_OPEN_EVT) { - LOG_VERBOSE("%s: event BTA_HF_CLIENT_OPEN_EVT allocating block", __func__); + log::verbose("event BTA_HF_CLIENT_OPEN_EVT allocating block"); cb = btif_hf_client_allocate_cb(); if (cb == NULL) { - LOG_ERROR("%s: event BTA_HF_CLIENT_OPEN_EVT failed to allocate cb", - __func__); + log::error("event BTA_HF_CLIENT_OPEN_EVT failed to allocate cb"); return; } cb->handle = p_data->open.handle; cb->peer_bda = p_data->open.bd_addr; } else if (cb == NULL) { - LOG_ERROR("%s: event %d but not allocating block: cb not found", __func__, - event); + log::error("event {} but not allocating block: cb not found", event); return; } - LOG_VERBOSE("%s: event=%s (%u)", __func__, dump_hf_client_event(event), - event); + log::verbose("event={} ({})", dump_hf_client_event(event), event); switch (event) { case BTA_HF_CLIENT_OPEN_EVT: @@ -868,10 +868,10 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { } else if (cb->state == BTHF_CLIENT_CONNECTION_STATE_CONNECTING) { cb->state = BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED; } else { - LOG_WARN( - "%s: HF CLient open failed, but another device connected. " - "status=%d state=%d connected device=%s", - __func__, p_data->open.status, cb->state, + log::warn( + "HF CLient open failed, but another device connected. status={} " + "state={} connected device={}", + p_data->open.status, cb->state, ADDRESS_TO_LOGGABLE_CSTR(cb->peer_bda)); break; } @@ -1040,7 +1040,7 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { p_data->unknown.event_string); break; default: - LOG_WARN("%s: Unhandled event: %d", __func__, event); + log::warn("Unhandled event: {}", event); break; } } @@ -1078,7 +1078,7 @@ static void bta_hf_client_evt(tBTA_HF_CLIENT_EVT event, * ******************************************************************************/ bt_status_t btif_hf_client_execute_service(bool b_enable) { - LOG_VERBOSE("%s: enable: %d", __func__, b_enable); + log::verbose("enable: {}", b_enable); tBTA_HF_CLIENT_FEAT features = get_default_hf_client_features(); uint16_t hfp_version = get_default_hfp_version(); @@ -1092,7 +1092,7 @@ bt_status_t btif_hf_client_execute_service(bool b_enable) { if (b_enable) { /* Enable and register with BTA-HFClient */ - LOG_VERBOSE("%s: support codec negotiation %d ", __func__, features); + log::verbose("support codec negotiation {}", features); BTA_HfClientEnable(bta_hf_client_evt, features, BTIF_HF_CLIENT_SERVICE_NAME); } else { @@ -1111,6 +1111,6 @@ bt_status_t btif_hf_client_execute_service(bool b_enable) { * ******************************************************************************/ const bthf_client_interface_t* btif_hf_client_get_interface(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &bthfClientInterface; } diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc index 968af1ae125..56887822a07 100644 --- a/system/btif/src/btif_hh.cc +++ b/system/btif/src/btif_hh.cc @@ -30,6 +30,7 @@ #include "btif/include/btif_hh.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <cstdint> @@ -62,6 +63,8 @@ #define LOGITECH_KB_MX5500_VENDOR_ID 0x046D #define LOGITECH_KB_MX5500_PRODUCT_ID 0xB30B +using namespace bluetooth; + static int btif_hh_keylockstates = 0; // The current key state of each key #define BTIF_TIMEOUT_VUP_MS (3 * 1000) @@ -103,12 +106,12 @@ static tHID_KB_LIST hid_kb_numlock_on_list[] = {{LOGITECH_KB_MX5500_PRODUCT_ID, LOGITECH_KB_MX5500_VENDOR_ID, "Logitech MX5500 Keyboard"}}; -#define CHECK_BTHH_INIT() \ - do { \ - if (bt_hh_callbacks == NULL) { \ - LOG_WARN("BTHH: %s: BTHH not initialized", __func__); \ - return BT_STATUS_NOT_READY; \ - } \ +#define CHECK_BTHH_INIT() \ + do { \ + if (bt_hh_callbacks == NULL) { \ + log::warn("BTHH: BTHH not initialized"); \ + return BT_STATUS_NOT_READY; \ + } \ } while (0) /******************************************************************************* @@ -160,8 +163,7 @@ static void set_keylockstate(int keymask, bool isSet) { ******************************************************************************/ static void toggle_os_keylockstates(int fd, int changedlockstates) { - LOG_VERBOSE("%s: fd = %d, changedlockstates = 0x%x", __func__, fd, - changedlockstates); + log::verbose("fd = {}, changedlockstates = 0x{:x}", fd, changedlockstates); uint8_t hidreport[9]; int reportIndex; memset(hidreport, 0, 9); @@ -169,40 +171,32 @@ static void toggle_os_keylockstates(int fd, int changedlockstates) { reportIndex = 4; if (changedlockstates & BTIF_HH_KEYSTATE_MASK_CAPSLOCK) { - LOG_VERBOSE("%s Setting CAPSLOCK", __func__); + log::verbose("Setting CAPSLOCK"); hidreport[reportIndex++] = (uint8_t)HID_REPORT_CAPSLOCK; } if (changedlockstates & BTIF_HH_KEYSTATE_MASK_NUMLOCK) { - LOG_VERBOSE("%s Setting NUMLOCK", __func__); + log::verbose("Setting NUMLOCK"); hidreport[reportIndex++] = (uint8_t)HID_REPORT_NUMLOCK; } if (changedlockstates & BTIF_HH_KEYSTATE_MASK_SCROLLLOCK) { - LOG_VERBOSE("%s Setting SCROLLLOCK", __func__); + log::verbose("Setting SCROLLLOCK"); hidreport[reportIndex++] = (uint8_t)HID_REPORT_SCROLLLOCK; } - LOG_VERBOSE( - "Writing hidreport #1 to os: " - "%s: %x %x %x", - __func__, hidreport[0], hidreport[1], hidreport[2]); - LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[3], hidreport[4], - hidreport[5]); - LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[6], hidreport[7], - hidreport[8]); + log::verbose("Writing hidreport #1 to os:"); + log::verbose("| {:x} {:x} {:x}", hidreport[0], hidreport[1], hidreport[2]); + log::verbose("| {:x} {:x} {:x}", hidreport[3], hidreport[4], hidreport[5]); + log::verbose("| {:x} {:x} {:x}", hidreport[6], hidreport[7], hidreport[8]); bta_hh_co_write(fd, hidreport, sizeof(hidreport)); usleep(200000); memset(hidreport, 0, 9); hidreport[0] = 1; - LOG_VERBOSE( - "Writing hidreport #2 to os: " - "%s: %x %x %x", - __func__, hidreport[0], hidreport[1], hidreport[2]); - LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[3], hidreport[4], - hidreport[5]); - LOG_VERBOSE("%s: %x %x %x ", __func__, hidreport[6], hidreport[7], - hidreport[8]); + log::verbose("Writing hidreport #2 to os:"); + log::verbose("| {:x} {:x} {:x}", hidreport[0], hidreport[1], hidreport[2]); + log::verbose("| {:x} {:x} {:x}", hidreport[3], hidreport[4], hidreport[5]); + log::verbose("| {:x} {:x} {:x}", hidreport[6], hidreport[7], hidreport[8]); bta_hh_co_write(fd, hidreport, sizeof(hidreport)); } @@ -241,8 +235,8 @@ static void update_keyboard_lockstates(btif_hh_device_t* p_dev) { static_cast<uint8_t>(btif_hh_keylockstates)}; /* keystate */ /* Set report for other keyboards */ - LOG_VERBOSE("%s: setting report on dev_handle %d to 0x%x", __func__, - p_dev->dev_handle, btif_hh_keylockstates); + log::verbose("setting report on dev_handle {} to 0x{:x}", p_dev->dev_handle, + btif_hh_keylockstates); /* Get SetReport buffer */ p_buf = create_pbuf(len, data); @@ -265,10 +259,7 @@ static void update_keyboard_lockstates(btif_hh_device_t* p_dev) { static void sync_lockstate_on_connect(btif_hh_device_t* p_dev) { int keylockstates; - LOG_VERBOSE( - "%s: Syncing keyboard lock states after " - "reconnect...", - __func__); + log::verbose("Syncing keyboard lock states after reconnect..."); /*If the device is connected, update keyboard state */ update_keyboard_lockstates(p_dev); @@ -277,17 +268,15 @@ static void sync_lockstate_on_connect(btif_hh_device_t* p_dev) { so the lockstate is in sync */ keylockstates = get_keylockstates(); if (keylockstates) { - LOG_VERBOSE( - "%s: Sending hid report to kernel " - "indicating lock key state 0x%x", - __func__, keylockstates); + log::verbose( + "Sending hid report to kernel indicating lock key state 0x{:x}", + keylockstates); usleep(200000); toggle_os_keylockstates(p_dev->fd, keylockstates); } else { - LOG_VERBOSE( - "%s: NOT sending hid report to kernel " - "indicating lock key state 0x%x", - __func__, keylockstates); + log::verbose( + "NOT sending hid report to kernel indicating lock key state 0x{:x}", + keylockstates); } } @@ -364,7 +353,7 @@ static void btif_hh_stop_vup_timer(tAclLinkSpec* link_spec) { btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec); if (p_dev != NULL) { - LOG_VERBOSE("stop VUP timer"); + log::verbose("stop VUP timer"); alarm_free(p_dev->vup_timer); p_dev->vup_timer = NULL; } @@ -378,7 +367,7 @@ static void btif_hh_stop_vup_timer(tAclLinkSpec* link_spec) { * Returns void ******************************************************************************/ static void btif_hh_start_vup_timer(const tAclLinkSpec* link_spec) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec); CHECK(p_dev != NULL); @@ -402,7 +391,7 @@ static void hh_connect_complete(uint8_t handle, tAclLinkSpec& link_spec, } static void hh_open_handler(tBTA_HH_CONN& conn) { - LOG_DEBUG("status = %d, handle = %d", conn.status, conn.handle); + log::debug("status = {}, handle = {}", conn.status, conn.handle); HAL_CBACK(bt_hh_callbacks, connection_state_cb, (RawAddress*)&conn.link_spec.addrt.bda, BTHH_CONN_STATE_CONNECTING); @@ -422,7 +411,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) { /* Initialize device driver */ if (!bta_hh_co_open(conn.handle, conn.sub_class, conn.attr_mask, conn.app_id)) { - LOG_WARN("Failed to find the uhid driver"); + log::warn("Failed to find the uhid driver"); hh_connect_complete(conn.handle, conn.link_spec, BTIF_HH_DEV_DISCONNECTED); return; } @@ -431,12 +420,12 @@ static void hh_open_handler(tBTA_HH_CONN& conn) { if (p_dev == NULL) { /* The connect request must have come from device side and exceeded the * connected HID device number. */ - LOG_WARN("Cannot find device with handle %d", conn.handle); + log::warn("Cannot find device with handle {}", conn.handle); hh_connect_complete(conn.handle, conn.link_spec, BTIF_HH_DEV_DISCONNECTED); return; } - LOG_INFO("Found device, getting dscp info for handle %d", conn.handle); + log::info("Found device, getting dscp info for handle {}", conn.handle); p_dev->link_spec = conn.link_spec; p_dev->dev_status = BTHH_CONN_STATE_CONNECTED; @@ -463,14 +452,13 @@ bool btif_hh_add_added_dev(const tAclLinkSpec& link_spec, for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) { if (btif_hh_cb.added_devices[i].link_spec.addrt.bda == link_spec.addrt.bda) { - LOG(WARNING) << " Device " << ADDRESS_TO_LOGGABLE_STR(link_spec) - << " already added"; + log::warn("Device {} already added", ADDRESS_TO_LOGGABLE_STR(link_spec)); return false; } } for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) { if (btif_hh_cb.added_devices[i].link_spec.addrt.bda.IsEmpty()) { - LOG(WARNING) << " Added device " << ADDRESS_TO_LOGGABLE_STR(link_spec); + log::warn("Added device {}", ADDRESS_TO_LOGGABLE_STR(link_spec)); btif_hh_cb.added_devices[i].link_spec = link_spec; btif_hh_cb.added_devices[i].dev_handle = BTA_HH_INVALID_HANDLE; btif_hh_cb.added_devices[i].attr_mask = attr_mask; @@ -478,7 +466,7 @@ bool btif_hh_add_added_dev(const tAclLinkSpec& link_spec, } } - LOG_WARN("%s: Error, out of space to add device", __func__); + log::warn("Error, out of space to add device"); return false; } @@ -495,7 +483,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) { btif_hh_device_t* p_dev; btif_hh_added_device_t* p_added_dev; - LOG(INFO) << __func__ << ": transport = " << link_spec.ToString(); + log::info("transport = {}", link_spec.ToString()); for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) { p_added_dev = &btif_hh_cb.added_devices[i]; @@ -510,8 +498,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) { p_dev = btif_hh_find_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(WARNING) << " Oops, can't find device " - << ADDRESS_TO_LOGGABLE_STR(link_spec); + log::warn("Oops, can't find device {}", ADDRESS_TO_LOGGABLE_STR(link_spec)); return; } @@ -532,7 +519,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) { if (btif_hh_cb.device_num > 0) { btif_hh_cb.device_num--; } else { - LOG_WARN("%s: device_num = 0", __func__); + log::warn("device_num = 0"); } bta_hh_co_close(p_dev); @@ -569,13 +556,13 @@ bool btif_hh_copy_hid_info(tBTA_HH_DEV_DSCP_INFO* dest, ******************************************************************************/ bt_status_t btif_hh_virtual_unplug(const tAclLinkSpec* link_spec) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_hh_device_t* p_dev; p_dev = btif_hh_find_dev_by_bda(*link_spec); if ((p_dev != NULL) && (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED) && (p_dev->attr_mask & HID_VIRTUAL_CABLE)) { - LOG_VERBOSE("%s: Sending BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG for: %s", - __func__, ADDRESS_TO_LOGGABLE_CSTR(*link_spec)); + log::verbose("Sending BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG for: {}", + ADDRESS_TO_LOGGABLE_CSTR(*link_spec)); /* start the timer */ btif_hh_start_vup_timer(link_spec); p_dev->local_vup = true; @@ -583,16 +570,16 @@ bt_status_t btif_hh_virtual_unplug(const tAclLinkSpec* link_spec) { return BT_STATUS_SUCCESS; } else if ((p_dev != NULL) && (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED)) { - LOG_ERROR("%s: Virtual unplug not supported, disconnecting device: %s", - __func__, ADDRESS_TO_LOGGABLE_CSTR(*link_spec)); + log::error("Virtual unplug not supported, disconnecting device: {}", + ADDRESS_TO_LOGGABLE_CSTR(*link_spec)); /* start the timer */ btif_hh_start_vup_timer(link_spec); p_dev->local_vup = true; BTA_HhClose(p_dev->dev_handle); return BT_STATUS_SUCCESS; } else { - LOG_ERROR("%s: Error, device %s not opened, status = %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*link_spec), btif_hh_cb.status); + log::error("Error, device {} not opened, status = {}", + ADDRESS_TO_LOGGABLE_CSTR(*link_spec), btif_hh_cb.status); if ((btif_hh_cb.pending_link_spec.addrt.bda == link_spec->addrt.bda) && (btif_hh_cb.status == BTIF_HH_DEV_CONNECTING)) { btif_hh_cb.status = (BTIF_HH_STATUS)BTIF_HH_DEV_DISCONNECTED; @@ -625,12 +612,12 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) { btif_hh_added_device_t* added_dev = NULL; CHECK_BTHH_INIT(); - LOG_VERBOSE("BTHH: %s", __func__); + log::verbose("BTHH"); btif_hh_device_t* dev = btif_hh_find_dev_by_bda(*link_spec); if (!dev && btif_hh_cb.device_num >= BTIF_HH_MAX_HID) { // No space for more HID device now. - LOG_WARN("%s: Error, exceeded the maximum supported HID device number %d", - __func__, BTIF_HH_MAX_HID); + log::warn("Error, exceeded the maximum supported HID device number {}", + BTIF_HH_MAX_HID); return BT_STATUS_NOMEM; } @@ -638,19 +625,16 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) { if (btif_hh_cb.added_devices[i].link_spec.addrt.bda == link_spec->addrt.bda) { added_dev = &btif_hh_cb.added_devices[i]; - LOG(WARNING) << __func__ << ": Device " - << ADDRESS_TO_LOGGABLE_STR(*link_spec) - << " already added, attr_mask = 0x" << std::hex - << added_dev->attr_mask; + log::warn("Device {} already added, attr_mask = 0x{:x}", + ADDRESS_TO_LOGGABLE_STR(*link_spec), added_dev->attr_mask); } } if (added_dev != NULL) { if (added_dev->dev_handle == BTA_HH_INVALID_HANDLE) { // No space for more HID device now. - LOG(ERROR) << __func__ << ": Error, device " - << ADDRESS_TO_LOGGABLE_STR(*link_spec) - << " added but addition failed"; + log::error("Error, device {} added but addition failed", + ADDRESS_TO_LOGGABLE_STR(*link_spec)); added_dev->link_spec = {}; added_dev->dev_handle = BTA_HH_INVALID_HANDLE; return BT_STATUS_NOMEM; @@ -658,8 +642,8 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) { } if (dev && dev->dev_status == BTHH_CONN_STATE_CONNECTED) { - LOG_DEBUG("HidHost profile already connected for %s", - ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); + log::debug("HidHost profile already connected for {}", + ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); return BT_STATUS_SUCCESS; } @@ -694,12 +678,12 @@ void btif_hh_disconnect(tAclLinkSpec* link_spec) { CHECK(link_spec != nullptr); const btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec); if (p_dev == nullptr) { - LOG_DEBUG("Unable to disconnect unknown HID device:%s", - ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); + log::debug("Unable to disconnect unknown HID device:{}", + ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); return; } - LOG_DEBUG("Disconnect and close request for HID device:%s", - ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); + log::debug("Disconnect and close request for HID device:{}", + ADDRESS_TO_LOGGABLE_CSTR((*link_spec))); BTA_HhClose(p_dev->dev_handle); } @@ -716,8 +700,7 @@ void btif_hh_setreport(btif_hh_device_t* p_dev, bthh_report_type_t r_type, uint16_t size, uint8_t* report) { BT_HDR* p_buf = create_pbuf(size, report); if (p_buf == NULL) { - LOG_ERROR("%s: Error, failed to allocate RPT buffer, size = %d", __func__, - size); + log::error("Error, failed to allocate RPT buffer, size = {}", size); return; } BTA_HhSetReport(p_dev->dev_handle, r_type, p_buf); @@ -735,8 +718,7 @@ void btif_hh_setreport(btif_hh_device_t* p_dev, bthh_report_type_t r_type, void btif_hh_senddata(btif_hh_device_t* p_dev, uint16_t size, uint8_t* report) { BT_HDR* p_buf = create_pbuf(size, report); if (p_buf == NULL) { - LOG_ERROR("%s: Error, failed to allocate RPT buffer, size = %d", __func__, - size); + log::error("Error, failed to allocate RPT buffer, size = {}", size); return; } p_buf->layer_specific = BTA_HH_RPTT_OUTPUT; @@ -753,9 +735,9 @@ void btif_hh_senddata(btif_hh_device_t* p_dev, uint16_t size, uint8_t* report) { * ******************************************************************************/ void btif_hh_service_registration(bool enable) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); - LOG_VERBOSE("enable = %d", enable); + log::verbose("enable = {}", enable); if (bt_hh_callbacks == NULL) { // The HID Host service was never initialized (it is either disabled or not // available in this build). We should proceed directly to changing the HID @@ -812,22 +794,21 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { int i; int len, tmplen; - LOG_VERBOSE("%s: event=%s dereg = %d", __func__, dump_hh_event(event), - btif_hh_cb.service_dereg_active); + log::verbose("event={} dereg = {}", dump_hh_event(event), + btif_hh_cb.service_dereg_active); switch (event) { case BTA_HH_ENABLE_EVT: - LOG_VERBOSE("%s: BTA_HH_ENABLE_EVT: status =%d", __func__, - p_data->status); + log::verbose("BTA_HH_ENABLE_EVT: status ={}", p_data->status); if (p_data->status == BTA_HH_OK) { btif_hh_cb.status = BTIF_HH_ENABLED; - LOG_VERBOSE("%s--Loading added devices", __func__); + log::verbose("Loading added devices"); /* Add hid descriptors for already bonded hid devices*/ btif_storage_load_bonded_hid_info(); } else { btif_hh_cb.status = BTIF_HH_DISABLED; - LOG_WARN("BTA_HH_ENABLE_EVT: Error, HH enabling failed, status = %d", - p_data->status); + log::warn("BTA_HH_ENABLE_EVT: Error, HH enabling failed, status = {}", + p_data->status); } break; @@ -838,7 +819,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { btif_hh_cb.status = BTIF_HH_DISABLED; if (btif_hh_cb.service_dereg_active) { - LOG_VERBOSE("BTA_HH_DISABLE_EVT: enabling HID Device service"); + log::verbose("BTA_HH_DISABLE_EVT: enabling HID Device service"); btif_hd_service_registration(); btif_hh_cb.service_dereg_active = FALSE; } @@ -853,8 +834,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { btif_hh_cb.devices[i].dev_status = BTHH_CONN_STATE_UNKNOWN; } } else - LOG_WARN("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = %d", - p_data->status); + log::warn("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = {}", + p_data->status); break; case BTA_HH_OPEN_EVT: @@ -862,14 +843,13 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_CLOSE_EVT: - LOG_VERBOSE("BTA_HH_CLOSE_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + log::verbose("BTA_HH_CLOSE_EVT: status = {}, handle = {}", + p_data->dev_status.status, p_data->dev_status.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); if (p_dev != NULL) { HAL_CBACK(bt_hh_callbacks, connection_state_cb, &(p_dev->link_spec.addrt.bda), BTHH_CONN_STATE_DISCONNECTING); - LOG_VERBOSE("%s: uhid fd=%d local_vup=%d", __func__, p_dev->fd, - p_dev->local_vup); + log::verbose("uhid fd={} local_vup={}", p_dev->fd, p_dev->local_vup); btif_hh_stop_vup_timer(&(p_dev->link_spec)); /* If this is a locally initiated VUP, remove the bond as ACL got * disconnected while VUP being processed. @@ -880,8 +860,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { } else if (p_data->dev_status.status == BTA_HH_HS_SERVICE_CHANGED) { /* Local disconnection due to service change in the HOGP device. HID descriptor would be read again, so remove it from cache. */ - LOG_WARN( - "Removing cached descriptor due to service change, handle = %d", + log::warn( + "Removing cached descriptor due to service change, handle = {}", p_data->dev_status.handle); btif_storage_remove_hid_info(p_dev->link_spec.addrt.bda); } @@ -893,14 +873,14 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { HAL_CBACK(bt_hh_callbacks, connection_state_cb, &(p_dev->link_spec.addrt.bda), p_dev->dev_status); } else { - LOG_WARN("Error: cannot find device with handle %d", - p_data->dev_status.handle); + log::warn("Error: cannot find device with handle {}", + p_data->dev_status.handle); } break; case BTA_HH_GET_RPT_EVT: { - LOG_VERBOSE("BTA_HH_GET_RPT_EVT: status = %d, handle = %d", - p_data->hs_data.status, p_data->hs_data.handle); + log::verbose("BTA_HH_GET_RPT_EVT: status = {}, handle = {}", + p_data->hs_data.status, p_data->hs_data.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle); if (p_dev) { BT_HDR* hdr = p_data->hs_data.rsp_data.p_rpt_data; @@ -921,15 +901,15 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { (bthh_status_t)p_data->hs_data.status); } } else { - LOG_WARN("Error: cannot find device with handle %d", - p_data->hs_data.handle); + log::warn("Error: cannot find device with handle {}", + p_data->hs_data.handle); } break; } case BTA_HH_SET_RPT_EVT: - LOG_VERBOSE("BTA_HH_SET_RPT_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + log::verbose("BTA_HH_SET_RPT_EVT: status = {}, handle = {}", + p_data->dev_status.status, p_data->dev_status.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); if (p_dev != NULL) { HAL_CBACK(bt_hh_callbacks, handshake_cb, @@ -943,13 +923,13 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { case BTA_HH_GET_PROTO_EVT: p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle); if (p_dev == NULL) { - LOG_WARN( - "BTA_HH_GET_PROTO_EVT: Error, cannot find device with handle %d", + log::warn( + "BTA_HH_GET_PROTO_EVT: Error, cannot find device with handle {}", p_data->hs_data.handle); return; } - LOG_WARN( - "BTA_HH_GET_PROTO_EVT: status = %d, handle = %d, proto = [%d], %s", + log::warn( + "BTA_HH_GET_PROTO_EVT: status = {}, handle = {}, proto = [{}], {}", p_data->hs_data.status, p_data->hs_data.handle, p_data->hs_data.rsp_data.proto_mode, (p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE) @@ -970,8 +950,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_SET_PROTO_EVT: - LOG_VERBOSE("BTA_HH_SET_PROTO_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + log::verbose("BTA_HH_SET_PROTO_EVT: status = {}, handle = {}", + p_data->dev_status.status, p_data->dev_status.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); if (p_dev) { HAL_CBACK(bt_hh_callbacks, handshake_cb, @@ -981,9 +961,9 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_GET_IDLE_EVT: - LOG_VERBOSE("BTA_HH_GET_IDLE_EVT: handle = %d, status = %d, rate = %d", - p_data->hs_data.handle, p_data->hs_data.status, - p_data->hs_data.rsp_data.idle_rate); + log::verbose("BTA_HH_GET_IDLE_EVT: handle = {}, status = {}, rate = {}", + p_data->hs_data.handle, p_data->hs_data.status, + p_data->hs_data.rsp_data.idle_rate); p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle); if (p_dev) { HAL_CBACK(bt_hh_callbacks, idle_time_cb, @@ -994,23 +974,22 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_SET_IDLE_EVT: - LOG_VERBOSE("BTA_HH_SET_IDLE_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + log::verbose("BTA_HH_SET_IDLE_EVT: status = {}, handle = {}", + p_data->dev_status.status, p_data->dev_status.handle); break; case BTA_HH_GET_DSCP_EVT: len = p_data->dscp_info.descriptor.dl_len; - LOG_VERBOSE("BTA_HH_GET_DSCP_EVT: len = %d", len); + log::verbose("BTA_HH_GET_DSCP_EVT: len = {}", len); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dscp_info.hid_handle); if (p_dev == NULL) { - LOG_ERROR("BTA_HH_GET_DSCP_EVT: No HID device is currently connected"); + log::error("BTA_HH_GET_DSCP_EVT: No HID device is currently connected"); p_data->dscp_info.hid_handle = BTA_HH_INVALID_HANDLE; return; } if (p_dev->fd < 0) { - LOG_ERROR( - + log::error( "BTA_HH_GET_DSCP_EVT: Error, failed to find the uhid driver..."); return; } @@ -1027,7 +1006,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { cached_name = "Bluetooth HID"; } - LOG_WARN("%s: name = %s", __func__, cached_name); + log::warn("name = {}", cached_name); bta_hh_co_send_hid_info(p_dev, cached_name, p_data->dscp_info.vendor_id, p_data->dscp_info.product_id, p_data->dscp_info.version, @@ -1037,8 +1016,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { tBTA_HH_DEV_DSCP_INFO dscp_info; bt_status_t ret; btif_hh_copy_hid_info(&dscp_info, &p_data->dscp_info); - VLOG(1) << "BTA_HH_GET_DSCP_EVT:bda = " - << ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda); + log::verbose("BTA_HH_GET_DSCP_EVT:bda = {}", + ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda)); BTA_HhAddDev(p_dev->link_spec, p_dev->attr_mask, p_dev->sub_class, p_dev->app_id, dscp_info); // write hid info to nvram @@ -1051,7 +1030,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { p_data->dscp_info.descriptor.dsc_list); ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret); - LOG_WARN("BTA_HH_GET_DSCP_EVT: Called add device"); + log::warn("BTA_HH_GET_DSCP_EVT: Called add device"); // Free buffer created for dscp_info; if (dscp_info.descriptor.dl_len > 0 && @@ -1061,7 +1040,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { } } else { // Device already added. - LOG_WARN("%s: Device already added ", __func__); + log::warn("Device already added"); } /*Sync HID Keyboard lockstates */ tmplen = sizeof(hid_kb_numlock_on_list) / sizeof(tHID_KB_LIST); @@ -1070,10 +1049,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { hid_kb_numlock_on_list[i].version_id && p_data->dscp_info.product_id == hid_kb_numlock_on_list[i].product_id) { - LOG_VERBOSE( - "%s() idx[%d] Enabling " - "NUMLOCK for device :: %s", - __func__, i, hid_kb_numlock_on_list[i].kb_name); + log::verbose("idx[{}] Enabling NUMLOCK for device :: {}", i, + hid_kb_numlock_on_list[i].kb_name); /* Enable NUMLOCK by default so that numeric keys work from first keyboard connect */ set_keylockstate(BTIF_HH_KEYSTATE_MASK_NUMLOCK, true); @@ -1086,8 +1063,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_ADD_DEV_EVT: - LOG_WARN("BTA_HH_ADD_DEV_EVT: status = %d, handle = %d", - p_data->dev_info.status, p_data->dev_info.handle); + log::warn("BTA_HH_ADD_DEV_EVT: status = {}, handle = {}", + p_data->dev_info.status, p_data->dev_info.handle); int i; for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) { if (btif_hh_cb.added_devices[i].link_spec.addrt.bda == @@ -1103,27 +1080,29 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { } break; case BTA_HH_RMV_DEV_EVT: - LOG_VERBOSE("BTA_HH_RMV_DEV_EVT: status = %d, handle = %d", - p_data->dev_info.status, p_data->dev_info.handle); - VLOG(1) << "BTA_HH_RMV_DEV_EVT:bda = " - << p_data->dev_info.link_spec.addrt.bda; + log::verbose("BTA_HH_RMV_DEV_EVT: status = {}, handle = {}", + p_data->dev_info.status, p_data->dev_info.handle); + log::verbose( + "BTA_HH_RMV_DEV_EVT:bda = {}", + ADDRESS_TO_LOGGABLE_STR(p_data->dev_info.link_spec.addrt.bda)); break; case BTA_HH_VC_UNPLUG_EVT: - LOG_VERBOSE("BTA_HH_VC_UNPLUG_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + log::verbose("BTA_HH_VC_UNPLUG_EVT: status = {}, handle = {}", + p_data->dev_status.status, p_data->dev_status.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); btif_hh_cb.status = (BTIF_HH_STATUS)BTIF_HH_DEV_DISCONNECTED; if (p_dev != NULL) { - VLOG(1) << "BTA_HH_VC_UNPLUG_EVT:bda = " << p_dev->link_spec.addrt.bda; + log::verbose("BTA_HH_VC_UNPLUG_EVT:bda = {}", + ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda)); /* Stop the VUP timer */ btif_hh_stop_vup_timer(&(p_dev->link_spec)); p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; - LOG_VERBOSE("%s---Sending connection state change", __func__); + log::verbose("--Sending connection state change"); HAL_CBACK(bt_hh_callbacks, connection_state_cb, &(p_dev->link_spec.addrt.bda), p_dev->dev_status); - LOG_VERBOSE("%s---Removing HID bond", __func__); + log::verbose("--Removing HID bond"); /* If it is locally initiated VUP or remote device has its major COD as Peripheral removed the bond.*/ if (p_dev->local_vup || check_cod_hid(&(p_dev->link_spec.addrt.bda))) { @@ -1138,11 +1117,11 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_HH_API_ERR_EVT: - LOG_INFO("BTA_HH API_ERR"); + log::info("BTA_HH API_ERR"); break; default: - LOG_WARN("%s: Unhandled event: %d", __func__, event); + log::warn("Unhandled event: {}", event); break; } } @@ -1164,7 +1143,7 @@ static void btif_hh_hsdata_rpt_copy_cb(uint16_t event, char* p_dest, BT_HDR* hdr; if (!p_src) { - LOG_ERROR("%s: Nothing to copy", __func__); + log::error("Nothing to copy"); return; } @@ -1245,8 +1224,8 @@ static void btif_hh_handle_evt(uint16_t event, char* p_param) { tAclLinkSpec* p_link_spec = (tAclLinkSpec*)p_param; switch (event) { case BTIF_HH_CONNECT_REQ_EVT: { - LOG_DEBUG("Connect request received remote:%s", - ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); + log::debug("Connect request received remote:{}", + ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); if (btif_hh_connect(p_link_spec) == BT_STATUS_SUCCESS) { HAL_CBACK(bt_hh_callbacks, connection_state_cb, &p_link_spec->addrt.bda, BTHH_CONN_STATE_CONNECTING); @@ -1256,25 +1235,25 @@ static void btif_hh_handle_evt(uint16_t event, char* p_param) { } break; case BTIF_HH_DISCONNECT_REQ_EVT: { - LOG_DEBUG("Disconnect request received remote:%s", - ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); + log::debug("Disconnect request received remote:{}", + ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); btif_hh_disconnect(p_link_spec); HAL_CBACK(bt_hh_callbacks, connection_state_cb, &p_link_spec->addrt.bda, BTHH_CONN_STATE_DISCONNECTING); } break; case BTIF_HH_VUP_REQ_EVT: { - LOG_DEBUG("Virtual unplug request received remote:%s", - ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); - if (btif_hh_virtual_unplug(p_link_spec) != BT_STATUS_SUCCESS) { - LOG_WARN("Unable to virtual unplug device remote:%s", + log::debug("Virtual unplug request received remote:{}", ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); + if (btif_hh_virtual_unplug(p_link_spec) != BT_STATUS_SUCCESS) { + log::warn("Unable to virtual unplug device remote:{}", + ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); } } break; default: { - LOG_WARN("Unknown event received:%d remote:%s", event, - ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); + log::warn("Unknown event received:{} remote:{}", event, + ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec))); } break; } } @@ -1293,7 +1272,7 @@ void btif_hh_timer_timeout(void* data) { tBTA_HH p_data; int param_len = sizeof(tBTA_HH_CBDATA); - LOG_VERBOSE("%s", __func__); + log::verbose(""); if (p_dev->dev_status != BTHH_CONN_STATE_CONNECTED) return; memset(&p_data, 0, sizeof(tBTA_HH)); @@ -1316,7 +1295,7 @@ void btif_hh_timer_timeout(void* data) { ******************************************************************************/ static bt_status_t init(bthh_callbacks_t* callbacks) { uint32_t i; - LOG_VERBOSE("%s", __func__); + log::verbose(""); bt_hh_callbacks = callbacks; memset(&btif_hh_cb, 0, sizeof(btif_hh_cb)); @@ -1343,11 +1322,11 @@ static bt_status_t connect(RawAddress* bd_addr) { tAclLinkSpec link_spec; if (btif_hh_cb.status == BTIF_HH_DEV_CONNECTING) { - LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::warn("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_BUSY; } else if (btif_hh_cb.status == BTIF_HH_DISABLED || btif_hh_cb.status == BTIF_HH_DISABLING) { - LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::warn("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_NOT_READY; } link_spec.addrt.bda = *bd_addr; @@ -1359,12 +1338,12 @@ static bt_status_t connect(RawAddress* bd_addr) { if (p_dev) { if (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED || p_dev->dev_status == BTHH_CONN_STATE_CONNECTING) { - LOG_ERROR("%s: Error, device %s already connected.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} already connected.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_DONE; } else if (p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTING) { - LOG_ERROR("%s: Error, device %s is busy with (dis)connecting.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} is busy with (dis)connecting.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_BUSY; } } @@ -1384,13 +1363,13 @@ static bt_status_t connect(RawAddress* bd_addr) { ******************************************************************************/ static bt_status_t disconnect(RawAddress* bd_addr) { CHECK_BTHH_INIT(); - LOG_VERBOSE("BTHH: %s", __func__); + log::verbose("BTHH"); btif_hh_device_t* p_dev; tAclLinkSpec link_spec; if (btif_hh_cb.status == BTIF_HH_DISABLED || btif_hh_cb.status == BTIF_HH_DISABLING) { - LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::warn("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_UNHANDLED; } link_spec.addrt.bda = *bd_addr; @@ -1400,19 +1379,19 @@ static bt_status_t disconnect(RawAddress* bd_addr) { p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (!p_dev) { - LOG_ERROR("%s: Error, device %s not opened.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} not opened.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_UNHANDLED; } if (p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTED || p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTING) { - LOG_ERROR("%s: Error, device %s already disconnected.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} already disconnected.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_DONE; } else if (p_dev->dev_status == BTHH_CONN_STATE_CONNECTING) { - LOG_ERROR("%s: Error, device %s is busy with (dis)connecting.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} is busy with (dis)connecting.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_BUSY; } @@ -1431,11 +1410,11 @@ static bt_status_t disconnect(RawAddress* bd_addr) { ******************************************************************************/ static bt_status_t virtual_unplug(RawAddress* bd_addr) { CHECK_BTHH_INIT(); - LOG_VERBOSE("BTHH: %s", __func__); + log::verbose("BTHH"); btif_hh_device_t* p_dev; tAclLinkSpec link_spec; if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1445,8 +1424,8 @@ static bt_status_t virtual_unplug(RawAddress* bd_addr) { p_dev = btif_hh_find_dev_by_bda(link_spec); if (!p_dev) { - LOG_ERROR("%s: Error, device %s not opened.", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("Error, device {} not opened.", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } btif_transfer_context(btif_hh_handle_evt, BTIF_HH_VUP_REQ_EVT, @@ -1467,10 +1446,10 @@ static bt_status_t get_idle_time(RawAddress* bd_addr) { CHECK_BTHH_INIT(); tAclLinkSpec link_spec; - LOG_VERBOSE("%s: addr = %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::verbose("addr = {}", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1498,11 +1477,11 @@ static bt_status_t set_idle_time(RawAddress* bd_addr, uint8_t idle_time) { CHECK_BTHH_INIT(); tAclLinkSpec link_spec; - LOG_VERBOSE("%s: addr = %s, idle time = %d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), idle_time); + log::verbose("addr = {}, idle time = {}", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), + idle_time); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1512,8 +1491,7 @@ static bt_status_t set_idle_time(RawAddress* bd_addr, uint8_t idle_time) { btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG_WARN("%s: addr = %s not opened", __func__, - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::warn("addr = {} not opened", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } @@ -1535,15 +1513,15 @@ static bt_status_t set_info(RawAddress* bd_addr, bthh_hid_info_t hid_info) { tBTA_HH_DEV_DSCP_INFO dscp_info; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: addr = " << *bd_addr; - LOG_VERBOSE( - "BTHH: %s: sub_class = 0x%02x, app_id = %d, vendor_id = 0x%04x, " - "product_id = 0x%04x, version= 0x%04x", - __func__, hid_info.sub_class, hid_info.app_id, hid_info.vendor_id, + log::verbose("BTHH: addr = {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); + log::verbose( + "BTHH: sub_class = 0x{:02x}, app_id = {}, vendor_id = 0x{:04x}, " + "product_id = 0x{:04x}, version= 0x{:04x}", + hid_info.sub_class, hid_info.app_id, hid_info.vendor_id, hid_info.product_id, hid_info.version); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } @@ -1587,10 +1565,10 @@ static bt_status_t get_protocol(RawAddress* bd_addr, CHECK_BTHH_INIT(); tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: addr = " << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::verbose("BTHH: addr = {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1621,11 +1599,11 @@ static bt_status_t set_protocol(RawAddress* bd_addr, uint8_t proto_mode = protocolMode; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: proto_mod=" << protocolMode - << " addr = " << *bd_addr; + log::verbose("BTHH: proto_mod={} addr = {}", protocolMode, + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1635,11 +1613,11 @@ static bt_status_t set_protocol(RawAddress* bd_addr, p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(WARNING) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened"; + log::warn("Error, device {} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_FAIL; } else if (protocolMode != BTA_HH_PROTO_RPT_MODE && protocolMode != BTA_HH_PROTO_BOOT_MODE) { - LOG_WARN("%s: Error, device proto_mode = %d.", __func__, proto_mode); + log::warn("Error, device proto_mode = {}.", proto_mode); return BT_STATUS_FAIL; } else { BTA_HhSetProtoMode(p_dev->dev_handle, protocolMode); @@ -1664,12 +1642,12 @@ static bt_status_t get_report(RawAddress* bd_addr, btif_hh_device_t* p_dev; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: r_type = " << reportType - << ", rpt_id = " << reportId << ", buf_size = " << bufferSize - << " addr = " << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::verbose("BTHH: r_type = {}, rpt_id = {}, buf_size = {} addr = {}", + reportType, reportId, bufferSize, + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1679,11 +1657,12 @@ static bt_status_t get_report(RawAddress* bd_addr, p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened"; + log::error("Error, device {} not opened", + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_FAIL; } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) { - LOG(ERROR) << " Error, report type=" << +reportType << " not supported"; + log::error("Error, report type={} not supported", reportType); return BT_STATUS_FAIL; } else { BTA_HhGetReport(p_dev->dev_handle, reportType, reportId, bufferSize); @@ -1707,10 +1686,10 @@ static bt_status_t get_report_reply(RawAddress* bd_addr, bthh_status_t status, btif_hh_device_t* p_dev; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::verbose("BTHH: addr={}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1720,7 +1699,8 @@ static bt_status_t get_report_reply(RawAddress* bd_addr, bthh_status_t status, p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened"; + log::error("Error, device {} not opened", + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_FAIL; } @@ -1744,11 +1724,11 @@ static bt_status_t set_report(RawAddress* bd_addr, btif_hh_device_t* p_dev; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " BTHH: reportType=" << reportType - << " addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::verbose("BTHH: reportType={} addr={}", reportType, + ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1758,11 +1738,11 @@ static bt_status_t set_report(RawAddress* bd_addr, p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened"; + log::error("Error, device{} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_FAIL; } else if (((int)reportType) <= BTA_HH_RPTT_RESRV || ((int)reportType) > BTA_HH_RPTT_FEATURE) { - LOG(ERROR) << " Error, report type=" << +reportType << " not supported"; + log::error("Error, report type={} not supported", reportType); return BT_STATUS_FAIL; } else { int hex_bytes_filled; @@ -1772,12 +1752,12 @@ static bt_status_t set_report(RawAddress* bd_addr, /* Build a SetReport data buffer */ // TODO hex_bytes_filled = ascii_2_hex(report, len, hexbuf); - LOG_INFO("Hex bytes filled, hex value: %d", hex_bytes_filled); + log::info("Hex bytes filled, hex value: {}", hex_bytes_filled); if (hex_bytes_filled) { BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf); if (p_buf == NULL) { - LOG_ERROR("%s: Error, failed to allocate RPT buffer, len = %d", - __func__, hex_bytes_filled); + log::error("Error, failed to allocate RPT buffer, len = {}", + hex_bytes_filled); osi_free(hexbuf); return BT_STATUS_FAIL; } @@ -1804,10 +1784,10 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) { btif_hh_device_t* p_dev; tAclLinkSpec link_spec; - VLOG(1) << __func__ << " addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr); + log::verbose("addr={}", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); if (btif_hh_cb.status == BTIF_HH_DISABLED) { - LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status); + log::error("Error, HH status = {}", btif_hh_cb.status); return BT_STATUS_FAIL; } link_spec.addrt.bda = *bd_addr; @@ -1817,8 +1797,7 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) { p_dev = btif_hh_find_connected_dev_by_bda(link_spec); if (p_dev == NULL) { - LOG(ERROR) << " Error, device" - << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened"; + log::error("Error, device{} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr)); return BT_STATUS_FAIL; } @@ -1829,13 +1808,13 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) { /* Build a SendData data buffer */ hex_bytes_filled = ascii_2_hex(data, len, hexbuf); - LOG_ERROR("Hex bytes filled, hex value: %d, %zu", hex_bytes_filled, len); + log::error("Hex bytes filled, hex value: {}, {}", hex_bytes_filled, len); if (hex_bytes_filled) { BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf); if (p_buf == NULL) { - LOG_ERROR("%s: Error, failed to allocate RPT buffer, len = %d", - __func__, hex_bytes_filled); + log::error("Error, failed to allocate RPT buffer, len = {}", + hex_bytes_filled); osi_free(hexbuf); return BT_STATUS_FAIL; } @@ -1859,13 +1838,13 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) { * ******************************************************************************/ static void cleanup(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_hh_device_t* p_dev; int i; if (btif_hh_cb.status == BTIF_HH_DISABLED || btif_hh_cb.status == BTIF_HH_DISABLING) { - LOG_WARN("%s: HH disabling or disabled already, status = %d", __func__, - btif_hh_cb.status); + log::warn("HH disabling or disabled already, status = {}", + btif_hh_cb.status); return; } if (bt_hh_callbacks) { @@ -1878,7 +1857,7 @@ static void cleanup(void) { for (i = 0; i < BTIF_HH_MAX_HID; i++) { p_dev = &btif_hh_cb.devices[i]; if (p_dev->dev_status != BTHH_CONN_STATE_UNKNOWN && p_dev->fd >= 0) { - LOG_VERBOSE("%s: Closing uhid fd = %d", __func__, p_dev->fd); + log::verbose("Closing uhid fd = {}", p_dev->fd); bta_hh_co_close(p_dev); } } @@ -1949,7 +1928,7 @@ bt_status_t btif_hh_execute_service(bool b_enable) { * ******************************************************************************/ const bthh_interface_t* btif_hh_get_interface() { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &bthhInterface; } diff --git a/system/btif/src/btif_iot_config.cc b/system/btif/src/btif_iot_config.cc index 967df79eadd..59b513f0132 100644 --- a/system/btif/src/btif_iot_config.cc +++ b/system/btif/src/btif_iot_config.cc @@ -16,6 +16,8 @@ * ******************************************************************************/ +#include <bluetooth/log.h> + #include "bta_sec_api.h" #include "btif_storage.h" #include "device/include/device_iot_config.h" @@ -23,6 +25,8 @@ #include "os/log.h" #include "stack/include/btm_ble_api.h" +using namespace bluetooth; + /******************************************************************************* * Constants & Macros ******************************************************************************/ @@ -100,9 +104,9 @@ void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble, if (btif_storage_get_remote_device_property(&p_auth_cmpl->bd_addr, &properties[num_properties]) == BT_STATUS_SUCCESS) - LOG_VERBOSE("%s cod retrieved from storage is 0x%06x", __func__, cod); + log::verbose("cod retrieved from storage is 0x{:06x}", cod); if (cod == 0) { - LOG_VERBOSE("%s cod is 0, set as unclassified", __func__); + log::verbose("cod is 0, set as unclassified"); cod = COD_UNCLASSIFIED; } DEVICE_IOT_CONFIG_ADDR_SET_INT(p_auth_cmpl->bd_addr, IOT_CONF_KEY_DEVCLASS, @@ -118,7 +122,7 @@ void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble, if (btif_storage_get_remote_device_property(&p_auth_cmpl->bd_addr, &properties[num_properties]) == BT_STATUS_SUCCESS) { - LOG_VERBOSE("%s retrieve dev type from storage", __func__); + log::verbose("retrieve dev type from storage"); dev_type = (bt_device_type_t)(remote_dev_type | p_auth_cmpl->dev_type); } else { dev_type = (bt_device_type_t)(p_auth_cmpl->dev_type); diff --git a/system/btif/src/btif_jni_task.cc b/system/btif/src/btif_jni_task.cc index 5a542530556..083515c8723 100644 --- a/system/btif/src/btif_jni_task.cc +++ b/system/btif/src/btif_jni_task.cc @@ -20,6 +20,7 @@ #include <base/location.h> #include <base/logging.h> #include <base/threading/platform_thread.h> +#include <bluetooth/log.h> #include <cstdint> #include <utility> @@ -30,6 +31,7 @@ #include "stack/include/bt_types.h" using base::PlatformThread; +using namespace bluetooth; static bluetooth::common::MessageLoopThread jni_thread("bt_jni_thread"); @@ -76,7 +78,7 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event, tBTIF_CONTEXT_SWITCH_CBACK* p_msg = (tBTIF_CONTEXT_SWITCH_CBACK*)osi_malloc( sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len); - LOG_VERBOSE("btif_transfer_context event %d, len %d", event, param_len); + log::verbose("btif_transfer_context event {}, len {}", event, param_len); /* allocate and send message that will be executed in btif context */ p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */ @@ -101,7 +103,7 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event, bt_status_t do_in_jni_thread(const base::Location& from_here, base::OnceClosure task) { if (!jni_thread.DoInThread(from_here, std::move(task))) { - LOG(ERROR) << __func__ << ": Post task to task runner failed!"; + log::error("Post task to task runner failed!"); return BT_STATUS_FAIL; } return BT_STATUS_SUCCESS; diff --git a/system/btif/src/btif_keystore.cc b/system/btif/src/btif_keystore.cc index 8125f0a107c..734fb3d8f8d 100644 --- a/system/btif/src/btif_keystore.cc +++ b/system/btif/src/btif_keystore.cc @@ -21,6 +21,7 @@ #include <base/functional/bind.h> #include <base/location.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <map> @@ -47,7 +48,7 @@ class BluetoothKeystoreInterfaceImpl ~BluetoothKeystoreInterfaceImpl() override = default; void init(BluetoothKeystoreCallbacks* callbacks) override { - VLOG(2) << __func__; + log::verbose(""); this->callbacks = callbacks; bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult( @@ -56,9 +57,9 @@ class BluetoothKeystoreInterfaceImpl } void ConvertEncryptOrDecryptKeyIfNeeded() { - VLOG(2) << __func__; + log::verbose(""); if (!callbacks) { - LOG(INFO) << __func__ << " callback isn't ready."; + log::info("callback isn't ready."); return; } do_in_jni_thread( @@ -69,10 +70,10 @@ class BluetoothKeystoreInterfaceImpl bool set_encrypt_key_or_remove_key(std::string prefix, std::string decryptedString) override { - VLOG(2) << __func__ << " prefix: " << prefix; + log::verbose("prefix: {}", prefix); if (!callbacks) { - LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; + log::warn("callback isn't ready. prefix: {}", prefix); return false; } @@ -87,10 +88,10 @@ class BluetoothKeystoreInterfaceImpl } std::string get_key(std::string prefix) override { - VLOG(2) << __func__ << " prefix: " << prefix; + log::verbose("prefix: {}", prefix); if (!callbacks) { - LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; + log::warn("callback isn't ready. prefix: {}", prefix); return ""; } @@ -101,7 +102,7 @@ class BluetoothKeystoreInterfaceImpl decryptedString = callbacks->get_key(prefix); // Save the value into a map. key_map[prefix] = decryptedString; - VLOG(2) << __func__ << ": get key from bluetoothkeystore."; + log::verbose("get key from bluetoothkeystore."); } else { decryptedString = iter->second; } @@ -109,7 +110,7 @@ class BluetoothKeystoreInterfaceImpl } void clear_map() override { - VLOG(2) << __func__; + log::verbose(""); std::map<std::string, std::string> empty_map; key_map.swap(empty_map); diff --git a/system/btif/src/btif_le_audio.cc b/system/btif/src/btif_le_audio.cc index 40138606d77..65760220f28 100644 --- a/system/btif/src/btif_le_audio.cc +++ b/system/btif/src/btif_le_audio.cc @@ -16,6 +16,7 @@ */ #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_le_audio.h> @@ -36,6 +37,7 @@ using bluetooth::le_audio::GroupStreamStatus; using bluetooth::le_audio::LeAudioClientCallbacks; using bluetooth::le_audio::LeAudioClientInterface; using bluetooth::le_audio::UnicastMonitorModeStatus; +using namespace bluetooth; namespace { class LeAudioClientInterfaceImpl; @@ -154,7 +156,7 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, this->callbacks = callbacks; for (auto codec : offloading_preference) { - LOG_INFO("supported codec: %s", codec.ToString().c_str()); + log::info("supported codec: {}", codec.ToString()); } do_in_main_thread( @@ -174,9 +176,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void Cleanup(void) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -187,9 +189,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void RemoveDevice(const RawAddress& address) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); do_in_jni_thread(FROM_HERE, Bind(&btif_storage_remove_leaudio, address)); return; @@ -204,9 +206,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void Connect(const RawAddress& address) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -217,9 +219,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void Disconnect(const RawAddress& address) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -230,9 +232,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void SetEnableState(const RawAddress& address, bool enabled) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -243,9 +245,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void GroupAddNode(const int group_id, const RawAddress& address) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -256,9 +258,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void GroupRemoveNode(const int group_id, const RawAddress& address) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -269,9 +271,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void GroupSetActive(const int group_id) override { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -284,9 +286,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, btle_audio_codec_config_t input_codec_config, btle_audio_codec_config_t output_codec_config) { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } do_in_main_thread(FROM_HERE, @@ -297,9 +299,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void SetCcidInformation(int ccid, int context_type) { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -310,9 +312,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, void SetInCall(bool in_call) { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -339,9 +341,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface, bool is_output_preference_le_audio, bool is_duplex_preference_le_audio) { if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } diff --git a/system/btif/src/btif_pan.cc b/system/btif/src/btif_pan.cc index 7ed00ae2f8f..b69d8867860 100644 --- a/system/btif/src/btif_pan.cc +++ b/system/btif/src/btif_pan.cc @@ -31,6 +31,7 @@ #include <arpa/inet.h> #include <base/functional/bind.h> #include <base/location.h> +#include <bluetooth/log.h> #include <fcntl.h> #include <linux/if_ether.h> #include <linux/if_tun.h> @@ -64,15 +65,15 @@ #define FORWARD_FAILURE (-1) #define FORWARD_CONGEST (-2) -#define asrt(s) \ - do { \ - if (!(s)) \ - LOG_ERROR("btif_pan: ## %s assert %s failed at line:%d ##", __func__, \ - #s, __LINE__); \ +#define asrt(s) \ + do { \ + if (!(s)) log::error("btif_pan: ## assert {} failed ##", #s); \ } while (0) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) +using namespace bluetooth; + btpan_cb_t btpan_cb; static bool jni_initialized; @@ -108,12 +109,12 @@ const btpan_interface_t* btif_pan_get_interface() { return &pan_if; } ** ******************************************************************************/ void btif_pan_init() { - LOG_VERBOSE("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized, - btpan_cb.enabled); + log::verbose("jni_initialized = {}, btpan_cb.enabled:{}", jni_initialized, + btpan_cb.enabled); stack_initialized = true; if (jni_initialized && !btpan_cb.enabled) { - LOG_VERBOSE("Enabling PAN...."); + log::verbose("Enabling PAN...."); memset(&btpan_cb, 0, sizeof(btpan_cb)); btpan_cb.tap_fd = INVALID_FD; btpan_cb.flow = 1; @@ -158,8 +159,8 @@ void btif_pan_cleanup() { static btpan_callbacks_t callback; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) { - LOG_VERBOSE("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, - btpan_cb.enabled); + log::verbose("stack_initialized = {}, btpan_cb.enabled:{}", stack_initialized, + btpan_cb.enabled); callback = *callbacks; jni_initialized = true; if (stack_initialized && !btpan_cb.enabled) btif_pan_init(); @@ -212,7 +213,7 @@ static bt_status_t btpan_connect(const RawAddress* bd_addr, int local_role, constexpr uint16_t BTIF_PAN_CB_DISCONNECTING = 0x8401; static void btif_in_pan_generic_evt(uint16_t event, char* p_param) { - LOG_VERBOSE("%s: event=%d", __func__, event); + log::verbose("event={}", event); switch (event) { case BTIF_PAN_CB_DISCONNECTING: { RawAddress* bd_addr = (RawAddress*)p_param; @@ -229,7 +230,7 @@ static void btif_in_pan_generic_evt(uint16_t event, char* p_param) { } } break; default: { - LOG_WARN("%s : Unknown event 0x%x", __func__, event); + log::warn("Unknown event 0x{:x}", event); } break; } } @@ -273,8 +274,8 @@ static int tap_if_up(const char* devname, const RawAddress* addr) { strlcpy(ifr.ifr_name, devname, IFNAMSIZ); err = ioctl(sk, SIOCGIFHWADDR, &ifr); if (err < 0) { - LOG_ERROR("Could not get network hardware for interface:%s, errno:%s", - devname, strerror(errno)); + log::error("Could not get network hardware for interface:{}, errno:{}", + devname, strerror(errno)); close(sk); return -1; } @@ -291,15 +292,15 @@ static int tap_if_up(const char* devname, const RawAddress* addr) { * Mask this bit to avoid any issue with auto generated address. */ if (ifr.ifr_hwaddr.sa_data[0] & 0x01) { - LOG_WARN("Not a unicast MAC address, force multicast bit flipping"); + log::warn("Not a unicast MAC address, force multicast bit flipping"); ifr.ifr_hwaddr.sa_data[0] &= ~0x01; } err = ioctl(sk, SIOCSIFHWADDR, (caddr_t)&ifr); if (err < 0) { - LOG_ERROR("Could not set bt address for interface:%s, errno:%s", devname, - strerror(errno)); + log::error("Could not set bt address for interface:{}, errno:{}", devname, + strerror(errno)); close(sk); return -1; } @@ -314,13 +315,13 @@ static int tap_if_up(const char* devname, const RawAddress* addr) { err = ioctl(sk, SIOCSIFFLAGS, (caddr_t)&ifr); if (err < 0) { - LOG_ERROR("Could not bring up network interface:%s, errno:%d", devname, - errno); + log::error("Could not bring up network interface:{}, errno:{}", devname, + errno); close(sk); return -1; } close(sk); - LOG_VERBOSE("network interface: %s is up", devname); + log::verbose("network interface: {} is up", devname); return 0; } @@ -363,7 +364,7 @@ int btpan_tap_open() { fd = open(clonedev, O_RDWR); if (fd < 0) { - LOG_VERBOSE("could not open %s, err:%d", clonedev, errno); + log::verbose("could not open {}, err:{}", clonedev, errno); return fd; } @@ -375,7 +376,7 @@ int btpan_tap_open() { /* try to create the device */ err = ioctl(fd, TUNSETIFF, (void*)&ifr); if (err < 0) { - LOG_VERBOSE("ioctl error:%d, errno:%s", err, strerror(errno)); + log::verbose("ioctl error:{}, errno:{}", err, strerror(errno)); close(fd); return err; } @@ -384,7 +385,7 @@ int btpan_tap_open() { fcntl(fd, F_SETFL, flags | O_NONBLOCK); return fd; } - LOG_ERROR("can not bring up tap interface:%s", TAP_IF_NAME); + log::error("can not bring up tap interface:{}", TAP_IF_NAME); close(fd); return INVALID_FD; } @@ -400,7 +401,7 @@ int btpan_tap_send(int tap_fd, const RawAddress& src, const RawAddress& dst, char packet[TAP_MAX_PKT_WRITE_LEN + sizeof(tETH_HDR)]; memcpy(packet, ð_hdr, sizeof(tETH_HDR)); if (len > TAP_MAX_PKT_WRITE_LEN) { - LOG_ERROR("btpan_tap_send eth packet size:%d is exceeded limit!", len); + log::error("btpan_tap_send eth packet size:{} is exceeded limit!", len); return -1; } memcpy(packet + sizeof(tETH_HDR), buf, len); @@ -408,7 +409,7 @@ int btpan_tap_send(int tap_fd, const RawAddress& src, const RawAddress& dst, /* Send data to network interface */ ssize_t ret; OSI_NO_INTR(ret = write(tap_fd, packet, len + sizeof(tETH_HDR))); - LOG_VERBOSE("ret:%zd", ret); + log::verbose("ret:{}", ret); return (int)ret; } return -1; @@ -435,18 +436,18 @@ btpan_conn_t* btpan_find_conn_addr(const RawAddress& addr) { } static void btpan_open_conn(btpan_conn_t* conn, tBTA_PAN* p_data) { - LOG_VERBOSE( - "btpan_open_conn: local_role:%d, peer_role: %d, handle:%d, conn: %p", + log::verbose( + "btpan_open_conn: local_role:{}, peer_role: {}, handle:{}, conn: {}", p_data->open.local_role, p_data->open.peer_role, p_data->open.handle, - conn); + fmt::ptr(conn)); if (conn == NULL) conn = btpan_new_conn(p_data->open.handle, p_data->open.bd_addr, p_data->open.local_role, p_data->open.peer_role); if (conn) { - LOG_VERBOSE( - "btpan_open_conn:tap_fd:%d, open_count:%d, " - "conn->handle:%d should = handle:%d, local_role:%d, remote_role:%d", + log::verbose( + "btpan_open_conn:tap_fd:{}, open_count:{}, conn->handle:{} should = " + "handle:{}, local_role:{}, remote_role:{}", btpan_cb.tap_fd, btpan_cb.open_count, conn->handle, p_data->open.handle, conn->local_role, conn->remote_role); @@ -465,10 +466,10 @@ static void btpan_open_conn(btpan_conn_t* conn, tBTA_PAN* p_data) { } static void btpan_close_conn(btpan_conn_t* conn) { - LOG_VERBOSE("btpan_close_conn: %p", conn); + log::verbose("btpan_close_conn: {}", fmt::ptr(conn)); if (conn && conn->state == PAN_STATE_OPEN) { - LOG_VERBOSE("btpan_close_conn: PAN_STATE_OPEN"); + log::verbose("btpan_close_conn: PAN_STATE_OPEN"); conn->state = PAN_STATE_CLOSE; btpan_cb.open_count--; @@ -498,9 +499,8 @@ btpan_conn_t* btpan_new_conn(int handle, const RawAddress& addr, tBTA_PAN_ROLE remote_role) { for (int i = 0; i < MAX_PAN_CONNS; i++) { if (btpan_cb.conns[i].handle == -1) { - LOG_DEBUG( - "Allocated new pan connection handle:%d local_role:%hhu" - " remote_role:%hhu", + log::debug( + "Allocated new pan connection handle:{} local_role:{} remote_role:{}", handle, local_role, remote_role); btpan_cb.conns[i].handle = handle; btpan_cb.conns[i].peer = addr; @@ -509,12 +509,12 @@ btpan_conn_t* btpan_new_conn(int handle, const RawAddress& addr, return &btpan_cb.conns[i]; } } - LOG_WARN("Unable to create new pan connection max:%d", MAX_PAN_CONNS); + log::warn("Unable to create new pan connection max:{}", MAX_PAN_CONNS); return nullptr; } void btpan_close_handle(btpan_conn_t* p) { - LOG_VERBOSE("btpan_close_handle : close handle %d", p->handle); + log::verbose("btpan_close_handle : close handle {}", p->handle); p->handle = -1; p->local_role = -1; p->remote_role = -1; @@ -525,7 +525,7 @@ static inline bool should_forward(tETH_HDR* hdr) { uint16_t proto = ntohs(hdr->h_proto); if (proto == ETH_P_IP || proto == ETH_P_ARP || proto == ETH_P_IPV6) return true; - LOG_VERBOSE("unknown proto:%x", proto); + log::verbose("unknown proto:{:x}", proto); return false; } @@ -559,7 +559,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { switch (event) { case BTA_PAN_ENABLE_EVT: - LOG_VERBOSE("BTA_PAN_ENABLE_EVT"); + log::verbose("BTA_PAN_ENABLE_EVT"); break; case BTA_PAN_SET_ROLE_EVT: { int btpan_role = bta_role_to_btpan(p_data->set_role.role); @@ -572,9 +572,9 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { } case BTA_PAN_OPENING_EVT: { btpan_conn_t* conn; - LOG_VERBOSE("BTA_PAN_OPENING_EVT handle %d, addr: %s", - p_data->opening.handle, - ADDRESS_TO_LOGGABLE_CSTR(p_data->opening.bd_addr)); + log::verbose("BTA_PAN_OPENING_EVT handle {}, addr: {}", + p_data->opening.handle, + ADDRESS_TO_LOGGABLE_CSTR(p_data->opening.bd_addr)); conn = btpan_find_conn_addr(p_data->opening.bd_addr); asrt(conn != NULL); @@ -586,7 +586,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { &p_data->opening.bd_addr, btpan_conn_local_role, btpan_remote_role); } else - LOG_ERROR("connection not found"); + log::error("connection not found"); break; } case BTA_PAN_OPEN_EVT: { @@ -594,8 +594,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { bt_status_t status; btpan_conn_t* conn = btpan_find_conn_handle(p_data->open.handle); - LOG_VERBOSE("%s pan connection open status: %d", __func__, - p_data->open.status); + log::verbose("pan connection open status: {}", p_data->open.status); if (p_data->open.status) { state = BTPAN_STATE_CONNECTED; status = BT_STATUS_SUCCESS; @@ -616,8 +615,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { break; } case BTA_PAN_CLOSE_EVT: { - LOG_INFO("%s: event = BTA_PAN_CLOSE_EVT handle %d", __func__, - p_data->close.handle); + log::info("event = BTA_PAN_CLOSE_EVT handle {}", p_data->close.handle); btpan_conn_t* conn = btpan_find_conn_handle(p_data->close.handle); btpan_close_conn(conn); @@ -629,11 +627,11 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) { btpan_remote_role); btpan_cleanup_conn(conn); } else - LOG_ERROR("pan handle not found (%d)", p_data->close.handle); + log::error("pan handle not found ({})", p_data->close.handle); break; } default: - LOG_WARN("Unknown pan event %d", event); + log::warn("Unknown pan event {}", event); break; } } @@ -670,14 +668,13 @@ static void btu_exec_tap_fd_read(int fd) { sizeof(btpan_cb.congest_packet))); switch (ret) { case -1: - LOG_ERROR("%s unable to read from driver: %s", __func__, - strerror(errno)); + log::error("unable to read from driver: {}", strerror(errno)); osi_free(buffer); // add fd back to monitor thread to try it again later btsock_thread_add_fd(pan_pth, fd, 0, SOCK_THREAD_FD_RD, 0); return; case 0: - LOG_WARN("%s end of file reached.", __func__); + log::warn("end of file reached."); osi_free(buffer); // add fd back to monitor thread to process the exception btsock_thread_add_fd(pan_pth, fd, 0, SOCK_THREAD_FD_RD, 0); @@ -706,7 +703,7 @@ static void btu_exec_tap_fd_read(int fd) { if (forward_bnep(&hdr, buffer) != FORWARD_CONGEST) btpan_cb.congest_packet_size = 0; } else { - LOG_WARN("%s dropping packet of length %d", __func__, buffer->len); + log::warn("dropping packet of length {}", buffer->len); btpan_cb.congest_packet_size = 0; osi_free(buffer); } @@ -740,8 +737,7 @@ static void btpan_tap_fd_signaled(int fd, int type, int flags, CHECK(btpan_cb.tap_fd == INVALID_FD || btpan_cb.tap_fd == fd); if (btpan_cb.tap_fd != fd) { - LOG_WARN("%s Signaled on mismatched fds exp:%d act:%d\n", __func__, - btpan_cb.tap_fd, fd); + log::warn("Signaled on mismatched fds exp:{} act:{}", btpan_cb.tap_fd, fd); return; } diff --git a/system/btif/src/btif_profile_queue.cc b/system/btif/src/btif_profile_queue.cc index 658bda62431..74788c22642 100644 --- a/system/btif/src/btif_profile_queue.cc +++ b/system/btif/src/btif_profile_queue.cc @@ -32,6 +32,7 @@ #include <base/functional/callback.h> #include <base/logging.h> #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <string.h> #include <list> @@ -41,6 +42,8 @@ #include "include/check.h" #include "types/raw_address.h" +using namespace bluetooth; + /******************************************************************************* * Local type definitions ******************************************************************************/ @@ -101,13 +104,13 @@ static void queue_int_add(uint16_t uuid, const RawAddress& bda, ConnectNode param(bda, uuid, connect_cb); for (const auto& node : connect_queue) { if (node.uuid() == param.uuid() && node.address() == param.address()) { - LOG_ERROR("Dropping duplicate profile connection request:%s", - param.ToString().c_str()); + log::error("Dropping duplicate profile connection request:{}", + param.ToString()); return; } } - LOG_INFO("Queueing profile connection request:%s", param.ToString().c_str()); + log::info("Queueing profile connection request:{}", param.ToString()); connect_queue.push_back(param); btif_queue_connect_next(); @@ -117,22 +120,20 @@ static void queue_int_advance() { if (connect_queue.empty()) return; const ConnectNode& head = connect_queue.front(); - LOG_INFO("%s: removing connection request: %s", __func__, - head.ToString().c_str()); + log::info("removing connection request: {}", head.ToString()); connect_queue.pop_front(); btif_queue_connect_next(); } static void queue_int_cleanup(uint16_t uuid) { - LOG_INFO("%s: UUID=%04X", __func__, uuid); + log::info("UUID={:04X}", uuid); for (auto it = connect_queue.begin(); it != connect_queue.end();) { auto it_prev = it++; const ConnectNode& node = *it_prev; if (node.uuid() == uuid) { - LOG_INFO("%s: removing connection request: %s", __func__, - node.ToString().c_str()); + log::info("removing connection request: {}", node.ToString()); connect_queue.erase(it_prev); } } @@ -194,11 +195,11 @@ bt_status_t btif_queue_connect_next(void) { ConnectNode& head = connect_queue.front(); - LOG_INFO("Executing profile connection request:%s", head.ToString().c_str()); + log::info("Executing profile connection request:{}", head.ToString()); bt_status_t b_status = head.connect(); if (b_status != BT_STATUS_SUCCESS) { - LOG_INFO("%s: connect %s failed, advance to next scheduled connection.", - __func__, head.ToString().c_str()); + log::info("connect {} failed, advance to next scheduled connection.", + head.ToString()); btif_queue_advance(); } return b_status; @@ -214,9 +215,9 @@ bt_status_t btif_queue_connect_next(void) { * ******************************************************************************/ void btif_queue_release() { - LOG_INFO("%s", __func__); + log::info(""); if (do_in_jni_thread(FROM_HERE, base::BindOnce(&queue_int_release)) != BT_STATUS_SUCCESS) { - LOG(FATAL) << __func__ << ": Failed to schedule on JNI thread"; + log::fatal("Failed to schedule on JNI thread"); } } diff --git a/system/btif/src/btif_profile_storage.cc b/system/btif/src/btif_profile_storage.cc index 3f6d17260ac..2884fb15d0d 100644 --- a/system/btif/src/btif_profile_storage.cc +++ b/system/btif/src/btif_profile_storage.cc @@ -21,6 +21,7 @@ #include <alloca.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -50,6 +51,7 @@ using base::Bind; using bluetooth::Uuid; using bluetooth::csis::CsisClient; using bluetooth::groups::DeviceGroups; +using namespace bluetooth; /******************************************************************************* * Constants & Macros @@ -95,7 +97,7 @@ bt_status_t btif_storage_add_hid_device_info( uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version, uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout, uint16_t dl_len, uint8_t* dsc_list) { - LOG_VERBOSE("btif_storage_add_hid_device_info:"); + log::verbose("btif_storage_add_hid_device_info:"); std::string bdstr = remote_bd_addr->ToString(); btif_config_set_int(bdstr, BTIF_STORAGE_KEY_HID_ATTR_MASK, attr_mask); btif_config_set_int(bdstr, BTIF_STORAGE_KEY_HID_SUB_CLASS, sub_class); @@ -129,7 +131,7 @@ bt_status_t btif_storage_load_bonded_hid_info(void) { auto name = bd_addr.ToString(); tAclLinkSpec link_spec; - LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); int value; if (!btif_config_get_int(name, BTIF_STORAGE_KEY_HID_ATTR_MASK, &value)) @@ -272,7 +274,7 @@ std::vector<std::pair<RawAddress, uint8_t>> btif_storage_get_le_hid_devices( btif_get_address_type(bd_addr, &type); hid_addresses.push_back({bd_addr, type}); - LOG_DEBUG("Remote device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::debug("Remote device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } } @@ -299,7 +301,7 @@ std::vector<RawAddress> btif_storage_get_wake_capable_classic_hid_devices( } hid_addresses.push_back(bd_addr); - LOG_DEBUG("Remote device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::debug("Remote device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } } @@ -312,8 +314,8 @@ void btif_storage_add_hearing_aid(const HearingDevice& dev_info) { Bind( [](const HearingDevice& dev_info) { std::string bdstr = dev_info.address.ToString(); - VLOG(2) << "saving hearing aid device: " - << ADDRESS_TO_LOGGABLE_STR(dev_info.address); + log::verbose("saving hearing aid device: {}", + ADDRESS_TO_LOGGABLE_STR(dev_info.address)); btif_config_set_int( bdstr, BTIF_STORAGE_KEY_HEARING_AID_SERVICE_CHANGED_CCC_HANDLE, dev_info.service_changed_ccc_handle); @@ -375,7 +377,7 @@ void btif_storage_load_bonded_hearing_aids() { continue; } - LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); if (btif_in_fetch_bonded_device(name) != BT_STATUS_SUCCESS) { btif_storage_remove_hearing_aid(bd_addr); @@ -537,8 +539,9 @@ void btif_storage_set_leaudio_autoconnect(const RawAddress& addr, do_in_jni_thread(FROM_HERE, Bind( [](const RawAddress& addr, bool autoconnect) { std::string bdstr = addr.ToString(); - VLOG(2) << "saving le audio device: " - << ADDRESS_TO_LOGGABLE_CSTR(addr); + log::verbose( + "saving le audio device: {}", + ADDRESS_TO_LOGGABLE_CSTR(addr)); btif_config_set_int( bdstr, BTIF_STORAGE_KEY_LEAUDIO_AUTOCONNECT, @@ -621,8 +624,8 @@ void btif_storage_set_leaudio_audio_location(const RawAddress& addr, Bind( [](const RawAddress& addr, int sink_location, int source_location) { std::string bdstr = addr.ToString(); - LOG_DEBUG("saving le audio device: %s", - ADDRESS_TO_LOGGABLE_CSTR(addr)); + log::debug("saving le audio device: {}", + ADDRESS_TO_LOGGABLE_CSTR(addr)); btif_config_set_int(bdstr, BTIF_STORAGE_KEY_LEAUDIO_SINK_AUDIOLOCATION, sink_location); @@ -643,8 +646,8 @@ void btif_storage_set_leaudio_supported_context_types( [](const RawAddress& addr, int sink_supported_context_type, int source_supported_context_type) { std::string bdstr = addr.ToString(); - LOG_DEBUG("saving le audio device: %s", - ADDRESS_TO_LOGGABLE_CSTR(addr)); + log::debug("saving le audio device: {}", + ADDRESS_TO_LOGGABLE_CSTR(addr)); btif_config_set_int( bdstr, BTIF_STORAGE_KEY_LEAUDIO_SINK_SUPPORTED_CONTEXT_TYPE, sink_supported_context_type); @@ -679,7 +682,7 @@ void btif_storage_load_bonded_leaudio() { continue; } - LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); int value; bool autoconnect = false; @@ -848,8 +851,9 @@ void btif_storage_load_bonded_leaudio_has_devices() { if (btif_config_get_int(name, BTIF_STORAGE_KEY_LEAUDIO_HAS_FLAGS, &value)) features = value; - do_in_main_thread(FROM_HERE, Bind(&le_audio::has::HasClient::AddFromStorage, - bd_addr, features, is_acceptlisted)); + do_in_main_thread(FROM_HERE, + Bind(&::le_audio::has::HasClient::AddFromStorage, bd_addr, + features, is_acceptlisted)); #else ASSERT_LOG(false, "TODO - Fix LE audio build."); #endif @@ -940,7 +944,7 @@ void btif_storage_load_bonded_groups(void) { btif_config_get_bin_length(name, BTIF_STORAGE_KEY_DEVICE_GROUP_BIN); if (buffer_size == 0) continue; - LOG_VERBOSE("Grouped device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Grouped device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); std::vector<uint8_t> in(buffer_size); if (btif_config_get_bin(name, BTIF_STORAGE_KEY_DEVICE_GROUP_BIN, in.data(), @@ -985,7 +989,7 @@ void btif_storage_load_bonded_csis_devices(void) { for (const auto& bd_addr : btif_config_get_paired_devices()) { auto name = bd_addr.ToString(); - LOG_VERBOSE("Loading CSIS device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Loading CSIS device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); size_t buffer_size = btif_config_get_bin_length(name, BTIF_STORAGE_KEY_CSIS_SET_INFO_BIN); @@ -1019,7 +1023,7 @@ bt_status_t btif_storage_load_hidd(void) { for (const auto& bd_addr : btif_config_get_paired_devices()) { auto name = bd_addr.ToString(); - LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); int value; if (btif_in_fetch_bonded_device(name) == BT_STATUS_SUCCESS) { if (btif_config_get_int(name, BTIF_STORAGE_KEY_HID_DEVICE_CABLED, @@ -1084,14 +1088,14 @@ bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr) { ******************************************************************************/ void btif_storage_set_pce_profile_version(const RawAddress& remote_bd_addr, uint16_t peer_pce_version) { - LOG_VERBOSE("peer_pce_version : 0x%x", peer_pce_version); + log::verbose("peer_pce_version : 0x{:x}", peer_pce_version); if (btif_config_set_bin( remote_bd_addr.ToString(), BTIF_STORAGE_KEY_PBAP_PCE_VERSION, (const uint8_t*)&peer_pce_version, sizeof(peer_pce_version))) { } else { - LOG_WARN("Failed to store peer_pce_version for %s", - ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); + log::warn("Failed to store peer_pce_version for {}", + ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); } } @@ -1113,8 +1117,8 @@ bool btif_storage_is_pce_version_102(const RawAddress& remote_bd_addr) { if (!btif_config_get_bin(remote_bd_addr.ToString(), BTIF_STORAGE_KEY_PBAP_PCE_VERSION, (uint8_t*)&pce_version, &version_value_size)) { - LOG_VERBOSE("Failed to read cached peer PCE version for %s", - ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); + log::verbose("Failed to read cached peer PCE version for {}", + ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); return entry_found; } @@ -1122,8 +1126,8 @@ bool btif_storage_is_pce_version_102(const RawAddress& remote_bd_addr) { entry_found = true; } - LOG_VERBOSE("read cached peer PCE version 0x%04x for %s", pce_version, - ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); + log::verbose("read cached peer PCE version 0x{:04x} for {}", pce_version, + ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr)); return entry_found; } diff --git a/system/btif/src/btif_rc.cc b/system/btif/src/btif_rc.cc index 20f4ddac94e..80159e8ba73 100644 --- a/system/btif/src/btif_rc.cc +++ b/system/btif/src/btif_rc.cc @@ -27,6 +27,7 @@ #include "btif_rc.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <fcntl.h> #include <hardware/bluetooth.h> #include <hardware/bt_rc.h> @@ -95,22 +96,24 @@ #define PLAY_STATUS_PLAYING 1 #define BTIF_RC_NUM_CONN BT_RC_NUM_APP -#define CHECK_RC_CONNECTED(p_dev) \ - do { \ - if ((p_dev) == NULL || !(p_dev)->rc_connected) { \ - LOG_WARN("%s: called when RC is not connected", __func__); \ - return BT_STATUS_NOT_READY; \ - } \ +#define CHECK_RC_CONNECTED(p_dev) \ + do { \ + if ((p_dev) == NULL || !(p_dev)->rc_connected) { \ + log::warn("called when RC is not connected"); \ + return BT_STATUS_NOT_READY; \ + } \ } while (0) -#define CHECK_BR_CONNECTED(p_dev) \ - do { \ - if ((p_dev) == NULL || !(p_dev)->br_connected) { \ - LOG_WARN("%s: called when BR is not connected", __func__); \ - return BT_STATUS_NOT_READY; \ - } \ +#define CHECK_BR_CONNECTED(p_dev) \ + do { \ + if ((p_dev) == NULL || !(p_dev)->br_connected) { \ + log::warn("called when BR is not connected"); \ + return BT_STATUS_NOT_READY; \ + } \ } while (0) +using namespace bluetooth; + /***************************************************************************** * Local type definitions *****************************************************************************/ @@ -411,18 +414,18 @@ static const uint8_t media_attr_list_no_cover_art_size = bool check_cod(const RawAddress& remote_bdaddr, uint32_t cod); void btif_rc_get_addr_by_handle(uint8_t handle, RawAddress& rc_addr) { - LOG_VERBOSE("%s: handle: 0x%x", __func__, handle); + log::verbose("handle: 0x{:x}", handle); for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) { if ((btif_rc_cb.rc_multi_cb[idx].rc_state != BTRC_CONNECTION_STATE_DISCONNECTED) && (btif_rc_cb.rc_multi_cb[idx].rc_handle == handle)) { - LOG_VERBOSE("%s: btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x%x", __func__, - btif_rc_cb.rc_multi_cb[idx].rc_handle); + log::verbose("btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x{:x}", + btif_rc_cb.rc_multi_cb[idx].rc_handle); rc_addr = btif_rc_cb.rc_multi_cb[idx].rc_addr; return; } } - LOG_ERROR("%s: returning NULL", __func__); + log::error("returning NULL"); rc_addr = RawAddress::kEmpty; return; } @@ -479,22 +482,21 @@ void initialize_device(btif_rc_device_cb_t* p_dev) { } static btif_rc_device_cb_t* get_connected_device(int index) { - LOG_VERBOSE("%s: index: %d", __func__, index); + log::verbose("index: {}", index); if (index >= BTIF_RC_NUM_CONN) { - LOG_ERROR("%s: can't support more than %d connections", __func__, - BTIF_RC_NUM_CONN); + log::error("can't support more than {} connections", BTIF_RC_NUM_CONN); return NULL; } if (btif_rc_cb.rc_multi_cb[index].rc_state != BTRC_CONNECTION_STATE_CONNECTED) { - LOG_ERROR("%s: returning NULL", __func__); + log::error("returning NULL"); return NULL; } return (&btif_rc_cb.rc_multi_cb[index]); } btif_rc_device_cb_t* btif_rc_get_device_by_bda(const RawAddress& bd_addr) { - VLOG(1) << __func__ << ": bd_addr: " << ADDRESS_TO_LOGGABLE_STR(bd_addr); + log::verbose("bd_addr: {}", ADDRESS_TO_LOGGABLE_STR(bd_addr)); for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) { if ((btif_rc_cb.rc_multi_cb[idx].rc_state != @@ -503,22 +505,22 @@ btif_rc_device_cb_t* btif_rc_get_device_by_bda(const RawAddress& bd_addr) { return (&btif_rc_cb.rc_multi_cb[idx]); } } - LOG_ERROR("%s: device not found, returning NULL!", __func__); + log::error("device not found, returning NULL!"); return NULL; } btif_rc_device_cb_t* btif_rc_get_device_by_handle(uint8_t handle) { - LOG_VERBOSE("%s: handle: 0x%x", __func__, handle); + log::verbose("handle: 0x{:x}", handle); for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) { if ((btif_rc_cb.rc_multi_cb[idx].rc_state != BTRC_CONNECTION_STATE_DISCONNECTED) && (btif_rc_cb.rc_multi_cb[idx].rc_handle == handle)) { - LOG_VERBOSE("%s: btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x%x", __func__, - btif_rc_cb.rc_multi_cb[idx].rc_handle); + log::verbose("btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x{:x}", + btif_rc_cb.rc_multi_cb[idx].rc_handle); return (&btif_rc_cb.rc_multi_cb[idx]); } } - LOG_ERROR("%s: returning NULL", __func__); + log::error("returning NULL"); return NULL; } @@ -549,15 +551,15 @@ void fill_avrc_attr_entry(tAVRC_ATTR_ENTRY* attr_vals, int num_attrs, attr_vals[attr_cnt].name.str_len = (uint16_t)strlen((char*)p_attrs[attr_cnt].text); attr_vals[attr_cnt].name.p_str = p_attrs[attr_cnt].text; - LOG_VERBOSE("%s: attr_id: 0x%x, charset_id: 0x%x, str_len: %d, str: %s", - __func__, (unsigned int)attr_vals[attr_cnt].attr_id, - attr_vals[attr_cnt].name.charset_id, - attr_vals[attr_cnt].name.str_len, - attr_vals[attr_cnt].name.p_str); + log::verbose("attr_id: 0x{:x}, charset_id: 0x{:x}, str_len: {}, str: {}", + (unsigned int)attr_vals[attr_cnt].attr_id, + attr_vals[attr_cnt].name.charset_id, + attr_vals[attr_cnt].name.str_len, + reinterpret_cast<char const*>(attr_vals[attr_cnt].name.p_str)); } } -void rc_cleanup_sent_cmd(void* p_data) { LOG_VERBOSE("%s: ", __func__); } +void rc_cleanup_sent_cmd(void* p_data) { log::verbose(""); } void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) { if (!(p_dev->peer_tg_features & BTA_AV_FEAT_RCTG) && @@ -568,10 +570,10 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) { int rc_features = 0; - LOG_VERBOSE( - "%s: peer_tg_features: 0x%x, rc_features_processed=%d, connected=%d, " - "peer_is_src:%d", - __func__, p_dev->peer_tg_features, p_dev->rc_features_processed, + log::verbose( + "peer_tg_features: 0x{:x}, rc_features_processed={}, connected={}, " + "peer_is_src:{}", + p_dev->peer_tg_features, p_dev->rc_features_processed, btif_av_is_connected_addr(p_dev->rc_addr), btif_av_peer_is_source(p_dev->rc_addr)); @@ -601,8 +603,8 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) { } } } else { - LOG_VERBOSE("%s: %s is not connected, pending", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr)); + log::verbose("{} is not connected, pending", + ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr)); p_dev->launch_cmd_pending |= (RC_PENDING_ACT_GET_CAP | RC_PENDING_ACT_REG_VOL); } @@ -618,7 +620,7 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) { } if (bt_rc_ctrl_callbacks != NULL) { - LOG_VERBOSE("%s: Update rc features to CTRL: %d", __func__, rc_features); + log::verbose("Update rc features to CTRL: {}", rc_features); do_in_jni_thread(FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->getrcfeatures_cb, p_dev->rc_addr, rc_features)); @@ -670,7 +672,7 @@ void handle_rc_ctrl_features(btif_rc_device_cb_t* p_dev) { rc_features |= BTRC_FEAT_COVER_ARTWORK; } - LOG_VERBOSE("%s: Update rc features to CTRL: %d", __func__, rc_features); + log::verbose("Update rc features to CTRL: {}", rc_features); do_in_jni_thread(FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->getrcfeatures_cb, p_dev->rc_addr, rc_features)); @@ -679,15 +681,15 @@ void btif_rc_check_pending_cmd(const RawAddress& peer_address) { btif_rc_device_cb_t* p_dev = NULL; p_dev = btif_rc_get_device_by_bda(peer_address); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } - LOG_VERBOSE( - "%s: launch_cmd_pending=%d, rc_connected=%d, peer_ct_features=0x%x, " - "peer_tg_features=0x%x", - __FUNCTION__, p_dev->launch_cmd_pending, p_dev->rc_connected, - p_dev->peer_ct_features, p_dev->peer_tg_features); + log::verbose( + "launch_cmd_pending={}, rc_connected={}, peer_ct_features=0x{:x}, " + "peer_tg_features=0x{:x}", + p_dev->launch_cmd_pending, p_dev->rc_connected, p_dev->peer_ct_features, + p_dev->peer_tg_features); if (p_dev->launch_cmd_pending && p_dev->rc_connected) { if ((p_dev->launch_cmd_pending & RC_PENDING_ACT_REG_VOL) && btif_av_peer_is_sink(p_dev->rc_addr)) { @@ -714,8 +716,7 @@ void btif_rc_check_pending_cmd(const RawAddress& peer_address) { void handle_rc_ctrl_psm(btif_rc_device_cb_t* p_dev) { uint16_t cover_art_psm = p_dev->rc_cover_art_psm; - LOG_VERBOSE("%s: Update rc cover art psm to CTRL: %d", __func__, - cover_art_psm); + log::verbose("Update rc cover art psm to CTRL: {}", cover_art_psm); if (bt_rc_ctrl_callbacks != NULL) { do_in_jni_thread(FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->get_cover_art_psm_cb, @@ -731,11 +732,10 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) { RawAddress avdtp_source_active_peer_addr = btif_av_source_active_peer(); RawAddress avdtp_sink_active_peer_addr = btif_av_sink_active_peer(); - LOG_VERBOSE( - "%s: AVDTP Source Active Peer Address: %s " - "AVDTP Sink Active Peer Address: %s " - "AVCTP address: %s", - __func__, ADDRESS_TO_LOGGABLE_CSTR(avdtp_source_active_peer_addr), + log::verbose( + "AVDTP Source Active Peer Address: {} AVDTP Sink Active Peer Address: {} " + "AVCTP address: {}", + ADDRESS_TO_LOGGABLE_CSTR(avdtp_source_active_peer_addr), ADDRESS_TO_LOGGABLE_CSTR(avdtp_sink_active_peer_addr), ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr)); @@ -764,12 +764,11 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) { (btrc_remote_features_t)(rc_features | BTRC_FEAT_ABSOLUTE_VOLUME); } - LOG_VERBOSE("%s: rc_features: 0x%x", __func__, rc_features); + log::verbose("rc_features: 0x{:x}", rc_features); HAL_CBACK(bt_rc_callbacks, remote_features_cb, p_dev->rc_addr, rc_features); - LOG_VERBOSE( - "%s: Checking for feature flags in btif_rc_handler with label: %d", - __func__, p_dev->rc_vol_label); + log::verbose("Checking for feature flags in btif_rc_handler with label: {}", + p_dev->rc_vol_label); // Register for volume change on connect if (p_dev->rc_features & BTA_AV_FEAT_ADV_CTRL && p_dev->rc_features & BTA_AV_FEAT_RCTG) { @@ -786,13 +785,13 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) { * ***************************************************************************/ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) { - LOG_VERBOSE("%s: rc_handle %d status %d", __func__, p_rc_br_open->rc_handle, - p_rc_br_open->status); + log::verbose("rc_handle {} status {}", p_rc_br_open->rc_handle, + p_rc_br_open->status); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_handle(p_rc_br_open->rc_handle); if (!p_dev) { - LOG_ERROR("%s p_dev is null", __func__); + log::error("p_dev is null"); return; } @@ -811,7 +810,7 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) { } } else { p_dev->launch_cmd_pending |= RC_PENDING_ACT_REPORT_CONN; - LOG_VERBOSE("%s: pending rc browse connection event", __func__); + log::verbose("pending rc browse connection event"); } } else { if (bt_rc_ctrl_callbacks != NULL) { @@ -820,7 +819,7 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) { base::BindOnce(bt_rc_ctrl_callbacks->connection_state_cb, true, true, p_dev->rc_addr)); } else { - LOG_WARN("%s: bt_rc_ctrl_callbacks is null.", __func__); + log::warn("bt_rc_ctrl_callbacks is null."); } } } @@ -835,17 +834,16 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) { * ***************************************************************************/ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) { - LOG_VERBOSE("%s: rc_handle: %d", __func__, p_rc_open->rc_handle); + log::verbose("rc_handle: {}", p_rc_open->rc_handle); btif_rc_device_cb_t* p_dev = alloc_device(); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev is NULL", __func__); + log::error("p_dev is NULL"); return; } if (!(p_rc_open->status == BTA_AV_SUCCESS)) { - LOG_ERROR("%s: Connect failed with error code: %d", __func__, - p_rc_open->status); + log::error("Connect failed with error code: {}", p_rc_open->status); p_dev->rc_connected = false; BTA_AvCloseRc(p_rc_open->rc_handle); p_dev->rc_handle = 0; @@ -868,7 +866,7 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) { __func__, p_dev->rc_handle, p_rc_open->rc_handle); if (p_dev->rc_handle != p_rc_open->rc_handle && p_dev->rc_addr != p_rc_open->peer_addr) { - LOG_VERBOSE("%s: Got RC connected for some other handle", __func__); + log::verbose("Got RC connected for some other handle"); BTA_AvCloseRc(p_rc_open->rc_handle); return; } @@ -881,12 +879,11 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) { p_dev->rc_vol_label = MAX_LABEL; p_dev->rc_volume = MAX_VOLUME; - LOG_VERBOSE( - "%s: handle_rc_connect in features=%#x, out features=%#x, " - "ct_feature=%#x, tg_feature=%#x, cover art psm=%#x", - __func__, p_rc_open->peer_features, p_dev->rc_features, - p_dev->peer_ct_features, p_dev->peer_tg_features, - p_dev->rc_cover_art_psm); + log::verbose( + "handle_rc_connect in features={:#x}, out features={:#x}, " + "ct_feature={:#x}, tg_feature={:#x}, cover art psm={:#x}", + p_rc_open->peer_features, p_dev->rc_features, p_dev->peer_ct_features, + p_dev->peer_tg_features, p_dev->rc_cover_art_psm); p_dev->rc_connected = true; p_dev->rc_handle = p_rc_open->rc_handle; @@ -897,7 +894,7 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) { if (btif_av_src_sink_coexist_enabled() && !btif_av_peer_is_connected_source(p_dev->rc_addr)) { p_dev->launch_cmd_pending |= RC_PENDING_ACT_REPORT_CONN; - LOG_VERBOSE("%s: pending rc connection event", __func__); + log::verbose("pending rc connection event"); return; } if (bt_rc_ctrl_callbacks != NULL) { @@ -922,17 +919,17 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) { ***************************************************************************/ void handle_rc_disconnect(tBTA_AV_RC_CLOSE* p_rc_close) { btif_rc_device_cb_t* p_dev = NULL; - LOG_VERBOSE("%s: rc_handle: %d", __func__, p_rc_close->rc_handle); + log::verbose("rc_handle: {}", p_rc_close->rc_handle); p_dev = btif_rc_get_device_by_handle(p_rc_close->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Got disconnect from invalid rc handle", __func__); + log::error("Got disconnect from invalid rc handle"); return; } if (p_rc_close->rc_handle != p_dev->rc_handle && p_dev->rc_addr != p_rc_close->peer_addr) { - LOG_ERROR("Got disconnect of unknown device"); + log::error("Got disconnect of unknown device"); return; } @@ -959,24 +956,24 @@ void handle_rc_disconnect(tBTA_AV_RC_CLOSE* p_rc_close) { ***************************************************************************/ void handle_rc_passthrough_cmd(tBTA_AV_REMOTE_CMD* p_remote_cmd) { if (p_remote_cmd == NULL) { - LOG_ERROR("%s: No remote command!", __func__); + log::error("No remote command!"); return; } btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_handle(p_remote_cmd->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Got passthrough command from invalid rc handle", __func__); + log::error("Got passthrough command from invalid rc handle"); return; } - LOG_VERBOSE("%s: p_remote_cmd->rc_id: %d", __func__, p_remote_cmd->rc_id); + log::verbose("p_remote_cmd->rc_id: {}", p_remote_cmd->rc_id); /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up * this PLAY */ if ((p_remote_cmd->rc_id == AVRC_ID_PLAY) && (!btif_av_is_connected())) { if (p_remote_cmd->key_state == AVRC_STATE_PRESS) { - LOG_WARN("%s: AVDT not open, queuing the PLAY command", __func__); + log::warn("AVDT not open, queuing the PLAY command"); p_dev->rc_pending_play = true; } return; @@ -984,22 +981,22 @@ void handle_rc_passthrough_cmd(tBTA_AV_REMOTE_CMD* p_remote_cmd) { /* If we previously queued a play and we get a PAUSE, clear it. */ if ((p_remote_cmd->rc_id == AVRC_ID_PAUSE) && (p_dev->rc_pending_play)) { - LOG_WARN("%s: Clear the pending PLAY on PAUSE received", __func__); + log::warn("Clear the pending PLAY on PAUSE received"); p_dev->rc_pending_play = false; return; } if ((p_remote_cmd->rc_id == AVRC_ID_STOP) && (!btif_av_stream_started_ready())) { - LOG_WARN("%s: Stream suspended, ignore STOP cmd", __func__); + log::warn("Stream suspended, ignore STOP cmd"); return; } int pressed = (p_remote_cmd->key_state == AVRC_STATE_PRESS) ? 1 : 0; /* pass all commands up */ - LOG_VERBOSE("%s: rc_features: %d, cmd->rc_id: %d, pressed: %d", __func__, - p_dev->rc_features, p_remote_cmd->rc_id, pressed); + log::verbose("rc_features: {}, cmd->rc_id: {}, pressed: {}", + p_dev->rc_features, p_remote_cmd->rc_id, pressed); HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed, p_dev->rc_addr); } @@ -1017,18 +1014,18 @@ void handle_rc_passthrough_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) { p_dev = btif_rc_get_device_by_handle(p_remote_rsp->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: passthrough response for Invalid rc handle", __func__); + log::error("passthrough response for Invalid rc handle"); return; } if (!(p_dev->rc_features & BTA_AV_FEAT_RCTG)) { - LOG_ERROR("%s: DUT does not support AVRCP controller role", __func__); + log::error("DUT does not support AVRCP controller role"); return; } const char* status = (p_remote_rsp->key_state == 1) ? "released" : "pressed"; - LOG_VERBOSE("%s: rc_id: %d state: %s", __func__, p_remote_rsp->rc_id, status); + log::verbose("rc_id: {} state: {}", p_remote_rsp->rc_id, status); release_transaction(p_dev, p_remote_rsp->label); if (bt_rc_ctrl_callbacks != NULL) { @@ -1054,7 +1051,7 @@ void handle_rc_vendorunique_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) { p_dev = btif_rc_get_device_by_handle(p_remote_rsp->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Got vendorunique rsp from invalid rc handle", __func__); + log::error("Got vendorunique rsp from invalid rc handle"); return; } @@ -1073,14 +1070,14 @@ void handle_rc_vendorunique_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) { vendor_id = p_remote_rsp->p_data[AVRC_PASS_THRU_GROUP_LEN - 1]; osi_free_and_reset((void**)&p_remote_rsp->p_data); } - LOG_VERBOSE("%s: vendor_id: %d status: %s", __func__, vendor_id, status); + log::verbose("vendor_id: {} status: {}", vendor_id, status); release_transaction(p_dev, p_remote_rsp->label); do_in_jni_thread( FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->groupnavigation_rsp_cb, vendor_id, key_state)); } else { - LOG_ERROR("%s: Remote does not support AVRCP TG role", __func__); + log::error("Remote does not support AVRCP TG role"); } } @@ -1101,33 +1098,33 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { btif_rc_device_cb_t* p_dev = NULL; if (NULL == pmeta_msg) { - LOG_VERBOSE("%s: Exiting as pmeta_msg is NULL", __func__); + log::verbose("Exiting as pmeta_msg is NULL"); return; } if (NULL == pmeta_msg->p_msg) { - LOG_VERBOSE("%s: Exiting as pmeta_msg->p_msg is NULL", __func__); + log::verbose("Exiting as pmeta_msg->p_msg is NULL"); return; } - LOG_VERBOSE("%s: pmeta_msg: opcode: %x, code: %x", __func__, - pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code); + log::verbose("pmeta_msg: opcode: {:x}, code: {:x}", + pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code); p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Meta msg event for Invalid rc handle", __func__); + log::error("Meta msg event for Invalid rc handle"); return; } if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR && pmeta_msg->p_msg->hdr.opcode != AVRC_OP_BROWSE) { - LOG_WARN("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode); + log::warn("Invalid opcode: {:x}", pmeta_msg->p_msg->hdr.opcode); return; } if (pmeta_msg->len < 3) { - LOG_WARN("%s: Invalid length. opcode: 0x%x, len: 0x%x", __func__, - pmeta_msg->p_msg->hdr.opcode, pmeta_msg->len); + log::warn("Invalid length. opcode: 0x{:x}, len: 0x{:x}", + pmeta_msg->p_msg->hdr.opcode, pmeta_msg->len); return; } @@ -1138,8 +1135,8 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { if (transaction != NULL) { handle_rc_metamsg_rsp(pmeta_msg, p_dev); } else { - LOG_VERBOSE("%s: Discard vendor dependent rsp. code: %d label: %d.", - __func__, pmeta_msg->code, pmeta_msg->label); + log::verbose("Discard vendor dependent rsp. code: {} label: {}.", + pmeta_msg->code, pmeta_msg->label); } return; } @@ -1147,14 +1144,13 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { status = AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf)); - LOG_VERBOSE("%s: Received vendor command.code,PDU and label: %d, %d, %d", - __func__, pmeta_msg->code, avrc_command.cmd.pdu, - pmeta_msg->label); + log::verbose("Received vendor command.code,PDU and label: {}, {}, {}", + pmeta_msg->code, avrc_command.cmd.pdu, pmeta_msg->label); if (status != AVRC_STS_NO_ERROR) { /* return error */ - LOG_WARN("%s: Error in parsing received metamsg command. status: 0x%02x", - __func__, status); + log::warn("Error in parsing received metamsg command. status: 0x{:02x}", + status); send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status, pmeta_msg->p_msg->hdr.opcode); @@ -1164,10 +1160,10 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) { uint8_t event_id = avrc_command.reg_notif.event_id; - LOG_VERBOSE( - "%s: New register notification received.event_id: %s, label: 0x%x, " - "code: %x", - __func__, dump_rc_notification_event_id(event_id), pmeta_msg->label, + log::verbose( + "New register notification received.event_id: {}, label: 0x{:x}, " + "code: {:x}", + dump_rc_notification_event_id(event_id), pmeta_msg->label, pmeta_msg->code); p_dev->rc_notif[event_id - 1].bNotify = true; p_dev->rc_notif[event_id - 1].label = pmeta_msg->label; @@ -1182,8 +1178,8 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { avrc_command.cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME) { return; } - LOG_VERBOSE("%s: Passing received metamsg command to app. pdu: %s", - __func__, dump_rc_pdu(avrc_command.cmd.pdu)); + log::verbose("Passing received metamsg command to app. pdu: {}", + dump_rc_pdu(avrc_command.cmd.pdu)); /* Since handle_rc_metamsg_cmd() itself is called from *btif context, no context switching is required. Invoke @@ -1201,12 +1197,13 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { ** ***************************************************************************/ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { - LOG_VERBOSE("%s: event: %s", __func__, dump_rc_event(event)); + log::verbose("event: {}", dump_rc_event(event)); btif_rc_device_cb_t* p_dev = NULL; switch (event) { case BTA_AV_RC_OPEN_EVT: { - LOG_VERBOSE("%s: Peer_features: 0x%x Cover Art PSM: 0x%x", __func__, - p_data->rc_open.peer_features, p_data->rc_open.cover_art_psm); + log::verbose("Peer_features: 0x{:x} Cover Art PSM: 0x{:x}", + p_data->rc_open.peer_features, + p_data->rc_open.cover_art_psm); handle_rc_connect(&(p_data->rc_open)); } break; @@ -1221,23 +1218,22 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { } break; case BTA_AV_RC_BROWSE_CLOSE_EVT: { - LOG_VERBOSE("%s: BTA_AV_RC_BROWSE_CLOSE_EVT", __func__); + log::verbose("BTA_AV_RC_BROWSE_CLOSE_EVT"); } break; case BTA_AV_REMOTE_CMD_EVT: { if (bt_rc_callbacks != NULL) { - LOG_VERBOSE("%s: rc_id: 0x%x key_state: %d", __func__, - p_data->remote_cmd.rc_id, p_data->remote_cmd.key_state); + log::verbose("rc_id: 0x{:x} key_state: {}", p_data->remote_cmd.rc_id, + p_data->remote_cmd.key_state); handle_rc_passthrough_cmd((&p_data->remote_cmd)); } else { - LOG_ERROR("%s: AVRCP TG role not up, drop passthrough commands", - __func__); + log::error("AVRCP TG role not up, drop passthrough commands"); } } break; case BTA_AV_REMOTE_RSP_EVT: { - LOG_VERBOSE("%s: RSP: rc_id: 0x%x key_state: %d", __func__, - p_data->remote_rsp.rc_id, p_data->remote_rsp.key_state); + log::verbose("RSP: rc_id: 0x{:x} key_state: {}", p_data->remote_rsp.rc_id, + p_data->remote_rsp.key_state); if (p_data->remote_rsp.rc_id == AVRC_ID_VENDOR) { handle_rc_vendorunique_rsp((&p_data->remote_rsp)); @@ -1247,20 +1243,19 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { } break; case BTA_AV_RC_FEAT_EVT: { - LOG_VERBOSE("%s: Peer_features: %x", __func__, - p_data->rc_feat.peer_features); + log::verbose("Peer_features: {:x}", p_data->rc_feat.peer_features); p_dev = btif_rc_get_device_by_handle(p_data->rc_feat.rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: RC Feature event for Invalid rc handle", __func__); + log::error("RC Feature event for Invalid rc handle"); break; } - LOG_VERBOSE("%s peer_ct_features:0x%x, peer_tg_features=0x%x", __func__, - p_data->rc_feat.peer_ct_features, - p_data->rc_feat.peer_tg_features); + log::verbose("peer_ct_features:0x{:x}, peer_tg_features=0x{:x}", + p_data->rc_feat.peer_ct_features, + p_data->rc_feat.peer_tg_features); if (btif_av_src_sink_coexist_enabled() && (p_dev->peer_ct_features == p_data->rc_feat.peer_ct_features) && (p_dev->peer_tg_features == p_data->rc_feat.peer_tg_features)) { - LOG_ERROR( + log::error( "do SDP twice, no need callback rc_feature to framework again"); break; } @@ -1278,11 +1273,11 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { } break; case BTA_AV_RC_PSM_EVT: { - LOG_VERBOSE("%s: Peer cover art PSM: %x", __func__, - p_data->rc_cover_art_psm.cover_art_psm); + log::verbose("Peer cover art PSM: {:x}", + p_data->rc_cover_art_psm.cover_art_psm); p_dev = btif_rc_get_device_by_handle(p_data->rc_cover_art_psm.rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: RC PSM event for Invalid rc handle", __func__); + log::error("RC PSM event for Invalid rc handle"); break; } @@ -1294,11 +1289,11 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { case BTA_AV_META_MSG_EVT: { if (bt_rc_callbacks != NULL) { - LOG_VERBOSE("%s: BTA_AV_META_MSG_EVT code: %d label: %d", __func__, - p_data->meta_msg.code, p_data->meta_msg.label); - LOG_VERBOSE("%s: company_id: 0x%x len: %d handle: %d", __func__, - p_data->meta_msg.company_id, p_data->meta_msg.len, - p_data->meta_msg.rc_handle); + log::verbose("BTA_AV_META_MSG_EVT code: {} label: {}", + p_data->meta_msg.code, p_data->meta_msg.label); + log::verbose("company_id: 0x{:x} len: {} handle: {}", + p_data->meta_msg.company_id, p_data->meta_msg.len, + p_data->meta_msg.rc_handle); /* handle the metamsg command */ handle_rc_metamsg_cmd(&(p_data->meta_msg)); @@ -1306,14 +1301,13 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { /* Free the Memory allocated for tAVRC_MSG */ } else if (bt_rc_ctrl_callbacks != NULL) { /* This is case of Sink + CT + TG(for abs vol)) */ - LOG_VERBOSE( - "%s BTA_AV_META_MSG_EVT code:%d label:%d opcode %d ctype %d", - __func__, p_data->meta_msg.code, p_data->meta_msg.label, - p_data->meta_msg.p_msg->hdr.opcode, - p_data->meta_msg.p_msg->hdr.ctype); - LOG_VERBOSE("%s company_id:0x%x len:%d handle:%d", __func__, - p_data->meta_msg.company_id, p_data->meta_msg.len, - p_data->meta_msg.rc_handle); + log::verbose("BTA_AV_META_MSG_EVT code:{} label:{} opcode {} ctype {}", + p_data->meta_msg.code, p_data->meta_msg.label, + p_data->meta_msg.p_msg->hdr.opcode, + p_data->meta_msg.p_msg->hdr.ctype); + log::verbose("company_id:0x{:x} len:{} handle:{}", + p_data->meta_msg.company_id, p_data->meta_msg.len, + p_data->meta_msg.rc_handle); switch (p_data->meta_msg.p_msg->hdr.opcode) { case AVRC_OP_VENDOR: if ((p_data->meta_msg.code >= AVRC_RSP_NOT_IMPL) && @@ -1335,12 +1329,12 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) { break; } } else { - LOG_ERROR("Neither CTRL, nor TG is up, drop meta commands"); + log::error("Neither CTRL, nor TG is up, drop meta commands"); } } break; default: - LOG_VERBOSE("%s: Unhandled RC event : 0x%x", __func__, event); + log::verbose("Unhandled RC event : 0x{:x}", event); } } @@ -1367,7 +1361,7 @@ uint8_t btif_rc_get_connected_peer_handle(const RawAddress& peer_addr) { p_dev = btif_rc_get_device_by_bda(peer_addr); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return BTRC_HANDLE_NONE; } return p_dev->rc_handle; @@ -1389,15 +1383,15 @@ void btif_rc_check_handle_pending_play(const RawAddress& peer_addr, p_dev = btif_rc_get_device_by_bda(peer_addr); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } - LOG_VERBOSE("%s: bSendToApp: %d", __func__, bSendToApp); + log::verbose("bSendToApp: {}", bSendToApp); if (p_dev->rc_pending_play) { if (bSendToApp) { tBTA_AV_REMOTE_CMD remote_cmd; - LOG_VERBOSE("%s: Sending queued PLAYED event to app", __func__); + log::verbose("Sending queued PLAYED event to app"); memset(&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD)); remote_cmd.rc_handle = p_dev->rc_handle; @@ -1438,13 +1432,13 @@ static void send_reject_response(uint8_t rc_handle, uint8_t label, uint8_t pdu, status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg); if (status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: status not AVRC_STS_NO_ERROR", __func__); + log::error("status not AVRC_STS_NO_ERROR"); return; } - LOG_VERBOSE( - "%s: Sending error notification to handle: %d. pdu: %s,status: 0x%02x", - __func__, rc_handle, dump_rc_pdu(pdu), status); + log::verbose( + "Sending error notification to handle: {}. pdu: {},status: 0x{:02x}", + rc_handle, dump_rc_pdu(pdu), status); BTA_AvMetaRsp(rc_handle, label, ctype, p_msg); } @@ -1491,21 +1485,21 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index, uint8_t ctype; if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } if (pmetamsg_resp == NULL) { - LOG_WARN("%s: Invalid response received from application", __func__); + log::warn("Invalid response received from application"); return; } - LOG_VERBOSE("%s: rc_handle: %d, index: %d, label: %d, code: 0x%02x, pdu: %s", - __func__, p_dev->rc_handle, index, label, code, - dump_rc_pdu(pmetamsg_resp->rsp.pdu)); + log::verbose("rc_handle: {}, index: {}, label: {}, code: 0x{:02x}, pdu: {}", + p_dev->rc_handle, index, label, code, + dump_rc_pdu(pmetamsg_resp->rsp.pdu)); if (index >= 0 && !p_dev->rc_pdu_info[index].is_rsp_pending) { - LOG_ERROR("%s: is_rsp_pending false, returning", __func__); + log::error("is_rsp_pending false, returning"); return; } @@ -1522,23 +1516,21 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index, /* de-register this notification for a CHANGED response */ p_dev->rc_notif[event_id - 1].bNotify = false; - LOG_VERBOSE("%s: rc_handle: %d. event_id: 0x%02d bNotify: %u", __func__, - p_dev->rc_handle, event_id, bNotify); + log::verbose("rc_handle: {}. event_id: 0x{:02} bNotify: {}", + p_dev->rc_handle, event_id, bNotify); if (bNotify) { BT_HDR* p_msg = NULL; tAVRC_STS status; if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse( p_dev->rc_handle, pmetamsg_resp, &p_msg))) { - LOG_VERBOSE( - "%s: Sending notification to rc_handle: %d. event_id: 0x%02d", - __func__, p_dev->rc_handle, event_id); + log::verbose("Sending notification to rc_handle: {}. event_id: 0x{:02}", + p_dev->rc_handle, event_id); bSent = true; BTA_AvMetaRsp(p_dev->rc_handle, p_dev->rc_notif[event_id - 1].label, ctype, p_msg); } else { - LOG_WARN("%s: failed to build metamsg response. status: 0x%02x", - __func__, status); + log::warn("failed to build metamsg response. status: 0x{:02x}", status); } } @@ -1559,8 +1551,7 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index, if (status == AVRC_STS_NO_ERROR) { BTA_AvMetaRsp(p_dev->rc_handle, label, ctype, p_msg); } else { - LOG_ERROR("%s: failed to build metamsg response. status: 0x%02x", - __func__, status); + log::error("failed to build metamsg response. status: 0x{:02x}", status); } } @@ -1669,9 +1660,9 @@ static uint8_t fill_attribute_id_array( static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, uint8_t ctype, uint8_t label, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: pdu: %s handle: 0x%x ctype: %x label: %x event ID: %x", - __func__, dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle, ctype, - label, pavrc_cmd->reg_notif.event_id); + log::verbose("pdu: {} handle: 0x{:x} ctype: {:x} label: {:x} event ID: {:x}", + dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle, ctype, label, + pavrc_cmd->reg_notif.event_id); switch (event) { case AVRC_PDU_GET_PLAY_STATUS: { @@ -1694,8 +1685,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, pavrc_cmd->get_elem_attrs.num_attr, pavrc_cmd->get_elem_attrs.attrs, BTRC_MAX_ELEM_ATTR_SIZE, element_attrs); if (num_attr == 0) { - LOG_ERROR("%s: No valid attributes requested in GET_ELEMENT_ATTRIBUTES", - __func__); + log::error("No valid attributes requested in GET_ELEMENT_ATTRIBUTES"); send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode); return; @@ -1707,9 +1697,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, case AVRC_PDU_REGISTER_NOTIFICATION: { if (pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED && pavrc_cmd->reg_notif.param == 0) { - LOG_WARN( - "%s: Device registering position changed with illegal param 0.", - __func__); + log::warn("Device registering position changed with illegal param 0."); send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode); /* de-register this notification for a rejected response */ @@ -1722,7 +1710,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, } break; case AVRC_PDU_INFORM_DISPLAY_CHARSET: { tAVRC_RESPONSE avrc_rsp; - LOG_VERBOSE("%s: AVRC_PDU_INFORM_DISPLAY_CHARSET", __func__); + log::verbose("AVRC_PDU_INFORM_DISPLAY_CHARSET"); if (p_dev->rc_connected) { memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP)); avrc_rsp.inform_charset.opcode = @@ -1782,8 +1770,8 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, } break; case AVRC_PDU_REQUEST_CONTINUATION_RSP: { - LOG_VERBOSE("%s() REQUEST CONTINUATION: target_pdu: 0x%02d", __func__, - pavrc_cmd->continu.target_pdu); + log::verbose("REQUEST CONTINUATION: target_pdu: 0x{:02d}", + pavrc_cmd->continu.target_pdu); tAVRC_RESPONSE avrc_rsp; if (p_dev->rc_connected == TRUE) { memset(&(avrc_rsp.continu), 0, sizeof(tAVRC_NEXT_RSP)); @@ -1797,8 +1785,8 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, } break; case AVRC_PDU_ABORT_CONTINUATION_RSP: { - LOG_VERBOSE("%s() ABORT CONTINUATION: target_pdu: 0x%02d", __func__, - pavrc_cmd->abort.target_pdu); + log::verbose("ABORT CONTINUATION: target_pdu: 0x{:02d}", + pavrc_cmd->abort.target_pdu); tAVRC_RESPONSE avrc_rsp; if (p_dev->rc_connected == TRUE) { memset(&(avrc_rsp.abort), 0, sizeof(tAVRC_NEXT_RSP)); @@ -1830,14 +1818,13 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd, pavrc_cmd->get_attrs.attr_count, pavrc_cmd->get_attrs.p_attr_list, BTRC_MAX_ELEM_ATTR_SIZE, item_attrs); if (num_attr == 0) { - LOG_ERROR("%s: No valid attributes requested in GET_ITEM_ATTRIBUTES", - __func__); + log::error("No valid attributes requested in GET_ITEM_ATTRIBUTES"); send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode); return; } fill_pdu_queue(IDX_GET_ITEM_ATTR_RSP, ctype, label, true, p_dev); - LOG_VERBOSE("%s: GET_ITEM_ATTRIBUTES: num_attr: %d", __func__, num_attr); + log::verbose("GET_ITEM_ATTRIBUTES: num_attr: {}", num_attr); HAL_CBACK(bt_rc_callbacks, get_item_attr_cb, pavrc_cmd->get_attrs.scope, pavrc_cmd->get_attrs.uid, pavrc_cmd->get_attrs.uid_counter, num_attr, item_attrs, p_dev->rc_addr); @@ -1884,8 +1871,8 @@ static void btif_rc_ctrl_upstreams_rsp_cmd(uint8_t event, tAVRC_COMMAND* pavrc_cmd, uint8_t label, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: pdu: %s: handle: 0x%x", __func__, - dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle); + log::verbose("pdu: {}: handle: 0x{:x}", dump_rc_pdu(pavrc_cmd->pdu), + p_dev->rc_handle); switch (event) { case AVRC_PDU_SET_ABSOLUTE_VOLUME: do_in_jni_thread( @@ -1917,8 +1904,8 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event, tAVRC_RESPONSE* pavrc_resp, uint8_t ctype, uint8_t label, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: pdu: %s: handle: 0x%x ctype: %x label: %x", __func__, - dump_rc_pdu(pavrc_resp->pdu), p_dev->rc_handle, ctype, label); + log::verbose("pdu: {}: handle: 0x{:x} ctype: {:x} label: {:x}", + dump_rc_pdu(pavrc_resp->pdu), p_dev->rc_handle, ctype, label); switch (event) { case AVRC_PDU_REGISTER_NOTIFICATION: { @@ -1929,10 +1916,9 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event, } break; case AVRC_PDU_SET_ABSOLUTE_VOLUME: { - LOG_VERBOSE( - "%s: Set absolute volume change event received: volume: %d, ctype: " - "%d", - __func__, pavrc_resp->volume.volume, ctype); + log::verbose( + "Set absolute volume change event received: volume: {}, ctype: {}", + pavrc_resp->volume.volume, ctype); if (AVRC_RSP_ACCEPT == ctype) p_dev->rc_volume = pavrc_resp->volume.volume; HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->volume.volume, @@ -1958,7 +1944,7 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event, * ******************************************************************************/ static bt_status_t init(btrc_callbacks_t* callbacks) { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); bt_status_t result = BT_STATUS_SUCCESS; if (bt_rc_callbacks) return BT_STATUS_DONE; @@ -1983,7 +1969,7 @@ static bt_status_t init(btrc_callbacks_t* callbacks) { * ******************************************************************************/ static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks) { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); bt_status_t result = BT_STATUS_SUCCESS; if (bt_rc_ctrl_callbacks) return BT_STATUS_DONE; @@ -2000,7 +1986,7 @@ static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks) { static void rc_ctrl_procedure_complete(btif_rc_device_cb_t* p_dev) { if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -2030,7 +2016,7 @@ static bt_status_t get_play_status_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s: song len %d song pos %d", __func__, song_len, song_pos); + log::verbose("song len {} song pos {}", song_len, song_pos); CHECK_RC_CONNECTED(p_dev); memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP)); @@ -2072,13 +2058,12 @@ static bt_status_t get_element_attr_rsp(const RawAddress& bd_addr, tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE]; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); if (num_attr > BTRC_MAX_ELEM_ATTR_SIZE) { - LOG(WARNING) << __func__ - << " Exceeded number attributes:" << static_cast<int>(num_attr) - << " max:" << BTRC_MAX_ELEM_ATTR_SIZE; + log::warn("Exceeded number attributes:{} max:{}", + static_cast<int>(num_attr), BTRC_MAX_ELEM_ATTR_SIZE); num_attr = BTRC_MAX_ELEM_ATTR_SIZE; } memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr); @@ -2092,10 +2077,11 @@ static bt_status_t get_element_attr_rsp(const RawAddress& bd_addr, element_attrs[i].name.str_len = (uint16_t)strnlen((char*)p_attrs[i].text, BTRC_MAX_ATTR_STR_LEN); element_attrs[i].name.p_str = p_attrs[i].text; - LOG_VERBOSE("%s: attr_id: 0x%x, charset_id: 0x%x, str_len: %d, str: %s", - __func__, (unsigned int)element_attrs[i].attr_id, - element_attrs[i].name.charset_id, - element_attrs[i].name.str_len, element_attrs[i].name.p_str); + log::verbose("attr_id: 0x{:x}, charset_id: 0x{:x}, str_len: {}, str: {}", + (unsigned int)element_attrs[i].attr_id, + element_attrs[i].name.charset_id, + element_attrs[i].name.str_len, + reinterpret_cast<char const*>(element_attrs[i].name.p_str)); } avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR; } @@ -2126,12 +2112,11 @@ static bt_status_t register_notification_rsp( btrc_event_id_t event_id, btrc_notification_type_t type, btrc_register_notification_t* p_param) { tAVRC_RESPONSE avrc_rsp; - LOG_VERBOSE("%s: event_id: %s", __func__, - dump_rc_notification_event_id(event_id)); + log::verbose("event_id: {}", dump_rc_notification_event_id(event_id)); std::unique_lock<std::mutex> lock(btif_rc_cb.lock); if (event_id > MAX_RC_NOTIFICATIONS) { - LOG_ERROR("Invalid event id"); + log::error("Invalid event id"); return BT_STATUS_PARM_INVALID; } @@ -2146,20 +2131,20 @@ static bt_status_t register_notification_rsp( memset(&(avrc_rsp.reg_notif.param), 0, sizeof(tAVRC_NOTIF_RSP_PARAM)); if (!(btif_rc_cb.rc_multi_cb[idx].rc_connected)) { - LOG_ERROR("%s: Avrcp device is not connected, handle: 0x%x", __func__, - btif_rc_cb.rc_multi_cb[idx].rc_handle); + log::error("Avrcp device is not connected, handle: 0x{:x}", + btif_rc_cb.rc_multi_cb[idx].rc_handle); continue; } if (!btif_rc_cb.rc_multi_cb[idx].rc_notif[event_id - 1].bNotify) { - LOG_WARN( - "%s: Avrcp Event id is not registered: event_id: %x, handle: 0x%x", - __func__, event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle); + log::warn( + "Avrcp Event id is not registered: event_id: {:x}, handle: 0x{:x}", + event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle); continue; } - LOG_VERBOSE("%s: Avrcp Event id is registered: event_id: %x handle: 0x%x", - __func__, event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle); + log::verbose("Avrcp Event id is registered: event_id: {:x} handle: 0x{:x}", + event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle); switch (event_id) { case BTRC_EVT_PLAY_STATUS_CHANGED: @@ -2190,7 +2175,7 @@ static bt_status_t register_notification_rsp( break; default: - LOG_WARN("%s: Unhandled event ID: 0x%x", __func__, event_id); + log::warn("Unhandled event ID: 0x{:x}", event_id); return BT_STATUS_UNHANDLED; } @@ -2234,13 +2219,12 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr, btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); btrc_folder_items_t* cur_item = NULL; - LOG_VERBOSE("%s: uid_counter %d num_items %d", __func__, uid_counter, - num_items); + log::verbose("uid_counter {} num_items {}", uid_counter, num_items); CHECK_RC_CONNECTED(p_dev); /* check if rsp to previous cmd was completed */ if (!p_dev->rc_pdu_info[IDX_GET_FOLDER_ITEMS_RSP].is_rsp_pending) { - LOG_WARN("%s: Not sending response as no PDU was registered", __func__); + log::warn("Not sending response as no PDU was registered"); return BT_STATUS_UNHANDLED; } @@ -2252,9 +2236,9 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr, avrc_rsp.get_items.status = status_code_map[rsp_status]; if (avrc_rsp.get_items.status != AVRC_STS_NO_ERROR) { - LOG_WARN( - "%s: Error in parsing the received getfolderitems cmd. status: 0x%02x", - __func__, avrc_rsp.get_items.status); + log::warn( + "Error in parsing the received getfolderitems cmd. status: 0x{:02x}", + avrc_rsp.get_items.status); status = avrc_rsp.get_items.status; } else { avrc_rsp.get_items.uid_counter = uid_counter; @@ -2313,8 +2297,8 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr, } break; default: { - LOG_ERROR("%s: Unknown item_type: %d. Internal Error", __func__, - p_items->item_type); + log::error("Unknown item_type: {}. Internal Error", + p_items->item_type); status = AVRC_STS_INTERNAL_ERR; } break; } @@ -2330,10 +2314,10 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr, } int len_before = p_msg ? p_msg->len : 0; - LOG_VERBOSE("%s: item_cnt: %d len: %d", __func__, item_cnt, len_before); + log::verbose("item_cnt: {} len: {}", item_cnt, len_before); status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg); - LOG_VERBOSE("%s: Build rsp status: %d len: %d", __func__, status, - (p_msg ? p_msg->len : 0)); + log::verbose("Build rsp status: {} len: {}", status, + (p_msg ? p_msg->len : 0)); int len_after = p_msg ? p_msg->len : 0; if (status != AVRC_STS_NO_ERROR || len_before == len_after) { /* Error occured in build response or we ran out of buffer so break the @@ -2355,8 +2339,8 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr, p_msg); } else /* Error occured, send reject response */ { - LOG_ERROR("%s: Error status: 0x%02X. Sending reject rsp", __func__, - avrc_rsp.rsp.status); + log::error("Error status: 0x{:02X}. Sending reject rsp", + avrc_rsp.rsp.status); send_reject_response( p_dev->rc_handle, p_dev->rc_pdu_info[IDX_GET_FOLDER_ITEMS_RSP].label, avrc_rsp.pdu, avrc_rsp.get_items.status, avrc_rsp.get_items.opcode); @@ -2387,7 +2371,7 @@ static bt_status_t set_addressed_player_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.addr_player.pdu = AVRC_PDU_SET_ADDRESSED_PLAYER; @@ -2444,12 +2428,12 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr, avrc_rsp.br_player.pdu = AVRC_PDU_SET_BROWSED_PLAYER; avrc_rsp.br_player.opcode = opcode_from_pdu(AVRC_PDU_SET_BROWSED_PLAYER); - LOG_VERBOSE("%s: rsp_status: 0x%02X avrc_rsp.br_player.status: 0x%02X", - __func__, rsp_status, avrc_rsp.br_player.status); + log::verbose("rsp_status: 0x{:02X} avrc_rsp.br_player.status: 0x{:02X}", + rsp_status, avrc_rsp.br_player.status); /* check if rsp to previous cmd was completed */ if (!p_dev->rc_pdu_info[IDX_SET_BROWSED_PLAYER_RSP].is_rsp_pending) { - LOG_WARN("%s: Not sending response as no PDU was registered", __func__); + log::warn("Not sending response as no PDU was registered"); return BT_STATUS_UNHANDLED; } @@ -2459,15 +2443,15 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr, avrc_rsp.br_player.folder_depth = folder_depth; avrc_rsp.br_player.p_folders = (tAVRC_NAME*)p_folders; - LOG_VERBOSE("%s: folder_depth: 0x%02X num_items: %d", __func__, - folder_depth, num_items); + log::verbose("folder_depth: 0x{:02X} num_items: {}", folder_depth, + num_items); if (folder_depth > 0) { /* Iteratively build response for all folders across folder depth upto * current path */ avrc_rsp.br_player.folder_depth = 1; for (item_cnt = 0; item_cnt < folder_depth; item_cnt++) { - LOG_VERBOSE("%s: iteration: %d", __func__, item_cnt); + log::verbose("iteration: {}", item_cnt); item.str_len = p_folders[item_cnt].str_len; item.p_str = p_folders[item_cnt].p_str; avrc_rsp.br_player.p_folders = &item; @@ -2475,7 +2459,7 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr, /* Add current item to buffer and build response */ status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg); if (AVRC_STS_NO_ERROR != status) { - LOG_WARN("%s: Build rsp status: %d", __func__, status); + log::warn("Build rsp status: {}", status); /* if the build fails, it is likely that we ran out of buffer. so if * we have * some items to send, reset this error to no error for sending what we @@ -2495,9 +2479,9 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr, avrc_rsp.br_player.status = status; } else /* error received from above layer */ { - LOG_WARN( - "%s: Error in parsing the received setbrowsed command. status: 0x%02x", - __func__, avrc_rsp.br_player.status); + log::warn( + "Error in parsing the received setbrowsed command. status: 0x{:02x}", + avrc_rsp.br_player.status); status = avrc_rsp.br_player.status; } @@ -2510,8 +2494,8 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr, p_msg); } else /* Error occured, send reject response */ { - LOG_ERROR("%s: Error status: 0x%02X. Sending reject rsp", __func__, - avrc_rsp.br_player.status); + log::error("Error status: 0x{:02X}. Sending reject rsp", + avrc_rsp.br_player.status); send_reject_response( p_dev->rc_handle, p_dev->rc_pdu_info[IDX_SET_BROWSED_PLAYER_RSP].label, avrc_rsp.pdu, avrc_rsp.br_player.status, avrc_rsp.get_items.opcode); @@ -2543,7 +2527,7 @@ static bt_status_t change_path_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.chg_path.pdu = AVRC_PDU_CHANGE_PATH; @@ -2576,7 +2560,7 @@ static bt_status_t search_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.search.pdu = AVRC_PDU_SEARCH; @@ -2611,7 +2595,7 @@ static bt_status_t get_item_attr_rsp(const RawAddress& bd_addr, tAVRC_ATTR_ENTRY item_attrs[BTRC_MAX_ELEM_ATTR_SIZE]; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); memset(item_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr); @@ -2651,7 +2635,7 @@ static bt_status_t add_to_now_playing_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.add_to_play.pdu = AVRC_PDU_ADD_TO_NOW_PLAYING; @@ -2683,7 +2667,7 @@ static bt_status_t play_item_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.play_item.pdu = AVRC_PDU_PLAY_ITEM; @@ -2717,7 +2701,7 @@ static bt_status_t get_total_num_of_items_rsp(const RawAddress& bd_addr, tAVRC_RESPONSE avrc_rsp; btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); avrc_rsp.get_num_of_items.pdu = AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS; @@ -2751,7 +2735,7 @@ static bt_status_t get_total_num_of_items_rsp(const RawAddress& bd_addr, * **************************************************************************/ static bt_status_t set_volume(uint8_t volume) { - LOG_VERBOSE("%s: volume: %d", __func__, volume); + log::verbose("volume: {}", volume); tAVRC_STS status = BT_STATUS_UNSUPPORTED; for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) { @@ -2760,8 +2744,7 @@ static bt_status_t set_volume(uint8_t volume) { if (p_dev->rc_volume == volume) { status = BT_STATUS_DONE; - LOG_ERROR("%s: volume value already set earlier: 0x%02x", __func__, - volume); + log::error("volume value already set earlier: 0x{:02x}", volume); continue; } @@ -2779,8 +2762,7 @@ static bt_status_t set_volume(uint8_t volume) { if (!(p_dev->rc_features & BTA_AV_FEAT_ADV_CTRL)) continue; - LOG_VERBOSE("%s: Peer supports absolute volume. newVolume: %d", __func__, - volume); + log::verbose("Peer supports absolute volume. newVolume: {}", volume); tAVRC_COMMAND avrc_cmd = {.volume = {.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME, .status = AVRC_STS_NO_ERROR, @@ -2789,8 +2771,8 @@ static bt_status_t set_volume(uint8_t volume) { BT_HDR* p_msg = NULL; if (AVRC_BldCommand(&avrc_cmd, &p_msg) != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: failed to build absolute volume command. status: 0x%02x", - __func__, status); + log::error("failed to build absolute volume command. status: 0x{:02x}", + status); status = BT_STATUS_FAIL; continue; } @@ -2806,14 +2788,13 @@ static bt_status_t set_volume(uint8_t volume) { if (tran_status != BT_STATUS_SUCCESS || !p_transaction) { osi_free_and_reset((void**)&p_msg); - LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__, - dump_rc_pdu(avrc_cmd.pdu), tran_status); + log::error("failed to get label, pdu_id={}, status=0x{:02x}", + dump_rc_pdu(avrc_cmd.pdu), tran_status); status = BT_STATUS_FAIL; continue; } - LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__, - p_transaction->label); + log::verbose("msgreq being sent out with label: {}", p_transaction->label); BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_CTRL, p_msg); status = BT_STATUS_SUCCESS; start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS); @@ -2833,7 +2814,7 @@ static bt_status_t set_volume(uint8_t volume) { static void register_volumechange(btif_rc_device_cb_t* p_dev) { if (p_dev == nullptr) { - LOG_ERROR("%s: device was null", __func__); + log::error("device was null"); return; } @@ -2854,8 +2835,7 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) { } else { p_transaction = get_transaction_by_lbl(p_dev, p_dev->rc_vol_label); if (NULL != p_transaction) { - LOG_VERBOSE("%s: already in progress for label: %d", __func__, - p_dev->rc_vol_label); + log::verbose("already in progress for label: {}", p_dev->rc_vol_label); return; } status = get_transaction(p_dev, context, &p_transaction); @@ -2864,11 +2844,11 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) { if (BT_STATUS_SUCCESS == status && NULL != p_transaction) { p_dev->rc_vol_label = p_transaction->label; } else { - LOG_ERROR("%s: failed to get a transaction label", __func__); + log::error("failed to get a transaction label"); return; } - LOG_VERBOSE("%s: label: %d", __func__, p_dev->rc_vol_label); + log::verbose("label: {}", p_dev->rc_vol_label); avrc_cmd.cmd.opcode = 0x00; avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION; @@ -2880,9 +2860,9 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) { if (AVRC_STS_NO_ERROR == BldResp && p_msg) { BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_NOTIF, p_msg); - LOG_VERBOSE("%s: BTA_AvMetaCmd called", __func__); + log::verbose("BTA_AvMetaCmd called"); } else { - LOG_ERROR("%s: failed to build command: %d", __func__, BldResp); + log::error("failed to build command: {}", BldResp); } } @@ -2901,7 +2881,7 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg, uint8_t scratch_buf[512] = {0}; tAVRC_STS status = BT_STATUS_UNSUPPORTED; - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); if (AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode && (AVRC_RSP_CHANGED == pmeta_msg->code || @@ -2910,9 +2890,9 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg, AVRC_RSP_NOT_IMPL == pmeta_msg->code)) { status = AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, sizeof(scratch_buf)); - LOG_VERBOSE( - "%s: code:%d, event ID: %d, PDU: %x, parsing status: %d, label: %d", - __func__, pmeta_msg->code, avrc_response.reg_notif.event_id, + log::verbose( + "code:{}, event ID: {}, PDU: {:x}, parsing status: {}, label: {}", + pmeta_msg->code, avrc_response.reg_notif.event_id, avrc_response.reg_notif.pdu, status, pmeta_msg->label); if (status != AVRC_STS_NO_ERROR) { @@ -2932,9 +2912,9 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg, p_dev->rc_vol_label != pmeta_msg->label) { // Just discard the message, if the device sends back with an incorrect // label - LOG_VERBOSE( - "%s: Discarding register notification in rsp.code: %d and label: %d", - __func__, pmeta_msg->code, pmeta_msg->label); + log::verbose( + "Discarding register notification in rsp.code: {} and label: {}", + pmeta_msg->code, pmeta_msg->label); return; } @@ -2942,16 +2922,16 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg, AVRC_EVT_VOLUME_CHANGE == avrc_response.reg_notif.event_id && (AVRC_RSP_REJ == pmeta_msg->code || AVRC_RSP_NOT_IMPL == pmeta_msg->code)) { - LOG_VERBOSE("%s remove AbsoluteVolume feature flag.", __func__); + log::verbose("remove AbsoluteVolume feature flag."); p_dev->rc_features &= ~BTA_AV_FEAT_ADV_CTRL; handle_rc_features(p_dev); return; } } else { - LOG_VERBOSE( - "%s: Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not " + log::verbose( + "Received vendor dependent in adv ctrl rsp. code: {} len: {}. Not " "processing it.", - __func__, pmeta_msg->code, pmeta_msg->len); + pmeta_msg->code, pmeta_msg->len); return; } @@ -2966,8 +2946,8 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg, release_transaction(p_dev, pmeta_msg->label); } - LOG_VERBOSE("%s: Passing received metamsg response to app. pdu: %s", __func__, - dump_rc_pdu(avrc_response.pdu)); + log::verbose("Passing received metamsg response to app. pdu: {}", + dump_rc_pdu(avrc_response.pdu)); btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code, pmeta_msg->label, p_dev); } @@ -3008,7 +2988,7 @@ static void rc_notification_interim_timeout(btif_rc_device_cb_t* p_dev, uint8_t event_id) { /* Device disconnections clear the event list but can't free the timer */ if (p_dev == NULL || p_dev->rc_supported_event_list == NULL) { - LOG_WARN("%s: timeout for null device or event list", __func__); + log::warn("timeout for null device or event list"); return; } @@ -3063,7 +3043,7 @@ static void register_for_event_notification(btif_rc_supported_event_t* p_event, bt_status_t status = register_notification_cmd(p_event->event_id, interval_in_seconds, p_dev); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s: failed, status=%d", __func__, status); + log::error("failed, status={}", status); return; } @@ -3100,8 +3080,8 @@ static bt_status_t build_and_send_vendor_cmd(tAVRC_COMMAND* avrc_cmd, bt_status_t tran_status = get_transaction(p_dev, context, &p_transaction); if (BT_STATUS_SUCCESS != tran_status || p_transaction == NULL) { - LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__, - dump_rc_pdu(avrc_cmd->pdu), tran_status); + log::error("failed to get label, pdu_id={}, status=0x{:02x}", + dump_rc_pdu(avrc_cmd->pdu), tran_status); return BT_STATUS_FAIL; } @@ -3109,14 +3089,14 @@ static bt_status_t build_and_send_vendor_cmd(tAVRC_COMMAND* avrc_cmd, tAVRC_STS status = AVRC_BldCommand(avrc_cmd, &p_msg); if (status == AVRC_STS_NO_ERROR && p_msg != NULL) { uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset; - LOG_VERBOSE("%s: %s msgreq being sent out with label: %d", __func__, - dump_rc_pdu(avrc_cmd->pdu), p_transaction->label); + log::verbose("{} msgreq being sent out with label: {}", + dump_rc_pdu(avrc_cmd->pdu), p_transaction->label); BTA_AvVendorCmd(p_dev->rc_handle, p_transaction->label, cmd_code, data_start, p_msg->len); status = BT_STATUS_SUCCESS; start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS); } else { - LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status); + log::error("failed to build command. status: 0x{:02x}", status); release_transaction(p_dev, p_transaction->label); } osi_free(p_msg); @@ -3146,21 +3126,21 @@ static bt_status_t build_and_send_browsing_cmd(tAVRC_COMMAND* avrc_cmd, bt_status_t tran_status = get_transaction(p_dev, context, &p_transaction); if (tran_status != BT_STATUS_SUCCESS || p_transaction == NULL) { - LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__, - dump_rc_pdu(avrc_cmd->pdu), tran_status); + log::error("failed to get label, pdu_id={}, status=0x{:02x}", + dump_rc_pdu(avrc_cmd->pdu), tran_status); return BT_STATUS_FAIL; } BT_HDR* p_msg = NULL; tAVRC_STS status = AVRC_BldCommand(avrc_cmd, &p_msg); if (status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: failed to build command status %d", __func__, status); + log::error("failed to build command status {}", status); release_transaction(p_dev, p_transaction->label); return BT_STATUS_FAIL; } - LOG_VERBOSE("%s: Send pdu_id=%s, label=%d", __func__, - dump_rc_pdu(avrc_cmd->pdu), p_transaction->label); + log::verbose("Send pdu_id={}, label={}", dump_rc_pdu(avrc_cmd->pdu), + p_transaction->label); BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_CTRL, p_msg); start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS); return BT_STATUS_SUCCESS; @@ -3184,7 +3164,7 @@ static void handle_get_capability_response(tBTA_AV_META_MSG* pmeta_msg, /* Todo: Do we need to retry on command timeout */ if (p_rsp->status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: Error capability response: 0x%02X", __func__, p_rsp->status); + log::error("Error capability response: 0x{:02X}", p_rsp->status); return; } @@ -3226,9 +3206,9 @@ static void handle_get_capability_response(tBTA_AV_META_MSG* pmeta_msg, } } else if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) { getcapabilities_cmd(AVRC_CAP_EVENTS_SUPPORTED, p_dev); - LOG_VERBOSE("%s: AVRC_CAP_COMPANY_ID: ", __func__); + log::verbose("AVRC_CAP_COMPANY_ID:"); for (xx = 0; xx < p_rsp->count; xx++) { - LOG_VERBOSE("%s: company_id: %d", __func__, p_rsp->param.company_id[xx]); + log::verbose("company_id: {}", p_rsp->param.company_id[xx]); } } } @@ -3268,16 +3248,14 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } if (btif_av_src_sink_coexist_enabled() && p_rsp->event_id == AVRC_EVT_VOLUME_CHANGE) { - LOG_ERROR( - "%s: legacy TG don't handle absolute volume change. leave it to new " - "avrcp", - __func__); + log::error( + "legacy TG don't handle absolute volume change. leave it to new avrcp"); return; } @@ -3288,7 +3266,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_supported_event_t* p_event; list_node_t* node; - LOG_VERBOSE("%s: Interim response: 0x%2X ", __func__, p_rsp->event_id); + log::verbose("Interim response: 0x{:2X}", p_rsp->event_id); switch (p_rsp->event_id) { case AVRC_EVT_PLAY_STATUS_CHANGE: get_play_status_cmd(p_dev); @@ -3323,7 +3301,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, break; case AVRC_EVT_AVAL_PLAYERS_CHANGE: - LOG_VERBOSE("%s: AVRC_EVT_AVAL_PLAYERS_CHANGE", __func__); + log::verbose("AVRC_EVT_AVAL_PLAYERS_CHANGE"); do_in_jni_thread( FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->available_player_changed_cb, @@ -3352,8 +3330,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, case AVRC_EVT_BATTERY_STATUS_CHANGE: case AVRC_EVT_SYSTEM_STATUS_CHANGE: default: - LOG_ERROR("%s: Unhandled interim response: 0x%2X", __func__, - p_rsp->event_id); + log::error("Unhandled interim response: 0x{:2X}", p_rsp->event_id); return; } @@ -3381,8 +3358,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, if (p_dev->rc_features & BTA_AV_FEAT_APP_SETTING) { list_player_app_setting_attrib_cmd(p_dev); } else { - LOG_VERBOSE("%s: App setting not supported, complete procedure", - __func__); + log::verbose("App setting not supported, complete procedure"); rc_ctrl_procedure_complete(p_dev); } } @@ -3390,8 +3366,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_supported_event_t* p_event; list_node_t* node; - LOG_VERBOSE("%s: Notification completed: 0x%2X ", __func__, - p_rsp->event_id); + log::verbose("Notification completed: 0x{:2X}", p_rsp->event_id); node = list_begin(p_dev->rc_supported_event_list); @@ -3463,8 +3438,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg, case AVRC_EVT_BATTERY_STATUS_CHANGE: case AVRC_EVT_SYSTEM_STATUS_CHANGE: default: - LOG_ERROR("%s: Unhandled completion response: 0x%2X", __func__, - p_rsp->event_id); + log::error("Unhandled completion response: 0x{:2X}", p_rsp->event_id); return; } } @@ -3486,8 +3460,8 @@ static void handle_app_attr_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL || p_rsp->status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: Error getting Player application settings: 0x%2X", __func__, - p_rsp->status); + log::error("Error getting Player application settings: 0x{:2X}", + p_rsp->status); rc_ctrl_procedure_complete(p_dev); return; } @@ -3514,7 +3488,7 @@ static void handle_app_attr_response(tBTA_AV_META_MSG* pmeta_msg, list_player_app_setting_value_cmd(p_dev->rc_app_settings.attrs[0].attr_id, p_dev); } else { - LOG_ERROR("%s: No Player application settings found", __func__); + log::error("No Player application settings found"); } } @@ -3540,8 +3514,7 @@ static void handle_app_val_response(tBTA_AV_META_MSG* pmeta_msg, /* Todo: Do we need to retry on command timeout */ if (p_dev == NULL || p_rsp->status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: Error fetching attribute values: 0x%02X", __func__, - p_rsp->status); + log::error("Error fetching attribute values: 0x{:02X}", p_rsp->status); return; } @@ -3616,13 +3589,12 @@ static void handle_app_cur_val_response(tBTA_AV_META_MSG* pmeta_msg, /* Todo: Do we need to retry on command timeout */ if (p_rsp->status != AVRC_STS_NO_ERROR) { - LOG_ERROR("%s: Error fetching current settings: 0x%02X", __func__, - p_rsp->status); + log::error("Error fetching current settings: 0x{:02X}", p_rsp->status); return; } p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Error in getting Device Address", __func__); + log::error("Error in getting Device Address"); osi_free_and_reset((void**)&p_rsp->p_vals); return; } @@ -3671,7 +3643,7 @@ static void handle_app_attr_txt_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -3681,8 +3653,7 @@ static void handle_app_attr_txt_response(tBTA_AV_META_MSG* pmeta_msg, if (p_rsp->status != AVRC_STS_NO_ERROR) { uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; - LOG_ERROR("%s: Error fetching attribute text: 0x%02X", __func__, - p_rsp->status); + log::error("Error fetching attribute text: 0x{:02X}", p_rsp->status); /* Not able to fetch Text for extended Menu, skip the process * and cleanup used memory. Proceed to get the current settings * for standard attributes. @@ -3751,7 +3722,7 @@ static void handle_app_attr_val_txt_response( btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -3761,8 +3732,7 @@ static void handle_app_attr_val_txt_response( if (p_rsp->status != AVRC_STS_NO_ERROR) { uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; - LOG_ERROR("%s: Error fetching attribute value text: 0x%02X", __func__, - p_rsp->status); + log::error("Error fetching attribute value text: 0x{:02X}", p_rsp->status); /* Not able to fetch Text for extended Menu, skip the process * and cleanup used memory. Proceed to get the current settings @@ -3796,8 +3766,8 @@ static void handle_app_attr_val_txt_response( } if (p_app_settings->ext_val_index >= AVRC_MAX_APP_ATTR_SIZE) { - LOG_ERROR("ext_val_index is 0x%02x, overflow!", - p_app_settings->ext_val_index); + log::error("ext_val_index is 0x{:02x}, overflow!", + p_app_settings->ext_val_index); return; } @@ -3888,7 +3858,7 @@ static void handle_set_app_attr_val_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -3925,7 +3895,7 @@ static void handle_get_metadata_attr_response(tBTA_AV_META_MSG* pmeta_msg, (btrc_element_attr_val_t*)osi_calloc(buf_size); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -3954,8 +3924,7 @@ static void handle_get_metadata_attr_response(tBTA_AV_META_MSG* pmeta_msg, const uint8_t attr_list_size = get_requested_attributes_list_size(p_dev); get_metadata_attribute_cmd(attr_list_size, attr_list, p_dev); } else { - LOG_ERROR("%s: Error in get element attr procedure: %d", __func__, - p_rsp->status); + log::error("Error in get element attr procedure: {}", p_rsp->status); } } @@ -3975,7 +3944,7 @@ static void handle_get_playstatus_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -3990,8 +3959,7 @@ static void handle_get_playstatus_response(tBTA_AV_META_MSG* pmeta_msg, base::BindOnce(bt_rc_ctrl_callbacks->play_position_changed_cb, p_dev->rc_addr, p_rsp->song_len, p_rsp->song_pos)); } else { - LOG_ERROR("%s: Error in get play status procedure: %d", __func__, - p_rsp->status); + log::error("Error in get play status procedure: {}", p_rsp->status); } } @@ -4011,7 +3979,7 @@ static void handle_set_addressed_player_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -4021,8 +3989,7 @@ static void handle_set_addressed_player_response(tBTA_AV_META_MSG* pmeta_msg, FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->set_addressed_player_cb, p_dev->rc_addr, p_rsp->status)); } else { - LOG_ERROR("%s: Error in get play status procedure %d", __func__, - p_rsp->status); + log::error("Error in get play status procedure {}", p_rsp->status); } } @@ -4050,10 +4017,10 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg, for (uint8_t i = 0; i < item_count; i++) { const tAVRC_ITEM* avrc_item = &(p_rsp->p_item_list[i]); btrc_folder_items_t* btrc_item = &(btrc_items[i]); - LOG_VERBOSE("%s folder item type %d", __func__, avrc_item->item_type); + log::verbose("folder item type {}", avrc_item->item_type); switch (avrc_item->item_type) { case AVRC_ITEM_MEDIA: - LOG_VERBOSE("%s setting type to %d", __func__, BTRC_ITEM_MEDIA); + log::verbose("setting type to {}", BTRC_ITEM_MEDIA); /* Allocate Space for Attributes */ btrc_item->media.num_attrs = avrc_item->u.media.attr_count; btrc_item->media.p_attrs = (btrc_element_attr_val_t*)osi_malloc( @@ -4062,18 +4029,18 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg, break; case AVRC_ITEM_FOLDER: - LOG_VERBOSE("%s setting type to BTRC_ITEM_FOLDER", __func__); + log::verbose("setting type to BTRC_ITEM_FOLDER"); get_folder_item_type_folder(avrc_item, btrc_item); break; case AVRC_ITEM_PLAYER: - LOG_VERBOSE("%s setting type to BTRC_ITEM_PLAYER", __func__); + log::verbose("setting type to BTRC_ITEM_PLAYER"); get_folder_item_type_player(avrc_item, btrc_item); break; default: - LOG_ERROR("%s cannot understand folder item type %d", __func__, - avrc_item->item_type); + log::error("cannot understand folder item type {}", + avrc_item->item_type); } } @@ -4096,9 +4063,9 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg, do_in_jni_thread(FROM_HERE, base::BindOnce(cleanup_btrc_folder_items, btrc_items, item_count)); - LOG_VERBOSE("%s get_folder_items_cb sent to JNI thread", __func__); + log::verbose("get_folder_items_cb sent to JNI thread"); } else { - LOG_ERROR("%s: Error %d", __func__, p_rsp->status); + log::error("Error {}", p_rsp->status); do_in_jni_thread( FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->get_folder_items_cb, p_dev->rc_addr, (btrc_status_t)p_rsp->status, @@ -4126,7 +4093,7 @@ static void cleanup_btrc_folder_items(btrc_folder_items_t* btrc_items, /*Nothing to free*/ break; default: - LOG_WARN("%s free unspecified type", __func__); + log::warn("free unspecified type"); } } osi_free(btrc_items); @@ -4165,8 +4132,8 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item, btrc_item_media->charset_id = avrc_item_media->name.charset_id; /* Copy the name */ - LOG_VERBOSE("%s max len %d str len %d", __func__, BTRC_MAX_ATTR_STR_LEN, - avrc_item_media->name.str_len); + log::verbose("max len {} str len {}", BTRC_MAX_ATTR_STR_LEN, + avrc_item_media->name.str_len); memset(btrc_item_media->name, 0, BTRC_MAX_ATTR_STR_LEN * sizeof(uint8_t)); memcpy(btrc_item_media->name, avrc_item_media->name.p_str, sizeof(uint8_t) * (avrc_item_media->name.str_len)); @@ -4176,7 +4143,7 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item, btrc_element_attr_val_t* btrc_attr_pair = &(btrc_item_media->p_attrs[i]); tAVRC_ATTR_ENTRY* avrc_attr_pair = &(avrc_item_media->p_attr_list[i]); - LOG_VERBOSE("%s media attr id 0x%x", __func__, avrc_attr_pair->attr_id); + log::verbose("media attr id 0x{:x}", avrc_attr_pair->attr_id); switch (avrc_attr_pair->attr_id) { case AVRC_MEDIA_ATTR_ID_TITLE: @@ -4204,8 +4171,7 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item, btrc_attr_pair->attr_id = BTRC_MEDIA_ATTR_ID_COVER_ARTWORK_HANDLE; break; default: - LOG_ERROR("%s invalid media attr id: 0x%x", __func__, - avrc_attr_pair->attr_id); + log::error("invalid media attr id: 0x{:x}", avrc_attr_pair->attr_id); btrc_attr_pair->attr_id = BTRC_MEDIA_ATTR_ID_INVALID; } @@ -4263,8 +4229,8 @@ void get_folder_item_type_folder(const tAVRC_ITEM* avrc_item, btrc_item_folder->playable = avrc_item_folder->playable; /* Copy name */ - LOG_VERBOSE("%s max len %d str len %d", __func__, BTRC_MAX_ATTR_STR_LEN, - avrc_item_folder->name.str_len); + log::verbose("max len {} str len {}", BTRC_MAX_ATTR_STR_LEN, + avrc_item_folder->name.str_len); memset(btrc_item_folder->name, 0, BTRC_MAX_ATTR_STR_LEN * sizeof(uint8_t)); memcpy(btrc_item_folder->name, avrc_item_folder->name.p_str, avrc_item_folder->name.str_len * sizeof(uint8_t)); @@ -4319,7 +4285,7 @@ static void handle_change_path_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Invalid rc handle", __func__); + log::error("Invalid rc handle"); return; } @@ -4328,8 +4294,7 @@ static void handle_change_path_response(tBTA_AV_META_MSG* pmeta_msg, base::BindOnce(bt_rc_ctrl_callbacks->change_folder_path_cb, p_dev->rc_addr, p_rsp->num_items)); } else { - LOG_ERROR("%s error in handle_change_path_response %d", __func__, - p_rsp->status); + log::error("error in handle_change_path_response {}", p_rsp->status); } } @@ -4348,7 +4313,7 @@ static void handle_set_browsed_player_response(tBTA_AV_META_MSG* pmeta_msg, btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: Invalid rc handle", __func__); + log::error("Invalid rc handle"); return; } @@ -4358,7 +4323,7 @@ static void handle_set_browsed_player_response(tBTA_AV_META_MSG* pmeta_msg, base::BindOnce(bt_rc_ctrl_callbacks->set_browsed_player_cb, p_dev->rc_addr, p_rsp->num_items, p_rsp->folder_depth)); } else { - LOG_ERROR("%s error %d", __func__, p_rsp->status); + log::error("error {}", p_rsp->status); } } @@ -4375,7 +4340,7 @@ static void clear_cmd_timeout(btif_rc_device_cb_t* p_dev, uint8_t label) { p_txn = get_transaction_by_lbl(p_dev, label); if (p_txn == NULL) { - LOG_ERROR("%s: Error in transaction label lookup", __func__); + log::error("Error in transaction label lookup"); return; } @@ -4402,8 +4367,8 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) { tAVRC_STS status; btif_rc_device_cb_t* p_dev = NULL; - LOG_VERBOSE("%s: opcode: %d rsp_code: %d ", __func__, - pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code); + log::verbose("opcode: {} rsp_code: {}", pmeta_msg->p_msg->hdr.opcode, + pmeta_msg->code); p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle); status = AVRC_Ctrl_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, @@ -4411,8 +4376,8 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) { if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode) && (pmeta_msg->code >= AVRC_RSP_NOT_IMPL) && (pmeta_msg->code <= AVRC_RSP_INTERIM)) { - LOG_VERBOSE("%s parse status %d pdu = %d rsp_status = %d", __func__, status, - avrc_response.pdu, pmeta_msg->p_msg->vendor.hdr.ctype); + log::verbose("parse status {} pdu = {} rsp_status = {}", status, + avrc_response.pdu, pmeta_msg->p_msg->vendor.hdr.ctype); switch (avrc_response.pdu) { case AVRC_PDU_REGISTER_NOTIFICATION: @@ -4468,7 +4433,7 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) { break; } } else if (AVRC_OP_BROWSE == pmeta_msg->p_msg->hdr.opcode) { - LOG_VERBOSE("%s AVRC_OP_BROWSE pdu %d", __func__, avrc_response.pdu); + log::verbose("AVRC_OP_BROWSE pdu {}", avrc_response.pdu); /* check what kind of command it is for browsing */ switch (avrc_response.pdu) { case AVRC_PDU_GET_FOLDER_ITEMS: @@ -4484,16 +4449,14 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) { handle_get_metadata_attr_response(pmeta_msg, &avrc_response.get_attrs); break; default: - LOG_ERROR("%s cannot handle browse pdu %d", __func__, - pmeta_msg->p_msg->hdr.opcode); + log::error("cannot handle browse pdu {}", pmeta_msg->p_msg->hdr.opcode); } } else { - LOG_VERBOSE( - "%s: Invalid Vendor Command code: %d len: %d. Not processing it.", - __func__, pmeta_msg->code, pmeta_msg->len); + log::verbose("Invalid Vendor Command code: {} len: {}. Not processing it.", + pmeta_msg->code, pmeta_msg->len); return; } - LOG_VERBOSE("%s: release transaction %d", __func__, pmeta_msg->label); + log::verbose("release transaction {}", pmeta_msg->label); release_transaction(p_dev, pmeta_msg->label); } @@ -4511,18 +4474,18 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { tAVRC_STS status = BT_STATUS_UNSUPPORTED; btif_rc_device_cb_t* p_dev = NULL; - LOG_VERBOSE("%s: opcode: %d rsp_code: %d", __func__, - pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code); + log::verbose("opcode: {} rsp_code: {}", pmeta_msg->p_msg->hdr.opcode, + pmeta_msg->code); status = AVRC_Ctrl_ParsCommand(pmeta_msg->p_msg, &avrc_cmd); if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode) && (pmeta_msg->code <= AVRC_CMD_GEN_INQ)) { - LOG_VERBOSE("%s Received vendor command.code %d, PDU %d label %d", __func__, - pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label); + log::verbose("Received vendor command.code {}, PDU {} label {}", + pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label); if (status != AVRC_STS_NO_ERROR) { /* return error */ - LOG_WARN("%s: Error in parsing received metamsg command. status: 0x%02x", - __func__, status); + log::warn("Error in parsing received metamsg command. status: 0x{:02x}", + status); if (true == btif_av_both_enable()) { if (AVRC_PDU_GET_CAPABILITIES == avrc_cmd.pdu || AVRC_PDU_GET_ELEMENT_ATTR == avrc_cmd.pdu || @@ -4536,25 +4499,24 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { } else { p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle); if (p_dev == NULL) { - LOG_ERROR("%s: avk rc meta msg cmd for Invalid rc handle", __func__); + log::error("avk rc meta msg cmd for Invalid rc handle"); return; } if (avrc_cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) { uint8_t event_id = avrc_cmd.reg_notif.event_id; - LOG_VERBOSE("%s: Register notification event_id: %s", __func__, - dump_rc_notification_event_id(event_id)); + log::verbose("Register notification event_id: {}", + dump_rc_notification_event_id(event_id)); } else if (avrc_cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME) { - LOG_VERBOSE("%s: Abs Volume Cmd Recvd", __func__); + log::verbose("Abs Volume Cmd Recvd"); } btif_rc_ctrl_upstreams_rsp_cmd(avrc_cmd.pdu, &avrc_cmd, pmeta_msg->label, p_dev); } } else { - LOG_VERBOSE( - "%s: Invalid Vendor Command code: %d len: %d. Not processing it.", - __func__, pmeta_msg->code, pmeta_msg->len); + log::verbose("Invalid Vendor Command code: {} len: {}. Not processing it.", + pmeta_msg->code, pmeta_msg->len); return; } } @@ -4569,7 +4531,7 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) { * **************************************************************************/ static void cleanup() { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); if (bt_rc_callbacks) { bt_rc_callbacks = NULL; } @@ -4580,7 +4542,7 @@ static void cleanup() { sizeof(btif_rc_cb.rc_multi_cb[idx])); } - LOG_VERBOSE("%s: completed", __func__); + log::verbose("completed"); } /*************************************************************************** @@ -4593,7 +4555,7 @@ static void cleanup() { * **************************************************************************/ static void cleanup_ctrl() { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); if (bt_rc_ctrl_callbacks) { bt_rc_ctrl_callbacks = NULL; @@ -4606,7 +4568,7 @@ static void cleanup_ctrl() { } memset(&btif_rc_cb.rc_multi_cb, 0, sizeof(btif_rc_cb.rc_multi_cb)); - LOG_VERBOSE("%s: completed", __func__); + log::verbose("completed"); } /*************************************************************************** @@ -4620,7 +4582,7 @@ static void cleanup_ctrl() { **************************************************************************/ static bt_status_t getcapabilities_cmd(uint8_t cap_id, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: cap_id: %d", __func__, cap_id); + log::verbose("cap_id: {}", cap_id); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -4643,7 +4605,7 @@ static bt_status_t getcapabilities_cmd(uint8_t cap_id, **************************************************************************/ static bt_status_t list_player_app_setting_attrib_cmd( btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -4665,7 +4627,7 @@ static bt_status_t list_player_app_setting_attrib_cmd( **************************************************************************/ static bt_status_t list_player_app_setting_value_cmd( uint8_t attrib_id, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: attrib_id: %d", __func__, attrib_id); + log::verbose("attrib_id: {}", attrib_id); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -4689,7 +4651,7 @@ static bt_status_t list_player_app_setting_value_cmd( static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, uint8_t* attrib_ids, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: num_attrib: %d", __func__, num_attrib); + log::verbose("num_attrib: {}", num_attrib); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -4716,10 +4678,10 @@ static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, * **************************************************************************/ static bt_status_t get_current_metadata_cmd(const RawAddress& bd_addr) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return BT_STATUS_FAIL; } const uint32_t* attr_list = get_requested_attributes_list(p_dev); @@ -4738,7 +4700,7 @@ static bt_status_t get_current_metadata_cmd(const RawAddress& bd_addr) { * **************************************************************************/ static bt_status_t get_playback_state_cmd(const RawAddress& bd_addr) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); return get_play_status_cmd(p_dev); } @@ -4759,7 +4721,7 @@ static bt_status_t get_playback_state_cmd(const RawAddress& bd_addr) { static bt_status_t get_now_playing_list_cmd(const RawAddress& bd_addr, uint32_t start_item, uint32_t end_item) { - LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item); + log::verbose("start, end: ({}, {})", start_item, end_item); return get_folder_items_cmd(bd_addr, AVRC_SCOPE_NOW_PLAYING, start_item, end_item); } @@ -4808,7 +4770,7 @@ static bt_status_t get_item_attribute_cmd(uint64_t uid, int scope, **************************************************************************/ static bt_status_t get_folder_list_cmd(const RawAddress& bd_addr, uint32_t start_item, uint32_t end_item) { - LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item); + log::verbose("start, end: ({}, {})", start_item, end_item); return get_folder_items_cmd(bd_addr, AVRC_SCOPE_FILE_SYSTEM, start_item, end_item); } @@ -4828,7 +4790,7 @@ static bt_status_t get_folder_list_cmd(const RawAddress& bd_addr, **************************************************************************/ static bt_status_t get_player_list_cmd(const RawAddress& bd_addr, uint32_t start_item, uint32_t end_item) { - LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item); + log::verbose("start, end: ({}, {})", start_item, end_item); return get_folder_items_cmd(bd_addr, AVRC_SCOPE_PLAYER_LIST, start_item, end_item); } @@ -4850,7 +4812,7 @@ static bt_status_t get_player_list_cmd(const RawAddress& bd_addr, **************************************************************************/ static bt_status_t change_folder_path_cmd(const RawAddress& bd_addr, uint8_t direction, uint8_t* uid) { - LOG_VERBOSE("%s: direction %d", __func__, direction); + log::verbose("direction {}", direction); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); CHECK_BR_CONNECTED(p_dev); @@ -4883,7 +4845,7 @@ static bt_status_t change_folder_path_cmd(const RawAddress& bd_addr, **************************************************************************/ static bt_status_t set_browsed_player_cmd(const RawAddress& bd_addr, uint16_t id) { - LOG_VERBOSE("%s: id %d", __func__, id); + log::verbose("id {}", id); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); CHECK_BR_CONNECTED(p_dev); @@ -4911,7 +4873,7 @@ static bt_status_t set_browsed_player_cmd(const RawAddress& bd_addr, ***************************************************************************/ static bt_status_t set_addressed_player_cmd(const RawAddress& bd_addr, uint16_t id) { - LOG_VERBOSE("%s: id %d", __func__, id); + log::verbose("id {}", id); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); @@ -4947,7 +4909,7 @@ static bt_status_t get_folder_items_cmd(const RawAddress& bd_addr, uint32_t end_item) { /* Check that both avrcp and browse channel are connected. */ btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); CHECK_BR_CONNECTED(p_dev); @@ -4979,7 +4941,7 @@ static bt_status_t change_player_app_setting(const RawAddress& bd_addr, uint8_t num_attrib, uint8_t* attrib_ids, uint8_t* attrib_vals) { - LOG_VERBOSE("%s: num_attrib: %d", __func__, num_attrib); + log::verbose("num_attrib: {}", num_attrib); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); @@ -5011,7 +4973,7 @@ static bt_status_t change_player_app_setting(const RawAddress& bd_addr, **************************************************************************/ static bt_status_t play_item_cmd(const RawAddress& bd_addr, uint8_t scope, uint8_t* uid, uint16_t uid_counter) { - LOG_VERBOSE("%s: scope %d uid_counter %d", __func__, scope, uid_counter); + log::verbose("scope {} uid_counter {}", scope, uid_counter); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); CHECK_BR_CONNECTED(p_dev); @@ -5038,7 +5000,7 @@ static bt_status_t play_item_cmd(const RawAddress& bd_addr, uint8_t scope, **************************************************************************/ static bt_status_t get_player_app_setting_attr_text_cmd( uint8_t* attrs, uint8_t num_attrs, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: num attrs: %d", __func__, num_attrs); + log::verbose("num attrs: {}", num_attrs); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -5064,7 +5026,7 @@ static bt_status_t get_player_app_setting_attr_text_cmd( **************************************************************************/ static bt_status_t get_player_app_setting_value_text_cmd( uint8_t* vals, uint8_t num_vals, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: num_vals: %d", __func__, num_vals); + log::verbose("num_vals: {}", num_vals); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -5091,8 +5053,7 @@ static bt_status_t get_player_app_setting_value_text_cmd( static bt_status_t register_notification_cmd(uint8_t event_id, uint32_t event_value, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: event_id: %d event_value %d", __func__, event_id, - event_value); + log::verbose("event_id: {} event_value {}", event_id, event_value); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -5120,8 +5081,8 @@ static bt_status_t register_notification_cmd(uint8_t event_id, static bt_status_t get_metadata_attribute_cmd(uint8_t num_attribute, const uint32_t* p_attr_ids, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: num_attribute: %d attribute_id: %d", __func__, num_attribute, - p_attr_ids[0]); + log::verbose("num_attribute: {} attribute_id: {}", num_attribute, + p_attr_ids[0]); // If browsing is connected then send the command out that channel if (p_dev->br_connected) { @@ -5146,8 +5107,8 @@ static bt_status_t get_metadata_attribute_cmd(uint8_t num_attribute, static bt_status_t get_element_attribute_cmd(uint8_t num_attribute, const uint32_t* p_attr_ids, btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s: num_attribute: %d attribute_id: %d", __func__, num_attribute, - p_attr_ids[0]); + log::verbose("num_attribute: {} attribute_id: {}", num_attribute, + p_attr_ids[0]); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; avrc_cmd.get_elem_attrs.opcode = AVRC_OP_VENDOR; @@ -5171,7 +5132,7 @@ static bt_status_t get_element_attribute_cmd(uint8_t num_attribute, * **************************************************************************/ static bt_status_t get_play_status_cmd(btif_rc_device_cb_t* p_dev) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); CHECK_RC_CONNECTED(p_dev); tAVRC_COMMAND avrc_cmd = {0}; @@ -5200,7 +5161,7 @@ static bt_status_t set_volume_rsp(const RawAddress& bd_addr, uint8_t abs_vol, CHECK_RC_CONNECTED(p_dev); - LOG_VERBOSE("%s: abs_vol: %d", __func__, abs_vol); + log::verbose("abs_vol: {}", abs_vol); avrc_rsp.volume.opcode = AVRC_OP_VENDOR; avrc_rsp.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME; @@ -5209,15 +5170,14 @@ static bt_status_t set_volume_rsp(const RawAddress& bd_addr, uint8_t abs_vol, status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg); if (status == AVRC_STS_NO_ERROR) { uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset; - LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__, - p_dev->rc_vol_label); + log::verbose("msgreq being sent out with label: {}", p_dev->rc_vol_label); if (p_msg != NULL) { BTA_AvVendorRsp(p_dev->rc_handle, label, AVRC_RSP_ACCEPT, data_start, p_msg->len, 0); status = BT_STATUS_SUCCESS; } } else { - LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status); + log::error("failed to build command. status: 0x{:02x}", status); } osi_free(p_msg); return (bt_status_t)status; @@ -5238,7 +5198,7 @@ static bt_status_t volume_change_notification_rsp( tAVRC_STS status = BT_STATUS_UNSUPPORTED; tAVRC_RESPONSE avrc_rsp; BT_HDR* p_msg = NULL; - LOG_VERBOSE("%s: rsp_type: %d abs_vol: %d", __func__, rsp_type, abs_vol); + log::verbose("rsp_type: {} abs_vol: {}", rsp_type, abs_vol); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); @@ -5252,7 +5212,7 @@ static bt_status_t volume_change_notification_rsp( status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg); if (status == AVRC_STS_NO_ERROR) { - LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__, label); + log::verbose("msgreq being sent out with label: {}", label); uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset; BTA_AvVendorRsp(p_dev->rc_handle, label, (rsp_type == BTRC_NOTIFICATION_TYPE_INTERIM) @@ -5261,7 +5221,7 @@ static bt_status_t volume_change_notification_rsp( data_start, p_msg->len, 0); status = BT_STATUS_SUCCESS; } else { - LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status); + log::error("failed to build command. status: 0x{:02x}", status); } osi_free(p_msg); @@ -5282,7 +5242,7 @@ static bt_status_t send_groupnavigation_cmd(const RawAddress& bd_addr, uint8_t key_state) { tAVRC_STS status = BT_STATUS_UNSUPPORTED; rc_transaction_t* p_transaction = NULL; - LOG_VERBOSE("%s: key-code: %d, key-state: %d", __func__, key_code, key_state); + log::verbose("key-code: {}, key-state: {}", key_code, key_state); btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); @@ -5305,16 +5265,16 @@ static bt_status_t send_groupnavigation_cmd(const RawAddress& bd_addr, AVRC_PASS_THRU_GROUP_LEN); status = BT_STATUS_SUCCESS; start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS); - LOG_VERBOSE("%s: Send command, key-code=%d, key-state=%d, label=%d", - __func__, key_code, key_state, p_transaction->label); + log::verbose("Send command, key-code={}, key-state={}, label={}", + key_code, key_state, p_transaction->label); } else { status = BT_STATUS_FAIL; - LOG_ERROR("%s: failed to get label, key-code=%d, key-state=%d, status=%d", - __func__, key_code, key_state, tran_status); + log::error("failed to get label, key-code={}, key-state={}, status={}", + key_code, key_state, tran_status); } } else { status = BT_STATUS_FAIL; - LOG_VERBOSE("%s: feature not supported", __func__); + log::verbose("feature not supported"); } return (bt_status_t)status; } @@ -5332,13 +5292,13 @@ static bt_status_t send_passthrough_cmd(const RawAddress& bd_addr, uint8_t key_code, uint8_t key_state) { tAVRC_STS status = BT_STATUS_UNSUPPORTED; btif_rc_device_cb_t* p_dev = NULL; - LOG_ERROR("%s: calling btif_rc_get_device_by_bda", __func__); + log::error("calling btif_rc_get_device_by_bda"); p_dev = btif_rc_get_device_by_bda(bd_addr); CHECK_RC_CONNECTED(p_dev); rc_transaction_t* p_transaction = NULL; - LOG_VERBOSE("%s: key-code: %d, key-state: %d", __func__, key_code, key_state); + log::verbose("key-code: {}, key-state: {}", key_code, key_state); if (p_dev->rc_features & BTA_AV_FEAT_RCTG) { rc_transaction_context_t context = { .rc_addr = p_dev->rc_addr, @@ -5351,16 +5311,16 @@ static bt_status_t send_passthrough_cmd(const RawAddress& bd_addr, (tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state); status = BT_STATUS_SUCCESS; start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS); - LOG_VERBOSE("%s: Send command, key-code=%d, key-state=%d, label=%d", - __func__, key_code, key_state, p_transaction->label); + log::verbose("Send command, key-code={}, key-state={}, label={}", + key_code, key_state, p_transaction->label); } else { status = BT_STATUS_FAIL; - LOG_ERROR("%s: failed to get label, key-code=%d, key-state=%d, status=%d", - __func__, key_code, key_state, tran_status); + log::error("failed to get label, key-code={}, key-state={}, status={}", + key_code, key_state, tran_status); } } else { status = BT_STATUS_FAIL; - LOG_VERBOSE("%s: feature not supported", __func__); + log::verbose("feature not supported"); } return (bt_status_t)status; } @@ -5420,7 +5380,7 @@ static const btrc_ctrl_interface_t bt_rc_ctrl_interface = { * ******************************************************************************/ const btrc_interface_t* btif_rc_get_interface(void) { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); return &bt_rc_interface; } @@ -5434,7 +5394,7 @@ const btrc_interface_t* btif_rc_get_interface(void) { * ******************************************************************************/ const btrc_ctrl_interface_t* btif_rc_ctrl_get_interface(void) { - LOG_VERBOSE("%s: ", __func__); + log::verbose(""); return &bt_rc_ctrl_interface; } @@ -5532,13 +5492,12 @@ static bt_status_t get_transaction(btif_rc_device_cb_t* p_dev, transaction_set->transaction[i].context = context; transaction_set->transaction[i].in_use = true; *ptransaction = &(transaction_set->transaction[i]); - LOG_VERBOSE("%s: Assigned transaction=%s", __func__, - dump_transaction(*ptransaction).c_str()); + log::verbose("Assigned transaction={}", dump_transaction(*ptransaction)); return BT_STATUS_SUCCESS; } } - LOG_ERROR("%s: p_dev=%s, failed to find free transaction", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr)); + log::error("p_dev={}, failed to find free transaction", + ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr)); return BT_STATUS_NOMEM; } @@ -5556,12 +5515,12 @@ static void start_transaction_timer(btif_rc_device_cb_t* p_dev, uint8_t label, uint64_t timeout_ms) { rc_transaction_t* transaction = get_transaction_by_lbl(p_dev, label); if (transaction == nullptr) { - LOG_ERROR("%s: transaction is null", __func__); + log::error("transaction is null"); return; } if (alarm_is_scheduled(transaction->timer)) { - LOG_WARN("%s: Restarting timer that's already scheduled", __func__); + log::warn("Restarting timer that's already scheduled"); } std::stringstream ss; @@ -5582,9 +5541,9 @@ static void start_transaction_timer(btif_rc_device_cb_t* p_dev, uint8_t label, * Returns bt_status_t ******************************************************************************/ void release_transaction(btif_rc_device_cb_t* p_dev, uint8_t lbl) { - LOG_VERBOSE("%s: p_dev=%s, label=%d", __func__, - p_dev == NULL ? "null" : ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), - lbl); + log::verbose( + "p_dev={}, label={}", + p_dev == NULL ? "null" : ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), lbl); if (p_dev == nullptr) return; rc_transaction_set_t* transaction_set = &(p_dev->transaction_set); @@ -5657,17 +5616,17 @@ static void vendor_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, uint8_t label, rc_vendor_context_t* p_context) { if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } tAVRC_RESPONSE avrc_response = {0}; tBTA_AV_META_MSG meta_msg = {.rc_handle = p_dev->rc_handle}; - LOG_WARN("%s: timeout, addr=%s, label=%d, pdu_id=%s, event_id=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, - dump_rc_pdu(p_context->pdu_id), - dump_rc_notification_event_id(p_context->event_id)); + log::warn("timeout, addr={}, label={}, pdu_id={}, event_id={}", + ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, + dump_rc_pdu(p_context->pdu_id), + dump_rc_notification_event_id(p_context->event_id)); switch (p_context->pdu_id) { case AVRC_PDU_REGISTER_NOTIFICATION: @@ -5724,8 +5683,7 @@ static void vendor_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, break; default: - LOG_WARN("%s: timeout for unknown pdu_id=%d", __func__, - p_context->pdu_id); + log::warn("timeout for unknown pdu_id={}", p_context->pdu_id); break; } } @@ -5742,7 +5700,7 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, uint8_t label, rc_browse_context_t* p_context) { if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } @@ -5757,9 +5715,9 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, .p_msg = nullptr, }; - LOG_WARN("%s: timeout, addr=%s, label=%d, pdu_id=%s", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, - dump_rc_pdu(p_context->pdu_id)); + log::warn("timeout, addr={}, label={}, pdu_id={}", + ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, + dump_rc_pdu(p_context->pdu_id)); switch (p_context->pdu_id) { case AVRC_PDU_GET_FOLDER_ITEMS: @@ -5779,8 +5737,7 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, handle_get_metadata_attr_response(&meta_msg, &avrc_response.get_attrs); break; default: - LOG_WARN("%s: timeout for unknown pdu_id=%d", __func__, - p_context->pdu_id); + log::warn("timeout for unknown pdu_id={}", p_context->pdu_id); break; } } @@ -5797,13 +5754,13 @@ static void passthru_cmd_timeout_handler(btif_rc_device_cb_t* p_dev, uint8_t label, rc_passthru_context_t* p_context) { if (p_dev == NULL) { - LOG_ERROR("%s: p_dev NULL", __func__); + log::error("p_dev NULL"); return; } - LOG_WARN("%s: timeout, addr=%s, label=%d, rc_id=%d, key_state=%d", __func__, - ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, p_context->rc_id, - p_context->key_state); + log::warn("timeout, addr={}, label={}, rc_id={}, key_state={}", + ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, p_context->rc_id, + p_context->key_state); // Other requests are wrapped in a tAVRC_RESPONSE response object, but these // passthru events are not in there. As well, the upper layers don't handle @@ -5824,13 +5781,13 @@ static void btif_rc_transaction_timeout_handler(uint16_t /* event */, char* data) { rc_transaction_context_t* p_context = (rc_transaction_context_t*)data; if (p_context == nullptr) { - LOG_ERROR("%s: p_context is null", __func__); + log::error("p_context is null"); return; } btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(p_context->rc_addr); if (p_dev == NULL) { - LOG_ERROR("%s: p_dev is null", __func__); + log::error("p_dev is null"); return; } @@ -5847,8 +5804,7 @@ static void btif_rc_transaction_timeout_handler(uint16_t /* event */, &(p_context->command.passthru)); break; default: - LOG_WARN("%s: received timeout for unknown opcode=%d", __func__, - p_context->opcode); + log::warn("received timeout for unknown opcode={}", p_context->opcode); return; } release_transaction(p_dev, label); @@ -5926,7 +5882,7 @@ static bool absolute_volume_disabled() { char volume_disabled[PROPERTY_VALUE_MAX] = {0}; osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false"); if (strncmp(volume_disabled, "true", 4) == 0) { - LOG_WARN("%s: Absolute volume disabled by property", __func__); + log::warn("Absolute volume disabled by property"); return true; } return false; diff --git a/system/btif/src/btif_sdp.cc b/system/btif/src/btif_sdp.cc index 0169a7f22c6..7688c3cc766 100644 --- a/system/btif/src/btif_sdp.cc +++ b/system/btif/src/btif_sdp.cc @@ -28,6 +28,7 @@ #define LOG_TAG "bt_btif_sdp" +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_sdp.h> #include <stdlib.h> @@ -40,6 +41,7 @@ #include "types/raw_address.h" using bluetooth::Uuid; +using namespace bluetooth; /***************************************************************************** * Functions implemented in sdp_server.c @@ -65,7 +67,7 @@ static btsdp_callbacks_t* bt_sdp_callbacks = NULL; static void btif_sdp_search_comp_evt(uint16_t event, char* p_param) { tBTA_SDP_SEARCH_COMP* evt_data = (tBTA_SDP_SEARCH_COMP*)p_param; - LOG_VERBOSE("%s: event = %d", __func__, event); + log::verbose("event = {}", event); if (event != BTA_SDP_SEARCH_COMP_EVT) return; @@ -116,7 +118,7 @@ static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data, } static bt_status_t init(btsdp_callbacks_t* callbacks) { - LOG_VERBOSE("Sdp Search %s", __func__); + log::verbose("Sdp Search Init"); bt_sdp_callbacks = callbacks; sdp_server_init(); @@ -127,7 +129,7 @@ static bt_status_t init(btsdp_callbacks_t* callbacks) { } static bt_status_t deinit() { - LOG_VERBOSE("Sdp Search %s", __func__); + log::verbose("Sdp Search Deinit"); bt_sdp_callbacks = NULL; sdp_server_cleanup(); @@ -146,7 +148,7 @@ static const btsdp_interface_t sdp_if = { remove_sdp_record}; const btsdp_interface_t* btif_sdp_get_interface(void) { - LOG_VERBOSE("%s", __func__); + log::verbose(""); return &sdp_if; } @@ -160,7 +162,7 @@ const btsdp_interface_t* btif_sdp_get_interface(void) { * ******************************************************************************/ bt_status_t btif_sdp_execute_service(bool b_enable) { - LOG_VERBOSE("%s enable:%d", __func__, b_enable); + log::verbose("enable:{}", b_enable); if (b_enable) { BTA_SdpEnable(sdp_dm_cback); diff --git a/system/btif/src/btif_sdp_server.cc b/system/btif/src/btif_sdp_server.cc index 75653a7b2aa..6591791d0f7 100644 --- a/system/btif/src/btif_sdp_server.cc +++ b/system/btif/src/btif_sdp_server.cc @@ -28,6 +28,7 @@ #define LOG_TAG "bt_btif_sdp_server" +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_sdp.h> #include <pthread.h> @@ -50,6 +51,7 @@ #include "utl.h" using namespace bluetooth::legacy::stack::sdp; +using namespace bluetooth; // Protects the sdp_slots array from concurrent access. static std::recursive_mutex sdp_lock; @@ -69,6 +71,11 @@ typedef struct { bluetooth_sdp_record* record_data; } sdp_slot_t; +namespace fmt { +template <> +struct formatter<sdp_state_t> : enum_formatter<sdp_state_t> {}; +} // namespace fmt + #define MAX_SDP_SLOTS 128 static sdp_slot_t sdp_slots[MAX_SDP_SLOTS]; @@ -109,13 +116,13 @@ static void init_sdp_slots() { } bt_status_t sdp_server_init() { - LOG_VERBOSE("Sdp Server %s", __func__); + log::verbose("Sdp Server Init"); init_sdp_slots(); return BT_STATUS_SUCCESS; } void sdp_server_cleanup() { - LOG_VERBOSE("Sdp Server %s", __func__); + log::verbose("Sdp Server Cleanup"); std::unique_lock<std::recursive_mutex> lock(sdp_lock); int i; for (i = 0; i < MAX_SDP_SLOTS; i++) { @@ -213,7 +220,7 @@ static int alloc_sdp_slot(bluetooth_sdp_record* in_record) { } } } - LOG_ERROR("%s() failed - no more free slots!", __func__); + log::error("failed - no more free slots!"); /* Rearly the optimist is too optimistic, and cleanup is needed...*/ osi_free(record); return -1; @@ -223,7 +230,7 @@ static int free_sdp_slot(int id) { int handle = -1; bluetooth_sdp_record* record = NULL; if (id < 0 || id >= MAX_SDP_SLOTS) { - LOG_ERROR("%s() failed - id %d is invalid", __func__, id); + log::error("failed - id {} is invalid", id); return handle; } @@ -253,17 +260,16 @@ static int free_sdp_slot(int id) { */ static const sdp_slot_t* start_create_sdp(int id) { if (id >= MAX_SDP_SLOTS) { - LOG_ERROR("%s() failed - id %d is invalid", __func__, id); + log::error("failed - id {} is invalid", id); return NULL; } std::unique_lock<std::recursive_mutex> lock(sdp_lock); if (sdp_slots[id].state != SDP_RECORD_ALLOCED) { /* The record have been removed before this event occurred - e.g. deinit */ - LOG_ERROR( - "%s() failed - state for id %d is " - "sdp_slots[id].state = %d expected %d", - __func__, id, sdp_slots[id].state, SDP_RECORD_ALLOCED); + log::error( + "failed - state for id {} is sdp_slots[id].state = {} expected {}", id, + sdp_slots[id].state, SDP_RECORD_ALLOCED); return NULL; } @@ -280,7 +286,7 @@ bt_status_t create_sdp_record(bluetooth_sdp_record* record, int handle; handle = alloc_sdp_slot(record); - LOG_VERBOSE("%s() handle = 0x%08x", __func__, handle); + log::verbose("handle = 0x{:08x}", handle); if (handle < 0) return BT_STATUS_FAIL; @@ -332,16 +338,14 @@ bt_status_t remove_sdp_record(int record_id) { /* Get the Record handle, and free the slot */ handle = free_sdp_slot(record_id); - LOG_VERBOSE("Sdp Server %s id=%d to handle=0x%08x", __func__, record_id, - handle); + log::verbose("Sdp Server id={} to handle=0x{:08x}", record_id, handle); /* Pass the actual record handle */ if (handle > 0) { BTA_SdpRemoveRecordByUser(INT_TO_PTR(handle)); return BT_STATUS_SUCCESS; } - LOG_VERBOSE("Sdp Server %s - record already removed - or never created", - __func__); + log::verbose("Sdp Server - record already removed - or never created"); return BT_STATUS_FAIL; } @@ -357,7 +361,7 @@ void on_create_record_event(int id) { * 3) Update state on completion * 4) What to do at fail? * */ - LOG_VERBOSE("Sdp Server %s", __func__); + log::verbose("Sdp Server"); const sdp_slot_t* sdp_slot = start_create_sdp(id); tBTA_SERVICE_ID service_id = -1; bluetooth_sdp_record* record; @@ -397,7 +401,7 @@ void on_create_record_event(int id) { } break; default: - LOG_VERBOSE("Record type %d is not supported", record->hdr.type); + log::verbose("Record type {} is not supported", record->hdr.type); break; } if (handle != -1) { @@ -419,14 +423,14 @@ void on_create_record_event(int id) { } void on_remove_record_event(int handle) { - LOG_VERBOSE("Sdp Server %s", __func__); + log::verbose("Sdp Server"); // User data carries the actual SDP handle, not the ID. if (handle != -1 && handle != 0) { bool result; result = get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle); if (!result) { - LOG_ERROR(" Unable to remove handle 0x%08x", handle); + log::error("Unable to remove handle 0x{:08x}", handle); } } } @@ -449,7 +453,7 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register MAPS Service"); + log::error("Unable to register MAPS Service"); return sdp_handle; } @@ -510,10 +514,10 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); } else { bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); } return sdp_handle; } @@ -531,7 +535,7 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register MAP Notification Service"); + log::error("Unable to register MAP Notification Service"); return sdp_handle; } @@ -582,10 +586,10 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); } else { bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); } return sdp_handle; } @@ -600,7 +604,7 @@ static int add_pbapc_sdp(const bluetooth_sdp_pce_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register PBAP Client Service"); + log::error("Unable to register PBAP Client Service"); return sdp_handle; } @@ -624,11 +628,11 @@ static int add_pbapc_sdp(const bluetooth_sdp_pce_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); return sdp_handle; } bta_sys_add_uuid(service); /* UUID_SERVCLASS_PBAP_PCE */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); return sdp_handle; } @@ -645,7 +649,7 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register PBAP Server Service"); + log::error("Unable to register PBAP Server Service"); return sdp_handle; } @@ -688,8 +692,8 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) { status &= get_legacy_stack_sdp_api()->handle.SDP_AddAttribute( sdp_handle, ATTR_ID_SUPPORTED_REPOSITORIES, UINT_DESC_TYPE, (uint32_t)1, (uint8_t*)&supported_repositories_1_1); - LOG_VERBOSE(" supported_repositories_1_1: 0x%x", - supported_repositories_1_1); + log::verbose("supported_repositories_1_1: 0x{:x}", + supported_repositories_1_1); sdp_save_local_pse_record_attributes( rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.profile_version, rec->supported_features, @@ -754,10 +758,10 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); } else { bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); } return sdp_handle; } @@ -780,7 +784,7 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register Object Push Server Service"); + log::error("Unable to register Object Push Server Service"); return sdp_handle; } @@ -837,14 +841,14 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); } else { /* set class of device */ cod.service = BTM_COD_SERVICE_OBJ_TRANSFER; utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS); bta_sys_add_uuid(service); /* UUID_SERVCLASS_OBEX_OBJECT_PUSH */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); } return sdp_handle; } @@ -860,7 +864,7 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register SAPS Service"); + log::error("Unable to register SAPS Service"); return sdp_handle; } @@ -898,10 +902,10 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s(): FAILED deleting record", __func__); + log::error("FAILED deleting record"); } else { bta_sys_add_uuid(UUID_SERVCLASS_SAP); - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); } return sdp_handle; } @@ -916,7 +920,7 @@ static int add_mps_sdp(const bluetooth_sdp_mps_record* rec) { sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (sdp_handle == 0) { - LOG_ERROR("Unable to register MPS record"); + log::error("Unable to register MPS record"); return sdp_handle; } @@ -947,10 +951,10 @@ static int add_mps_sdp(const bluetooth_sdp_mps_record* rec) { if (!status) { get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - LOG_ERROR("%s() FAILED", __func__); + log::error("FAILED"); return sdp_handle; } bta_sys_add_uuid(service); /* UUID_SERVCLASS_MPS_SC */ - LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle); + log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle); return sdp_handle; } diff --git a/system/btif/src/btif_sock.cc b/system/btif/src/btif_sock.cc index ecf7f5f6143..a8416c359d1 100644 --- a/system/btif/src/btif_sock.cc +++ b/system/btif/src/btif_sock.cc @@ -22,6 +22,7 @@ #include <base/functional/callback.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h> #include <hardware/bluetooth.h> #include <hardware/bt_sock.h> @@ -48,6 +49,7 @@ bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type); bool btif_get_device_type(const RawAddress& bda, int* p_device_type); using bluetooth::Uuid; +using namespace bluetooth; static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, const Uuid* uuid, int channel, int* sock_fd, @@ -105,32 +107,32 @@ bt_status_t btif_sock_init(uid_set_t* uid_set) { btsock_thread_init(); thread_handle = btsock_thread_create(btsock_signaled, NULL); if (thread_handle == -1) { - LOG_ERROR("%s unable to create btsock_thread.", __func__); + log::error("unable to create btsock_thread."); goto error; } status = btsock_rfc_init(thread_handle, uid_set); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing RFCOMM sockets: %d", __func__, status); + log::error("error initializing RFCOMM sockets: {}", status); goto error; } status = btsock_l2cap_init(thread_handle, uid_set); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing L2CAP sockets: %d", __func__, status); + log::error("error initializing L2CAP sockets: {}", status); goto error; } thread = thread_new("btif_sock"); if (!thread) { - LOG_ERROR("%s error creating new thread.", __func__); + log::error("error creating new thread."); btsock_rfc_cleanup(); goto error; } status = btsock_sco_init(thread); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing SCO sockets: %d", __func__, status); + log::error("error initializing SCO sockets: {}", status); btsock_rfc_cleanup(); goto error; } @@ -160,8 +162,8 @@ void btif_sock_cleanup(void) { void btif_sock_connection_logger(int state, int role, const RawAddress& addr, int channel, const char* server_name) { - LOG_INFO("address=%s, state=%d, role=%d, server_name=%s, channel=%d", - ADDRESS_TO_LOGGABLE_CSTR(addr), state, role, server_name, channel); + log::info("address={}, state={}, role={}, server_name={}, channel={}", + ADDRESS_TO_LOGGABLE_CSTR(addr), state, role, server_name, channel); uint8_t index = logger_index++ % SOCK_LOGGER_SIZE_MAX; @@ -288,15 +290,13 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, /* Set channel to zero so that it will be assigned */ channel = 0; } else if (channel <= 0) { - LOG_ERROR("%s: type BTSOCK_L2CAP_LE: invalid channel=%d", __func__, - channel); + log::error("type BTSOCK_L2CAP_LE: invalid channel={}", channel); break; } flags |= BTSOCK_FLAG_LE_COC; - LOG_INFO( - - "%s: type=BTSOCK_L2CAP_LE, channel=0x%x, original=0x%x, flags=0x%x", - __func__, channel, original_channel, flags); + log::info( + "type=BTSOCK_L2CAP_LE, channel=0x{:x}, original=0x{:x}, flags=0x{:x}", + channel, original_channel, flags); status = btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid); break; @@ -305,7 +305,7 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, break; default: - LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type); + log::error("unknown/unsupported socket type: {}", type); status = BT_STATUS_UNSUPPORTED; break; } @@ -328,7 +328,7 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type, CHECK(bd_addr != NULL); CHECK(sock_fd != NULL); - LOG_INFO("%s", __func__); + log::info(""); *sock_fd = INVALID_FD; bt_status_t status = BT_STATUS_FAIL; @@ -364,8 +364,8 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type, BTA_DmAddBleDevice(*bd_addr, addr_type, device_type); } - LOG_INFO("%s: type=BTSOCK_L2CAP_LE, channel=0x%x, flags=0x%x", __func__, - channel, flags); + log::info("type=BTSOCK_L2CAP_LE, channel=0x{:x}, flags=0x{:x}", channel, + flags); status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid); break; } @@ -375,7 +375,7 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type, break; default: - LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type); + log::error("unknown/unsupported socket type: {}", type); status = BT_STATUS_UNSUPPORTED; break; } @@ -408,8 +408,8 @@ static void btsock_signaled(int fd, int type, int flags, uint32_t user_id) { btsock_l2cap_signaled(fd, flags, user_id); break; default: - LOG(FATAL) << "Invalid socket type! type=" << type << " fd=" << fd - << " flags=" << flags << " user_id=" << user_id; + log::fatal("Invalid socket type! type={} fd={} flags={} user_id={}", type, + fd, flags, user_id); break; } } @@ -421,8 +421,7 @@ static bt_status_t btsock_disconnect_all(const RawAddress* bd_addr) { bt_status_t l2cap_status = btsock_l2cap_disconnect(bd_addr); /* SCO is disconnected via btif_hf, so is not handled here. */ - LOG_INFO("%s: rfc status: %d, l2cap status: %d", __func__, rfc_status, - l2cap_status); + log::info("rfc status: {}, l2cap status: {}", rfc_status, l2cap_status); /* Return error status, if any. */ if (rfc_status == BT_STATUS_SUCCESS) { diff --git a/system/btif/src/btif_sock_l2cap.cc b/system/btif/src/btif_sock_l2cap.cc index 8e1150f0865..a7583d5e42f 100644 --- a/system/btif/src/btif_sock_l2cap.cc +++ b/system/btif/src/btif_sock_l2cap.cc @@ -16,6 +16,7 @@ */ #include <base/logging.h> +#include <bluetooth/log.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/types.h> @@ -38,6 +39,8 @@ #include "stack/include/bt_hdr.h" #include "types/raw_address.h" +using namespace bluetooth; + struct packet { struct packet *next, *prev; uint32_t len; @@ -163,8 +166,8 @@ static char packet_put_head_l(l2cap_socket* sock, const void* data, static char packet_put_tail_l(l2cap_socket* sock, const void* data, uint32_t len) { if (sock->bytes_buffered >= L2CAP_MAX_RX_BUFFER) { - LOG_ERROR("Unable to add to buffer due to buffer overflow socket_id:%u", - sock->id); + log::error("Unable to add to buffer due to buffer overflow socket_id:{}", + sock->id); return false; } @@ -230,8 +233,8 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) { if (sock->app_fd != -1) { close(sock->app_fd); } else { - LOG_INFO("Application has already closed l2cap socket socket_id:%u", - sock->id); + log::info("Application has already closed l2cap socket socket_id:{}", + sock->id); } while (packet_get_head_l(sock, &buf, NULL)) osi_free(buf); @@ -244,8 +247,8 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) { } if ((sock->channel >= 0) && (sock->server)) { BTA_JvFreeChannel(sock->channel, BTA_JV_CONN_TYPE_L2CAP_LE); - LOG_INFO("Stopped L2CAP LE COC server socket_id:%u channel:%u", sock->id, - sock->channel); + log::info("Stopped L2CAP LE COC server socket_id:{} channel:{}", sock->id, + sock->channel); BTA_JvL2capStopServer(sock->channel, sock->id); } } else { @@ -285,7 +288,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name, sock_type = SOCK_STREAM; #endif if (socketpair(AF_LOCAL, sock_type, 0, fds)) { - LOG_ERROR("socketpair failed:%s", strerror(errno)); + log::error("socketpair failed:{}", strerror(errno)); goto fail_sockpair; } @@ -328,7 +331,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name, sock->id++; } last_sock_id = sock->id; - LOG_INFO("Allocated l2cap socket structure socket_id:%u", sock->id); + log::info("Allocated l2cap socket structure socket_id:{}", sock->id); return sock; fail_sockpair: @@ -352,15 +355,15 @@ bt_status_t btsock_l2cap_cleanup() { } static inline bool send_app_psm_or_chan_l(l2cap_socket* sock) { - LOG_INFO("Sending l2cap socket socket_id:%u channel:%d", sock->id, - sock->channel); + log::info("Sending l2cap socket socket_id:{} channel:{}", sock->id, + sock->channel); return sock_send_all(sock->our_fd, (const uint8_t*)&sock->channel, sizeof(sock->channel)) == sizeof(sock->channel); } static bool send_app_err_code(l2cap_socket* sock, tBTA_JV_L2CAP_REASON code) { - LOG_INFO("Sending l2cap failure reason socket_id:%u reason code:%d", sock->id, - code); + log::info("Sending l2cap failure reason socket_id:{} reason code:{}", + sock->id, code); int err_channel = 0; if (sock_send_all(sock->our_fd, (const uint8_t*)&err_channel, sizeof(err_channel)) != sizeof(err_channel)) { @@ -388,7 +391,7 @@ static bool send_app_connect_signal(int fd, const RawAddress* addr, int channel, return true; } - LOG_ERROR("Unable to send data to socket fd:%d send_fd:%d", fd, send_fd); + log::error("Unable to send data to socket fd:{} send_fd:{}", fd, send_fd); return false; } @@ -399,12 +402,12 @@ static void on_srv_l2cap_listen_started(tBTA_JV_L2CAP_START* p_start, std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } if (p_start->status != BTA_JV_SUCCESS) { - LOG_ERROR("Unable to start l2cap server socket_id:%u", sock->id); + log::error("Unable to start l2cap server socket_id:{}", sock->id); btsock_l2cap_free_l(sock); return; } @@ -427,7 +430,7 @@ static void on_srv_l2cap_listen_started(tBTA_JV_L2CAP_START* p_start, if (!sock->server_psm_sent) { if (!send_app_psm_or_chan_l(sock)) { // closed - LOG_INFO("Unable to send socket to application socket_id:%u", sock->id); + log::info("Unable to send socket to application socket_id:{}", sock->id); btsock_l2cap_free_l(sock); } else { sock->server_psm_sent = true; @@ -441,12 +444,12 @@ static void on_cl_l2cap_init(tBTA_JV_L2CAP_CL_INIT* p_init, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } if (p_init->status != BTA_JV_SUCCESS) { - LOG_ERROR("Initialization status failed socket_id:%u", id); + log::error("Initialization status failed socket_id:{}", id); btsock_l2cap_free_l(sock); return; } @@ -512,15 +515,15 @@ static void on_cl_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open, sock->tx_mtu = p_open->tx_mtu; if (!send_app_psm_or_chan_l(sock)) { - LOG_ERROR("Unable to send l2cap socket to application socket_id:%u", - sock->id); + log::error("Unable to send l2cap socket to application socket_id:{}", + sock->id); return; } if (!send_app_connect_signal(sock->our_fd, &sock->addr, sock->channel, 0, -1, sock->rx_mtu, p_open->tx_mtu)) { - LOG_ERROR("Unable to connect l2cap socket to application socket_id:%u", - sock->id); + log::error("Unable to connect l2cap socket to application socket_id:{}", + sock->id); return; } @@ -539,7 +542,7 @@ static void on_cl_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open, // start monitoring the socketpair to get call back when app writing data btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD, sock->id); - LOG_INFO("Connected l2cap socket socket_id:%u", sock->id); + log::info("Connected l2cap socket socket_id:{}", sock->id); sock->connected = true; } @@ -551,7 +554,7 @@ static void on_l2cap_connect(tBTA_JV* p_data, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } @@ -563,8 +566,8 @@ static void on_l2cap_connect(tBTA_JV* p_data, uint32_t id) { on_srv_l2cap_psm_connect_l(psm_open, sock); } } else { - LOG_ERROR("Unable to open socket after receiving connection socket_id:%u", - sock->id); + log::error("Unable to open socket after receiving connection socket_id:{}", + sock->id); btsock_l2cap_free_l(sock); } } @@ -575,8 +578,8 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_INFO( - "Unable to find probably already closed l2cap socket with socket_id:%u", + log::info( + "Unable to find probably already closed l2cap socket with socket_id:{}", id); return; } @@ -594,8 +597,8 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) { : android::bluetooth::SOCKET_ROLE_CONNECTION); if (!send_app_err_code(sock, p_close->reason)) { - LOG_ERROR("Unable to send l2cap socket to application socket_id:%u", - sock->id); + log::error("Unable to send l2cap socket to application socket_id:{}", + sock->id); } // TODO: This does not seem to be called... // I'm not sure if this will be called for non-server sockets? @@ -611,15 +614,15 @@ static void on_l2cap_outgoing_congest(tBTA_JV_L2CAP_CONG* p, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } sock->outgoing_congest = p->cong ? 1 : 0; if (!sock->outgoing_congest) { - LOG_VERBOSE("Monitoring l2cap socket for outgoing data socket_id:%u", - sock->id); + log::verbose("Monitoring l2cap socket for outgoing data socket_id:{}", + sock->id); btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD, sock->id); } @@ -629,7 +632,7 @@ static void on_l2cap_write_done(uint16_t len, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); l2cap_socket* sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } @@ -638,7 +641,7 @@ static void on_l2cap_write_done(uint16_t len, uint32_t id) { btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD, sock->id); } else { - LOG_INFO("Socket congestion on socket_id:%u", sock->id); + log::info("Socket congestion on socket_id:{}", sock->id); } sock->tx_bytes += len; @@ -654,7 +657,7 @@ static void on_l2cap_data_ind(tBTA_JV* evt, uint32_t id) { std::unique_lock<std::mutex> lock(state_lock); sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } @@ -671,8 +674,9 @@ static void on_l2cap_data_ind(tBTA_JV* evt, uint32_t id) { btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_WR, sock->id); } else { // connection must be dropped - LOG_WARN("Closing socket as unable to push data to socket socket_id:%u", - sock->id); + log::warn( + "Closing socket as unable to push data to socket socket_id:{}", + sock->id); BTA_JvL2capClose(sock->handle); btsock_l2cap_free_l(sock); return; @@ -721,8 +725,8 @@ static void btsock_l2cap_cbk(tBTA_JV_EVT event, tBTA_JV* p_data, break; default: - LOG_ERROR("Unhandled event:%hu l2cap_socket_id:%u", event, - l2cap_socket_id); + log::error("Unhandled event:{} l2cap_socket_id:{}", event, + l2cap_socket_id); break; } } @@ -743,7 +747,7 @@ void on_l2cap_psm_assigned(int id, int psm) { std::unique_lock<std::mutex> lock(state_lock); l2cap_socket* sock = btsock_l2cap_find_by_id_l(id); if (!sock) { - LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id); + log::error("Unable to find l2cap socket with socket_id:{}", id); return; } @@ -785,7 +789,7 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name, bool is_le_coc = (flags & BTSOCK_FLAG_LE_COC) != 0; if (!sock_fd) { - LOG_INFO("Invalid socket descriptor"); + log::info("Invalid socket descriptor"); return BT_STATUS_PARM_INVALID; } @@ -925,7 +929,7 @@ void btsock_l2cap_signaled(int fd, int flags, uint32_t user_id) { if (count > sock->tx_mtu) { /* This can't happen thanks to check in BluetoothSocket.java but leave * this in case this socket is ever used anywhere else*/ - LOG(ERROR) << "recv more than MTU. Data will be lost: " << count; + log::error("recv more than MTU. Data will be lost: {}", count); count = sock->tx_mtu; } diff --git a/system/btif/src/btif_sock_rfc.cc b/system/btif/src/btif_sock_rfc.cc index cff0648f6f7..78cc1feedc0 100644 --- a/system/btif/src/btif_sock_rfc.cc +++ b/system/btif/src/btif_sock_rfc.cc @@ -18,6 +18,7 @@ #define LOG_TAG "bt_btif_sock_rfcomm" +#include <bluetooth/log.h> #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -47,6 +48,7 @@ #include "types/raw_address.h" using bluetooth::Uuid; +using namespace bluetooth; // Maximum number of RFCOMM channels (1-30 inclusive). #define MAX_RFC_CHANNEL 30 @@ -139,7 +141,7 @@ void btsock_rfc_cleanup(void) { uid_set = NULL; - LOG_DEBUG("cleanup finished"); + log::debug("cleanup finished"); } static rfc_slot_t* find_free_slot(void) { @@ -173,7 +175,7 @@ static rfc_slot_t* find_rfc_slot_by_pending_sdp(void) { static bool is_requesting_sdp(void) { for (size_t i = 0; i < ARRAY_SIZE(rfc_slots); ++i) if (rfc_slots[i].id && rfc_slots[i].f.doing_sdp_request) { - LOG_INFO("slot id %u is doing sdp request", rfc_slots[i].id); + log::info("slot id {} is doing sdp request", rfc_slots[i].id); return true; } return false; @@ -194,13 +196,13 @@ static rfc_slot_t* alloc_rfc_slot(const RawAddress* addr, const char* name, rfc_slot_t* slot = find_free_slot(); if (!slot) { - LOG_ERROR("%s unable to find free RFCOMM slot.", __func__); + log::error("unable to find free RFCOMM slot."); return NULL; } int fds[2] = {INVALID_FD, INVALID_FD}; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) == -1) { - LOG_ERROR("%s error creating socketpair: %s", __func__, strerror(errno)); + log::error("error creating socketpair: {}", strerror(errno)); return NULL; } @@ -241,7 +243,7 @@ static rfc_slot_t* create_srv_accept_rfc_slot(rfc_slot_t* srv_rs, rfc_slot_t* accept_rs = alloc_rfc_slot( addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, false); if (!accept_rs) { - LOG_ERROR("%s unable to allocate RFCOMM slot.", __func__); + log::error("unable to allocate RFCOMM slot."); return NULL; } @@ -275,7 +277,7 @@ bt_status_t btsock_rfc_control_req(uint8_t dlci, const RawAddress& bd_addr, RFCOMM_ControlReqFromBTSOCK(dlci, bd_addr, modem_signal, break_signal, discard_buffers, break_signal_seq, fc); if (status != PORT_SUCCESS) { - LOG_WARN("failed to send control parameters, status=%d", status); + log::warn("failed to send control parameters, status={}", status); return BT_STATUS_FAIL; } return BT_STATUS_SUCCESS; @@ -296,7 +298,7 @@ bt_status_t btsock_rfc_listen(const char* service_name, // functions on RFCOMM sockets before initializing the module. Probably // should be an assert. if (!is_init_done()) { - LOG_ERROR("BT not ready"); + log::error("BT not ready"); return BT_STATUS_NOT_READY; } @@ -318,11 +320,11 @@ bt_status_t btsock_rfc_listen(const char* service_name, rfc_slot_t* slot = alloc_rfc_slot(NULL, service_name, *service_uuid, channel, flags, true); if (!slot) { - LOG_ERROR("unable to allocate RFCOMM slot"); + log::error("unable to allocate RFCOMM slot"); return BT_STATUS_FAIL; } - LOG_INFO("Adding listening socket service_name: %s - channel: %d", - service_name, channel); + log::info("Adding listening socket service_name: {} - channel: {}", + service_name, channel); BTA_JvGetChannelId(BTA_JV_CONN_TYPE_RFCOMM, slot->id, channel); *sock_fd = slot->app_fd; // Transfer ownership of fd to caller. /*TODO: @@ -354,7 +356,7 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr, // functions on RFCOMM sockets before initializing the module. Probably should // be an assert. if (!is_init_done()) { - LOG_ERROR("BT not ready"); + log::error("BT not ready"); return BT_STATUS_NOT_READY; } @@ -363,8 +365,8 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr, rfc_slot_t* slot = alloc_rfc_slot(bd_addr, NULL, *service_uuid, channel, flags, false); if (!slot) { - LOG_ERROR("unable to allocate RFCOMM slot. bd_addr:%s", - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); + log::error("unable to allocate RFCOMM slot. bd_addr:{}", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); return BT_STATUS_FAIL; } @@ -373,22 +375,22 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr, BTA_JvRfcommConnect(slot->security, slot->role, slot->scn, slot->addr, rfcomm_cback, slot->id); if (ret != BTA_JV_SUCCESS) { - LOG_ERROR( - "unable to initiate RFCOMM connection. status:%d, scn:%d, bd_addr:%s", + log::error( + "unable to initiate RFCOMM connection. status:{}, scn:{}, bd_addr:{}", ret, slot->scn, ADDRESS_TO_LOGGABLE_CSTR(slot->addr)); cleanup_rfc_slot(slot); return BT_STATUS_FAIL; } if (!send_app_scn(slot)) { - LOG_ERROR("send_app_scn() failed, closing slot->id:%u", slot->id); + log::error("send_app_scn() failed, closing slot->id:{}", slot->id); cleanup_rfc_slot(slot); return BT_STATUS_FAIL; } } else { - LOG_INFO("service_uuid:%s, bd_addr:%s, slot_id:%u", - service_uuid->ToString().c_str(), - ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), slot->id); + log::info("service_uuid:{}, bd_addr:{}, slot_id:{}", + service_uuid->ToString(), ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), + slot->id); if (!is_requesting_sdp()) { BTA_JvStartDiscovery(*bd_addr, 1, service_uuid, slot->id); slot->f.pending_sdp_request = false; @@ -479,8 +481,8 @@ static bool send_app_scn(rfc_slot_t* slot) { // already sent, just return success. return true; } - LOG_DEBUG("Sending scn for slot %u. bd_addr:%s", slot->id, - ADDRESS_TO_LOGGABLE_CSTR(slot->addr)); + log::debug("Sending scn for slot {}. bd_addr:{}", slot->id, + ADDRESS_TO_LOGGABLE_CSTR(slot->addr)); slot->scn_notified = true; return sock_send_all(slot->fd, (const uint8_t*)&slot->scn, sizeof(slot->scn)) == sizeof(slot->scn); @@ -506,11 +508,11 @@ static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT* p_init, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found. p_init->status=%u", id, - p_init->status); + log::error("RFCOMM slot with id {} not found. p_init->status={}", id, + p_init->status); } else if (p_init->status != BTA_JV_SUCCESS) { - LOG_WARN("INIT unsuccessful, status %u. Cleaning up slot with id %u", - p_init->status, slot->id); + log::warn("INIT unsuccessful, status {}. Cleaning up slot with id {}", + p_init->status, slot->id); cleanup_rfc_slot(slot); } else { slot->rfc_handle = p_init->handle; @@ -522,11 +524,11 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start, std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found", id); + log::error("RFCOMM slot with id {} not found", id); return; } else if (p_start->status != BTA_JV_SUCCESS) { - LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u", - p_start->status, slot->id); + log::warn("START unsuccessful, status {}. Cleaning up slot with id {}", + p_start->status, slot->id); cleanup_rfc_slot(slot); return; } @@ -547,12 +549,12 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start, static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint32_t id) { - LOG_VERBOSE("id:%u", id); + log::verbose("id:{}", id); std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* accept_rs; rfc_slot_t* srv_rs = find_rfc_slot_by_id(id); if (!srv_rs) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return 0; } @@ -584,17 +586,17 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, } static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) { - LOG_VERBOSE("id:%u", id); + log::verbose("id:{}", id); std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return; } if (p_open->status != BTA_JV_SUCCESS) { - LOG_WARN("CONNECT unsuccessful, status %u. Cleaning up slot with id %u", - p_open->status, slot->id); + log::warn("CONNECT unsuccessful, status {}. Cleaning up slot with id {}", + p_open->status, slot->id); cleanup_rfc_slot(slot); return; } @@ -616,20 +618,19 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) { if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) { slot->f.connected = true; } else { - LOG_ERROR("%s unable to send connect completion signal to caller.", - __func__); + log::error("unable to send connect completion signal to caller."); } } static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, uint32_t id) { - LOG_VERBOSE("id:%u", id); + log::verbose("id:{}", id); std::unique_lock<std::recursive_mutex> lock(slot_lock); // rfc_handle already closed when receiving rfcomm close event from stack. rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_WARN("RFCOMM slot with id %u not found.", id); + log::warn("RFCOMM slot with id {} not found.", id); return; } log_socket_connection_state( @@ -643,8 +644,7 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { if (p->status != BTA_JV_SUCCESS) { - LOG_ERROR("%s error writing to RFCOMM socket with slot %u.", __func__, - p->req_id); + log::error("error writing to RFCOMM socket with slot {}.", p->req_id); return; } @@ -653,7 +653,7 @@ static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return; } app_uid = slot->app_uid; @@ -669,7 +669,7 @@ static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG* p, uint32_t id) { rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return; } @@ -685,9 +685,9 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, // Write events are too frequent to log at info level if (event != BTA_JV_RFCOMM_WRITE_EVT) { - LOG_INFO("handling event:%d id:%u", event, rfcomm_slot_id); + log::info("handling event:{} id:{}", event, rfcomm_slot_id); } else { - LOG_VERBOSE("handling event:%d id:%u", event, rfcomm_slot_id); + log::verbose("handling event:{} id:{}", event, rfcomm_slot_id); } switch (event) { @@ -712,7 +712,8 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, break; case BTA_JV_RFCOMM_CLOSE_EVT: - LOG_VERBOSE("BTA_JV_RFCOMM_CLOSE_EVT: rfcomm_slot_id:%d", rfcomm_slot_id); + log::verbose("BTA_JV_RFCOMM_CLOSE_EVT: rfcomm_slot_id:{}", + rfcomm_slot_id); on_rfc_close(&p_data->rfc_close, rfcomm_slot_id); break; @@ -729,27 +730,26 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, break; default: - LOG_ERROR("%s unhandled event %d, slot id: %u", __func__, event, - rfcomm_slot_id); + log::error("unhandled event {}, slot id: {}", event, rfcomm_slot_id); break; } return id; } static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { - LOG_INFO("handling event:%d, id:%u", event, id); + log::info("handling event:{}, id:{}", event, id); switch (event) { case BTA_JV_GET_SCN_EVT: { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* rs = find_rfc_slot_by_id(id); if (!rs) { - LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); + log::error("RFCOMM slot with id {} not found. event:{}", id, event); break; } if (p_data->scn == 0) { - LOG_ERROR( - "Unable to allocate scn: all resources exhausted. slot found: %p", - rs); + log::error( + "Unable to allocate scn: all resources exhausted. slot found: {}", + fmt::ptr(rs)); cleanup_rfc_slot(rs); break; } @@ -757,7 +757,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { rs->scn = p_data->scn; // Send channel ID to java layer if (!send_app_scn(rs)) { - LOG_WARN("send_app_scn() failed, closing rs->id:%d", rs->id); + log::warn("send_app_scn() failed, closing rs->id:{}", rs->id); cleanup_rfc_slot(rs); break; } @@ -771,7 +771,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { // thread needed for the java layer to get a RFCOMM channel. // create_sdp_record() will be called from Java when it has received the // RFCOMM and L2CAP channel numbers through the sockets. - LOG_DEBUG( + log::debug( "Since UUID is not valid; not setting SDP-record and just starting " "the RFCOMM server"); // now start the rfcomm server after sdp & channel # assigned @@ -782,7 +782,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { } case BTA_JV_GET_PSM_EVT: { - LOG_VERBOSE("Received PSM: 0x%04x", p_data->psm); + log::verbose("Received PSM: 0x{:04x}", p_data->psm); on_l2cap_psm_assigned(id, p_data->psm); break; } @@ -792,12 +792,12 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); + log::error("RFCOMM slot with id {} not found. event:{}", id, event); break; } if (!create_server_sdp_record(slot)) { - LOG_ERROR("cannot start server, slot found: %p", slot); + log::error("cannot start server, slot found: {}", fmt::ptr(slot)); cleanup_rfc_slot(slot); break; } @@ -823,7 +823,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { } default: - LOG_DEBUG("unhandled event:%d, slot id:%d", event, id); + log::debug("unhandled event:{}, slot id:{}", event, id); break; } } @@ -831,23 +831,23 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { static void handle_discovery_comp(tBTA_JV_STATUS status, int scn, uint32_t id) { rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR( - "RFCOMM slot with id %u not found. event: BTA_JV_DISCOVERY_COMP_EVT", + log::error( + "RFCOMM slot with id {} not found. event: BTA_JV_DISCOVERY_COMP_EVT", id); return; } if (!slot->f.doing_sdp_request) { - LOG_ERROR( - "SDP response returned but RFCOMM slot %d did not request SDP record.", + log::error( + "SDP response returned but RFCOMM slot {} did not request SDP record.", id); return; } if (status != BTA_JV_SUCCESS || !scn) { - LOG_ERROR( - "SDP service discovery completed for slot id: %u with the result " - "status: %u, scn: %d", + log::error( + "SDP service discovery completed for slot id: {} with the result " + "status: {}, scn: {}", id, status, scn); cleanup_rfc_slot(slot); return; @@ -855,9 +855,9 @@ static void handle_discovery_comp(tBTA_JV_STATUS status, int scn, uint32_t id) { if (BTA_JvRfcommConnect(slot->security, slot->role, scn, slot->addr, rfcomm_cback, slot->id) != BTA_JV_SUCCESS) { - LOG_WARN( + log::warn( "BTA_JvRfcommConnect() returned BTA_JV_FAILURE for RFCOMM slot with " - "id: %u", + "id: {}", id); cleanup_rfc_slot(slot); return; @@ -867,7 +867,7 @@ static void handle_discovery_comp(tBTA_JV_STATUS status, int scn, uint32_t id) { slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) { - LOG_WARN("send_app_scn() failed, closing slot->id %u", slot->id); + log::warn("send_app_scn() failed, closing slot->id {}", slot->id); cleanup_rfc_slot(slot); return; } @@ -889,8 +889,7 @@ static sent_status_t send_data_to_app(int fd, BT_HDR* p_buf) { if (sent == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) return SENT_NONE; - LOG_ERROR("%s error writing RFCOMM data back to app: %s", __func__, - strerror(errno)); + log::error("error writing RFCOMM data back to app: {}", strerror(errno)); return SENT_FAILED; } @@ -926,8 +925,8 @@ static bool flush_incoming_que_on_wr_signal(rfc_slot_t* slot) { // app is ready to receive data, tell stack to start the data flow // fix me: need a jv flow control api to serialize the call in stack - LOG_VERBOSE( - "enable data flow, rfc_handle:0x%x, rfc_port_handle:0x%x, user_id:%d", + log::verbose( + "enable data flow, rfc_handle:0x{:x}, rfc_port_handle:0x{:x}, user_id:{}", slot->rfc_handle, slot->rfc_port_handle, slot->id); PORT_FlowControl_MaxCredit(slot->rfc_port_handle, true); return true; @@ -938,7 +937,7 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return; } @@ -952,10 +951,9 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) { BTA_JvRfcommWrite(slot->rfc_handle, slot->id); } } else { - LOG_ERROR( - "%s socket signaled for read while disconnected, slot: %d, " - "channel: %d", - __func__, slot->id, slot->scn); + log::error( + "socket signaled for read while disconnected, slot: {}, channel: {}", + slot->id, slot->scn); need_close = true; } } @@ -963,10 +961,10 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) { if (flags & SOCK_THREAD_FD_WR) { // App is ready to receive more data, tell stack to enable data flow. if (!slot->f.connected || !flush_incoming_que_on_wr_signal(slot)) { - LOG_ERROR( - "%s socket signaled for write while disconnected (or write " - "failure), slot: %d, channel: %d", - __func__, slot->id, slot->scn); + log::error( + "socket signaled for write while disconnected (or write failure), " + "slot: {}, channel: {}", + slot->id, slot->scn); need_close = true; } } @@ -986,7 +984,7 @@ int bta_co_rfc_data_incoming(uint32_t id, BT_HDR* p_buf) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return 0; } @@ -1027,13 +1025,13 @@ int bta_co_rfc_data_outgoing_size(uint32_t id, int* size) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return false; } if (ioctl(slot->fd, FIONREAD, size) != 0) { - LOG_ERROR("%s unable to determine bytes remaining to be read on fd %d: %s", - __func__, slot->fd, strerror(errno)); + log::error("unable to determine bytes remaining to be read on fd {}: {}", + slot->fd, strerror(errno)); cleanup_rfc_slot(slot); return false; } @@ -1045,7 +1043,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (!slot) { - LOG_ERROR("RFCOMM slot with id %u not found.", id); + log::error("RFCOMM slot with id {} not found.", id); return false; } @@ -1053,8 +1051,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) { OSI_NO_INTR(received = recv(slot->fd, buf, size, 0)); if (received != size) { - LOG_ERROR("%s error receiving RFCOMM data from app: %s", __func__, - strerror(errno)); + log::error("error receiving RFCOMM data from app: {}", strerror(errno)); cleanup_rfc_slot(slot); return false; } @@ -1065,7 +1062,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) { bt_status_t btsock_rfc_disconnect(const RawAddress* bd_addr) { CHECK(bd_addr != NULL); if (!is_init_done()) { - LOG_ERROR("BT not ready"); + log::error("BT not ready"); return BT_STATUS_NOT_READY; } diff --git a/system/btif/src/btif_sock_sco.cc b/system/btif/src/btif_sock_sco.cc index a847323e777..66fee0349fe 100644 --- a/system/btif/src/btif_sock_sco.cc +++ b/system/btif/src/btif_sock_sco.cc @@ -18,6 +18,7 @@ #define LOG_TAG "bt_btif_sock_sco" +#include <bluetooth/log.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> @@ -54,6 +55,8 @@ // socket_read_ready_cb() - local host closed SCO socket // disconnect_completed_cb() - connection terminated +using namespace bluetooth; + typedef struct { uint16_t sco_handle; socket_t* socket; @@ -134,14 +137,13 @@ static sco_socket_t* sco_socket_establish_locked(bool is_listening, tBTM_STATUS status; enh_esco_params_t params; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pair) == -1) { - LOG_ERROR("%s unable to allocate socket pair: %s", __func__, - strerror(errno)); + log::error("unable to allocate socket pair: {}", strerror(errno)); goto error; } sco_socket = sco_socket_new(); if (!sco_socket) { - LOG_ERROR("%s unable to allocate new SCO socket.", __func__); + log::error("unable to allocate new SCO socket."); goto error; } @@ -150,14 +152,13 @@ static sco_socket_t* sco_socket_establish_locked(bool is_listening, &sco_socket->sco_handle, connect_completed_cb, disconnect_completed_cb); if (status != BTM_CMD_STARTED) { - LOG_ERROR("%s unable to create SCO socket: %d", __func__, status); + log::error("unable to create SCO socket: {}", status); goto error; } socket = socket_new_from_fd(pair[1]); if (!socket) { - LOG_ERROR("%s unable to allocate socket from file descriptor %d.", __func__, - pair[1]); + log::error("unable to allocate socket from file descriptor {}.", pair[1]); goto error; } @@ -222,22 +223,19 @@ static void connection_request_cb(tBTM_ESCO_EVT event, sco_socket_t* new_sco_socket; if (!sco_socket) { - LOG_ERROR("%s unable to find sco_socket for handle: %hu", __func__, - conn_data->sco_inx); + log::error("unable to find sco_socket for handle: {}", conn_data->sco_inx); goto error; } if (sco_socket != listen_sco_socket) { - LOG_ERROR( - - "%s received connection request on non-listening socket handle: %hu", - __func__, conn_data->sco_inx); + log::error("received connection request on non-listening socket handle: {}", + conn_data->sco_inx); goto error; } new_sco_socket = sco_socket_establish_locked(true, NULL, &client_fd); if (!new_sco_socket) { - LOG_ERROR("%s unable to allocate new sco_socket.", __func__); + log::error("unable to allocate new sco_socket."); goto error; } @@ -255,8 +253,7 @@ static void connection_request_cb(tBTM_ESCO_EVT event, if (socket_write_and_transfer_fd(sco_socket->socket, &connect_signal, sizeof(connect_signal), client_fd) != sizeof(connect_signal)) { - LOG_ERROR("%s unable to send new file descriptor to listening socket.", - __func__); + log::error("unable to send new file descriptor to listening socket."); goto error; } @@ -275,8 +272,7 @@ static void connect_completed_cb(uint16_t sco_handle) { sco_socket_t* sco_socket = sco_socket_find_locked(sco_handle); if (!sco_socket) { - LOG_ERROR("%s SCO socket not found on connect for handle: %hu", __func__, - sco_handle); + log::error("SCO socket not found on connect for handle: {}", sco_handle); return; } @@ -297,8 +293,7 @@ static void disconnect_completed_cb(uint16_t sco_handle) { sco_socket_t* sco_socket = sco_socket_find_locked(sco_handle); if (!sco_socket) { - LOG_ERROR("%s SCO socket not found on disconnect for handle: %hu", __func__, - sco_handle); + log::error("SCO socket not found on disconnect for handle: {}", sco_handle); return; } diff --git a/system/btif/src/btif_sock_sdp.cc b/system/btif/src/btif_sock_sdp.cc index b550bf30598..5c53bdf2119 100644 --- a/system/btif/src/btif_sock_sdp.cc +++ b/system/btif/src/btif_sock_sdp.cc @@ -20,6 +20,8 @@ #include "btif/include/btif_sock_sdp.h" +#include <bluetooth/log.h> + #include "bta/include/bta_jv_api.h" #include "bta/include/bta_op_api.h" #include "bta/include/utl.h" @@ -33,6 +35,7 @@ #include "types/bluetooth/uuid.h" using namespace bluetooth::legacy::stack::sdp; +using namespace bluetooth; using bluetooth::Uuid; @@ -90,8 +93,8 @@ static const tBTA_OP_FMT bta_ops_obj_fmt[OBEX_PUSH_NUM_FORMATS] = { // Returns true if successful, otherwise false. static bool create_base_record(const uint32_t sdp_handle, const char* name, const uint16_t channel, const bool with_obex) { - LOG_VERBOSE("create_base_record: scn: %d, name: %s, with_obex: %d", channel, - name, with_obex); + log::verbose("create_base_record: scn: {}, name: {}, with_obex: {}", channel, + name, with_obex); // Setup the protocol list and add it. tSDP_PROTOCOL_ELEM proto_list[SDP_MAX_LIST_ELEMS]; @@ -132,16 +135,16 @@ static bool create_base_record(const uint32_t sdp_handle, const char* name, sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &list)) goto error; - LOG_VERBOSE( - "create_base_record: successfully created base service " - "record, handle: 0x%08x, scn: %d, name: %s, with_obex: %d", + log::verbose( + "create_base_record: successfully created base service record, handle: " + "0x{:08x}, scn: {}, name: {}, with_obex: {}", sdp_handle, channel, name, with_obex); return true; error: - LOG_ERROR( - "create_base_record: failed to create base service " - "record, stage: %s, scn: %d, name: %s, with_obex: %d", + log::error( + "create_base_record: failed to create base service record, stage: {}, " + "scn: {}, name: {}, with_obex: {}", stage, channel, name, with_obex); return false; } @@ -151,13 +154,13 @@ error: // class sequence. static int add_sdp_by_uuid(const char* name, const Uuid& uuid, const uint16_t channel) { - LOG_VERBOSE("%s: uuid: %s, scn: %d, service_name: %s", __func__, - uuid.ToString().c_str(), channel, name); + log::verbose("uuid: {}, scn: {}, service_name: {}", uuid.ToString(), channel, + name); uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (handle == 0) { - LOG_ERROR("%s: failed to create sdp record, scn: %d, service_name: %s", - __func__, channel, name); + log::error("failed to create sdp record, scn: {}, service_name: {}", + channel, name); return 0; } @@ -188,9 +191,9 @@ static int add_sdp_by_uuid(const char* name, const Uuid& uuid, &type_buf_ptr)) goto error; - LOG_VERBOSE( - "%s: service registered successfully, service_name: %s, handle: 0x%08x", - __func__, name, handle); + log::verbose( + "service registered successfully, service_name: {}, handle: 0x{:08x}", + name, handle); { // Write the custom 128-bit UUID to EIR @@ -202,22 +205,20 @@ static int add_sdp_by_uuid(const char* name, const Uuid& uuid, error: get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle); - LOG_ERROR("%s: failed to register service stage: %s, service_name: %s", - __func__, stage, name); + log::error("failed to register service stage: {}, service_name: {}", stage, + name); return 0; } // Registers a service with the given |name| and |channel| in the SDP // database as a PBAP protocol. static int add_pbap_sdp(const char* name, const int channel) { - LOG_VERBOSE("add_pbap_sdp: scn %d, service_name %s", channel, name); + log::verbose("add_pbap_sdp: scn {}, service_name {}", channel, name); uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (handle == 0) { - LOG_ERROR( - "add_pbap_sdp: failed to create sdp record, " - "service_name: %s", - name); + log::error("add_pbap_sdp: failed to create sdp record, service_name: {}", + name); return 0; } @@ -249,32 +250,30 @@ static int add_pbap_sdp(const char* name, const int channel) { // Notify the system that we've got a new service class UUID. bta_sys_add_uuid(UUID_SERVCLASS_PBAP_PSE); - LOG_VERBOSE( - "add_pbap_sdp: service registered successfully, " - "service_name: %s, handle: 0x%08x", + log::verbose( + "add_pbap_sdp: service registered successfully, service_name: {}, " + "handle: 0x{:08x}", name, handle); return handle; error: get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle); - LOG_ERROR( - "add_pbap_sdp: failed to register PBAP service, stage: %s, " - "service_name: %s", + log::error( + "add_pbap_sdp: failed to register PBAP service, stage: {}, service_name: " + "{}", stage, name); return 0; } // Registers a service with the given |name| and |channel| as an OBEX Push // protocol. static int add_ops_sdp(const char* name, const int channel) { - LOG_VERBOSE("add_ops_sdp: scn %d, service_name %s", channel, name); + log::verbose("add_ops_sdp: scn {}, service_name {}", channel, name); uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (handle == 0) { - LOG_ERROR( - "add_ops_sdp: failed to create sdp record, " - "service_name: %s", - name); + log::error("add_ops_sdp: failed to create sdp record, service_name: {}", + name); return 0; } @@ -325,18 +324,18 @@ static int add_ops_sdp(const char* name, const int channel) { // Notify the system that we've got a new service class UUID. bta_sys_add_uuid(UUID_SERVCLASS_OBEX_OBJECT_PUSH); - LOG_VERBOSE( - "ad_maps_sdp: service registered successfully, " - "service_name: %s, handle 0x%08x)", + log::verbose( + "ad_maps_sdp: service registered successfully, service_name: {}, handle " + "0x{:08x})", name, handle); return handle; error: get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle); - LOG_ERROR( - "add_ops_sdp: failed to register OPS service, " - "stage: %s, service_name: %s", + log::error( + "add_ops_sdp: failed to register OPS service, stage: {}, service_name: " + "{}", stage, name); return 0; } @@ -344,14 +343,12 @@ error: // Registers a service with the given |name| and |channel| as a serial port // profile protocol. static int add_spp_sdp(const char* name, const int channel) { - LOG_VERBOSE("add_spp_sdp: scn %d, service_name %s", channel, name); + log::verbose("add_spp_sdp: scn {}, service_name {}", channel, name); int handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord(); if (handle == 0) { - LOG_ERROR( - "add_spp_sdp: failed to create sdp record, " - "service_name: %s", - name); + log::error("add_spp_sdp: failed to create sdp record, service_name: {}", + name); return 0; } @@ -372,18 +369,18 @@ static int add_spp_sdp(const char* name, const int channel) { handle, UUID_SERVCLASS_SERIAL_PORT, SPP_PROFILE_VERSION)) goto error; - LOG_VERBOSE( - "add_spp_sdp: service registered successfully, " - "service_name: %s, handle 0x%08x)", + log::verbose( + "add_spp_sdp: service registered successfully, service_name: {}, handle " + "0x{:08x})", name, handle); return handle; error: get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle); - LOG_ERROR( - "add_spp_sdp: failed to register SPP service, " - "stage: %s, service_name: %s", + log::error( + "add_spp_sdp: failed to register SPP service, stage: {}, service_name: " + "{}", stage, name); return 0; } @@ -394,8 +391,8 @@ error: // number if the |uuid| matches one of the preregistered bluez SDP records. static int add_rfc_sdp_by_uuid(const char* name, const Uuid& uuid, const int channel) { - LOG_VERBOSE("%s: uuid: %s, service_name: %s, channel: %d", __func__, - uuid.ToString().c_str(), name, channel); + log::verbose("uuid: {}, service_name: {}, channel: {}", uuid.ToString(), name, + channel); /* * Bluetooth Socket API relies on having preregistered bluez sdp records for @@ -479,7 +476,7 @@ int add_rfc_sdp_rec(const char* name, Uuid uuid, const int channel) { // Deletes an SDP record with the given |handle|. void del_rfc_sdp_rec(int handle) { - LOG_VERBOSE("del_rfc_sdp_rec: handle:0x%x", handle); + log::verbose("del_rfc_sdp_rec: handle:0x{:x}", handle); if ((handle != -1) && (handle != 0)) { // Remove the custom 128-bit UUID from EIR diff --git a/system/btif/src/btif_sock_thread.cc b/system/btif/src/btif_sock_thread.cc index 7dbdf79cb9f..c3cefcbd74d 100644 --- a/system/btif/src/btif_sock_thread.cc +++ b/system/btif/src/btif_sock_thread.cc @@ -29,6 +29,7 @@ #include "btif_sock_thread.h" #include <alloca.h> +#include <bluetooth/log.h> #include <fcntl.h> #include <features.h> #include <poll.h> @@ -50,11 +51,9 @@ #include "os/log.h" #include "osi/include/osi.h" // OSI_NO_INTR -#define asrt(s) \ - do { \ - if (!(s)) \ - LOG_ERROR("## %s assert %s failed at line:%d ##", __func__, #s, \ - __LINE__); \ +#define asrt(s) \ + do { \ + if (!(s)) log::error("## assert {} failed ##", #s); \ } while (0) #define MAX_THREAD 8 @@ -70,6 +69,8 @@ #define CMD_REMOVE_FD 4 #define CMD_USER_PRIVATE 5 +using namespace bluetooth; + struct poll_slot_t { struct pollfd pfd; uint32_t user_id; @@ -108,7 +109,7 @@ static inline int create_thread(void* (*start_routine)(void*), void* arg, ret = pthread_create(thread_id, &thread_attr, start_routine, arg); if (ret != 0) { - LOG_ERROR("pthread_create : %s", strerror(errno)); + log::error("pthread_create : {}", strerror(errno)); return ret; } /* We need to lower the priority of this thread to ensure the stack gets @@ -132,7 +133,7 @@ static int alloc_thread_slot() { return i; } } - LOG_ERROR("execeeded max thread count"); + log::error("execeeded max thread count"); return -1; } static void free_thread_slot(int h) { @@ -140,7 +141,7 @@ static void free_thread_slot(int h) { close_cmd_fd(h); ts[h].used = 0; } else - LOG_ERROR("invalid thread handle:%d", h); + log::error("invalid thread handle:{}", h); } void btsock_thread_init() { static int initialized; @@ -166,7 +167,7 @@ int btsock_thread_create(btsock_signaled_cb callback, pthread_t thread; int status = create_thread(sock_poll_thread, (void*)(uintptr_t)h, &thread); if (status) { - LOG_ERROR("create_thread failed: %s", strerror(status)); + log::error("create_thread failed: {}", strerror(status)); free_thread_slot(h); return -1; } @@ -182,7 +183,7 @@ int btsock_thread_create(btsock_signaled_cb callback, static inline void init_cmd_fd(int h) { asrt(ts[h].cmd_fdr == -1 && ts[h].cmd_fdw == -1); if (socketpair(AF_UNIX, SOCK_STREAM, 0, &ts[h].cmd_fdr) < 0) { - LOG_ERROR("socketpair failed: %s", strerror(errno)); + log::error("socketpair failed: {}", strerror(errno)); return; } // add the cmd fd for read & write @@ -207,11 +208,11 @@ typedef struct { } sock_cmd_t; int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) { if (h < 0 || h >= MAX_THREAD) { - LOG_ERROR("invalid bt thread handle:%d", h); + log::error("invalid bt thread handle:{}", h); return false; } if (ts[h].cmd_fdw == -1) { - LOG_ERROR("cmd socket is not created. socket thread may not initialized"); + log::error("cmd socket is not created. socket thread may not initialized"); return false; } if (flags & SOCK_THREAD_ADD_FD_SYNC) { @@ -222,7 +223,7 @@ int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) { add_poll(h, fd, type, flags, user_id); return true; } - LOG_WARN( + log::warn( "THREAD_ADD_FD_SYNC is not called in poll thread, fallback to async"); } sock_cmd_t cmd = {CMD_ADD_FD, fd, type, flags, user_id}; @@ -235,11 +236,11 @@ int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) { bool btsock_thread_remove_fd_and_close(int thread_handle, int fd) { if (thread_handle < 0 || thread_handle >= MAX_THREAD) { - LOG_ERROR("%s invalid thread handle: %d", __func__, thread_handle); + log::error("invalid thread handle: {}", thread_handle); return false; } if (fd == -1) { - LOG_ERROR("%s invalid file descriptor.", __func__); + log::error("invalid file descriptor."); return false; } @@ -254,11 +255,11 @@ bool btsock_thread_remove_fd_and_close(int thread_handle, int fd) { int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size, uint32_t user_id) { if (h < 0 || h >= MAX_THREAD) { - LOG_ERROR("invalid bt thread handle:%d", h); + log::error("invalid bt thread handle:{}", h); return false; } if (ts[h].cmd_fdw == -1) { - LOG_ERROR("cmd socket is not created. socket thread may not initialized"); + log::error("cmd socket is not created. socket thread may not initialized"); return false; } sock_cmd_t cmd = {CMD_USER_PRIVATE, 0, type, size, user_id}; @@ -271,8 +272,8 @@ int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size, *cmd_send = cmd; memcpy(cmd_send + 1, data, size); } else { - LOG_ERROR("alloca failed at h:%d, cmd type:%d, size:%d", h, type, - size_send); + log::error("alloca failed at h:{}, cmd type:{}, size:{}", h, type, + size_send); return false; } } @@ -284,11 +285,11 @@ int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size, } int btsock_thread_wakeup(int h) { if (h < 0 || h >= MAX_THREAD) { - LOG_ERROR("invalid bt thread handle:%d", h); + log::error("invalid bt thread handle:{}", h); return false; } if (ts[h].cmd_fdw == -1) { - LOG_ERROR("thread handle:%d, cmd socket is not created", h); + log::error("thread handle:{}, cmd socket is not created", h); return false; } sock_cmd_t cmd = {CMD_WAKEUP, 0, 0, 0, 0}; @@ -300,11 +301,11 @@ int btsock_thread_wakeup(int h) { } int btsock_thread_exit(int h) { if (h < 0 || h >= MAX_THREAD) { - LOG_ERROR("invalid bt thread slot:%d", h); + log::error("invalid bt thread slot:{}", h); return false; } if (ts[h].cmd_fdw == -1) { - LOG_ERROR("cmd socket is not created"); + log::error("cmd socket is not created"); return false; } sock_cmd_t cmd = {CMD_EXIT, 0, 0, 0, 0}; @@ -347,8 +348,8 @@ static inline void set_poll(poll_slot_t* ps, int fd, int type, int flags, ps->pfd.fd = fd; ps->user_id = user_id; if (ps->type != 0 && ps->type != type) - LOG_ERROR("poll socket type should not changed! type was:%d, type now:%d", - ps->type, type); + log::error("poll socket type should not changed! type was:{}, type now:{}", + ps->type, type); ps->type = type; ps->flags = flags; ps->pfd.events = flags2pevents(flags); @@ -376,7 +377,7 @@ static inline void add_poll(int h, int fd, int type, int flags, ++ts[h].poll_count; return; } - LOG_ERROR("exceeded max poll slot:%d!", MAX_POLL); + log::error("exceeded max poll slot:{}!", MAX_POLL); } static inline void remove_poll(int h, poll_slot_t* ps, int flags) { if (flags == ps->flags) { @@ -399,7 +400,7 @@ static int process_cmd_sock(int h) { OSI_NO_INTR(ret = recv(fd, &cmd, sizeof(cmd), MSG_WAITALL)); if (ret != sizeof(cmd)) { - LOG_ERROR("recv cmd errno:%d", errno); + log::error("recv cmd errno:{}", errno); return false; } switch (cmd.id) { @@ -426,7 +427,7 @@ static int process_cmd_sock(int h) { case CMD_EXIT: return false; default: - LOG_WARN("unknown cmd: %d", cmd.id); + log::warn("unknown cmd: {}", cmd.id); break; } return true; @@ -440,7 +441,7 @@ static void process_data_sock(int h, struct pollfd* pfds, int pfds_count, if (pfds[i].revents) { int ps_i = ts[h].psi[i]; if (ts[h].ps[ps_i].pfd.fd == -1) { - LOG_INFO("Socket has been removed from poll set"); + log::info("Socket has been removed from poll set"); continue; } asrt(pfds[i].fd == ts[h].ps[ps_i].pfd.fd); @@ -472,9 +473,9 @@ static void prepare_poll_fds(int h, struct pollfd* pfds) { asrt(ts[h].poll_count <= MAX_POLL); while (count < ts[h].poll_count) { if (ps_i >= MAX_POLL) { - LOG_ERROR( - "exceed max poll range, ps_i:%d, MAX_POLL:%d, count:%d, " - "ts[h].poll_count:%d", + log::error( + "exceed max poll range, ps_i:{}, MAX_POLL:{}, count:{}, " + "ts[h].poll_count:{}", ps_i, MAX_POLL, count, ts[h].poll_count); return; } @@ -497,8 +498,8 @@ static void* sock_poll_thread(void* arg) { int ret; OSI_NO_INTR(ret = poll(pfds.data(), ts[h].poll_count, -1)); if (ret == -1) { - LOG_ERROR("poll ret -1, exit the thread, errno:%d, err:%s", errno, - strerror(errno)); + log::error("poll ret -1, exit the thread, errno:{}, err:{}", errno, + strerror(errno)); break; } if (ret != 0) { @@ -508,7 +509,7 @@ static void* sock_poll_thread(void* arg) { { asrt(pfds[0].fd == ts[h].cmd_fdr); if (!process_cmd_sock(h)) { - LOG_INFO("h:%d, process_cmd_sock return false, exit...", h); + log::info("h:{}, process_cmd_sock return false, exit...", h); break; } if (ret == 1) @@ -519,9 +520,9 @@ static void* sock_poll_thread(void* arg) { if (need_process_data_fd) process_data_sock(h, pfds.data(), pfds_count, ret); } else { - LOG_INFO("no data, select ret: %d", ret); + log::info("no data, select ret: {}", ret); }; } - LOG_INFO("socket poll thread exiting, h:%d", h); + log::info("socket poll thread exiting, h:{}", h); return 0; } diff --git a/system/btif/src/btif_sock_util.cc b/system/btif/src/btif_sock_util.cc index 72f7bbb9724..536f824d9e0 100644 --- a/system/btif/src/btif_sock_util.cc +++ b/system/btif/src/btif_sock_util.cc @@ -21,6 +21,7 @@ #include "btif_sock_util.h" #include <arpa/inet.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_sock.h> #include <netinet/in.h> @@ -37,13 +38,13 @@ #include "os/log.h" #include "osi/include/osi.h" -#define asrt(s) \ - do { \ - if (!(s)) \ - LOG_ERROR("## %s assert %s failed at line:%d ##", __func__, #s, \ - __LINE__); \ +#define asrt(s) \ + do { \ + if (!(s)) log::error("## assert {} failed ##", #s); \ } while (0) +using namespace bluetooth; + int sock_send_all(int sock_fd, const uint8_t* buf, int len) { int s = len; @@ -51,7 +52,7 @@ int sock_send_all(int sock_fd, const uint8_t* buf, int len) { ssize_t ret; OSI_NO_INTR(ret = send(sock_fd, buf, s, 0)); if (ret <= 0) { - LOG_ERROR("sock fd:%d send errno:%d, ret:%zd", sock_fd, errno, ret); + log::error("sock fd:{} send errno:{}, ret:{}", sock_fd, errno, ret); return -1; } buf += ret; @@ -66,7 +67,7 @@ int sock_recv_all(int sock_fd, uint8_t* buf, int len) { ssize_t ret; OSI_NO_INTR(ret = recv(sock_fd, buf, r, MSG_WAITALL)); if (ret <= 0) { - LOG_ERROR("sock fd:%d recv errno:%d, ret:%zd", sock_fd, errno, ret); + log::error("sock fd:{} recv errno:{}, ret:{}", sock_fd, errno, ret); return -1; } buf += ret; @@ -109,8 +110,8 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) { ssize_t ret; OSI_NO_INTR(ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL)); if (ret < 0) { - LOG_ERROR("fd:%d, send_fd:%d, sendmsg ret:%d, errno:%d, %s", sock_fd, - send_fd, (int)ret, errno, strerror(errno)); + log::error("fd:{}, send_fd:{}, sendmsg ret:{}, errno:{}, {}", sock_fd, + send_fd, (int)ret, errno, strerror(errno)); ret_len = -1; break; } @@ -121,7 +122,7 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) { // Wipes out any msg_control too memset(&msg, 0, sizeof(msg)); } - LOG_VERBOSE("close fd:%d after sent", send_fd); + log::verbose("close fd:{} after sent", send_fd); // TODO: This seems wrong - if the FD is not opened in JAVA before this is // called // we get a "socket closed" exception in java, when reading from the diff --git a/system/btif/src/btif_storage.cc b/system/btif/src/btif_storage.cc index 8cfc4e81771..930fda8a1ea 100644 --- a/system/btif/src/btif_storage.cc +++ b/system/btif/src/btif_storage.cc @@ -34,6 +34,7 @@ #include <alloca.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -62,6 +63,7 @@ using base::Bind; using bluetooth::Uuid; +using namespace bluetooth; /******************************************************************************* * Constants & Macros @@ -112,8 +114,8 @@ static bool btif_has_ble_keys(const std::string& bdstr); static void btif_storage_set_mode(RawAddress* remote_bd_addr) { std::string bdstr = remote_bd_addr->ToString(); if (GetInterfaceToProfiles()->config->isRestrictedMode()) { - LOG_INFO("%s will be removed exiting restricted mode", - ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); + log::info("{} will be removed exiting restricted mode", + ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); btif_config_set_int(bdstr, BTIF_STORAGE_KEY_RESTRICTED, 1); } } @@ -126,9 +128,9 @@ static bool prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) { char value[1024]; if (prop->len <= 0 || prop->len > (int)sizeof(value) - 1) { - LOG_WARN( - "Unable to save property to configuration file type:%d, " - " len:%d is invalid", + log::warn( + "Unable to save property to configuration file type:{}, len:{} is " + "invalid", prop->type, prop->len); return false; } @@ -214,7 +216,7 @@ static bool prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) { btif_config_set_str(bdstr, BTIF_STORAGE_KEY_DIS_MODEL_NUM, value); } break; default: - LOG_ERROR("Unknown prop type:%d", prop->type); + log::error("Unknown prop type:{}", prop->type); return false; } @@ -227,8 +229,8 @@ static bool cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) { bdstr = remote_bd_addr->ToString(); } if (prop->len <= 0) { - LOG_WARN("Invalid property read from configuration file type:%d, len:%d", - prop->type, prop->len); + log::warn("Invalid property read from configuration file type:{}, len:{}", + prop->type, prop->len); return false; } bool ret = false; @@ -383,7 +385,7 @@ static bool cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) { } break; default: - LOG_ERROR("Unknown prop type:%d", prop->type); + log::error("Unknown prop type:{}", prop->type); return false; } return ret; @@ -442,7 +444,7 @@ static bt_status_t btif_in_fetch_bonded_devices( for (const auto& bd_addr : btif_config_get_paired_devices()) { auto name = bd_addr.ToString(); - LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); LinkKey link_key; size_t size = sizeof(link_key); if (btif_config_get_bin(name, BTIF_STORAGE_KEY_LINK_KEY, link_key.data(), @@ -470,7 +472,7 @@ static bt_status_t btif_in_fetch_bonded_devices( if (p_bonded_devices->num_devices < BTM_SEC_MAX_DEVICE_RECORDS) { p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr; } else { - LOG_WARN("Exceed the max number of bonded devices"); + log::warn("Exceed the max number of bonded devices"); } } else { bt_linkkey_file_found = false; @@ -478,8 +480,8 @@ static bt_status_t btif_in_fetch_bonded_devices( } if (!btif_in_fetch_bonded_ble_device(name, add, p_bonded_devices) && !bt_linkkey_file_found) { - LOG_VERBOSE("No link key or ble key found for device:%s", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("No link key or ble key found for device:{}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); } } return BT_STATUS_SUCCESS; @@ -503,8 +505,8 @@ static void btif_read_le_key(const uint8_t key_type, const size_t key_len, *device_added = true; } - LOG_VERBOSE("Adding key type %d for %s", key_type, - ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Adding key type {} for {}", key_type, + ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); BTA_DmAddBleKey(bd_addr, &key, key_type); } @@ -619,11 +621,11 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) { /* Fetch the local BD ADDR */ const controller_t* controller = controller_get_interface(); if (!controller->get_is_ready()) { - LOG_ERROR("Controller not ready! Unable to return Bluetooth Address"); + log::error("Controller not ready! Unable to return Bluetooth Address"); *bd_addr = RawAddress::kEmpty; return BT_STATUS_FAIL; } else { - LOG_INFO("Controller ready!"); + log::info("Controller ready!"); *bd_addr = *controller->get_address(); } property->len = RawAddress::kLength; @@ -633,8 +635,8 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) { btif_in_fetch_bonded_devices(&bonded_devices, 0); - LOG_VERBOSE( - "BT_PROPERTY_ADAPTER_BONDED_DEVICES: Number of bonded devices=%d", + log::verbose( + "BT_PROPERTY_ADAPTER_BONDED_DEVICES: Number of bonded devices={}", bonded_devices.num_devices); property->len = bonded_devices.num_devices * RawAddress::kLength; @@ -649,7 +651,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) { uint32_t i; tBTA_SERVICE_MASK service_mask = btif_get_enabled_services_mask(); - LOG_INFO("Service_mask=0x%x", service_mask); + log::info("Service_mask=0x{:x}", service_mask); for (i = 0; i < BTA_MAX_SERVICE_ID; i++) { /* This should eventually become a function when more services are enabled */ @@ -857,8 +859,8 @@ bt_status_t btif_storage_add_bonded_device(RawAddress* remote_bd_addr, bt_status_t btif_storage_remove_bonded_device( const RawAddress* remote_bd_addr) { std::string bdstr = remote_bd_addr->ToString(); - LOG_INFO("Removing bonded device addr=%s", - ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); + log::info("Removing bonded device addr={}", + ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); btif_config_remove_device(bdstr); @@ -866,7 +868,7 @@ bt_status_t btif_storage_remove_bonded_device( auto paired_devices = btif_config_get_paired_devices(); if (paired_devices.empty() && bluetooth::common::init_flags::irk_rotation_is_enabled()) { - LOG_INFO("Last paired device removed, resetting IRK"); + log::info("Last paired device removed, resetting IRK"); BTA_DmBleResetId(); } return BT_STATUS_SUCCESS; @@ -897,8 +899,8 @@ static void remove_devices_with_sample_ltk() { } for (RawAddress address : bad_ltk) { - LOG_ERROR("Removing bond to device using test TLK: %s", - ADDRESS_TO_LOGGABLE_CSTR(address)); + log::error("Removing bond to device using test TLK: {}", + ADDRESS_TO_LOGGABLE_CSTR(address)); btif_storage_remove_bonded_device(&address); } @@ -932,13 +934,13 @@ void btif_storage_load_le_devices(void) { bonded_devices.devices[i], BTM_LE_KEY_PID, (uint8_t*)&key, sizeof(tBTM_LE_PID_KEYS)) == BT_STATUS_SUCCESS) { if (bonded_devices.devices[i] != key.pid_key.identity_addr) { - LOG_INFO("Found device with a known identity address %s %s", - ADDRESS_TO_LOGGABLE_CSTR(bonded_devices.devices[i]), - ADDRESS_TO_LOGGABLE_CSTR(key.pid_key.identity_addr)); + log::info("Found device with a known identity address {} {}", + ADDRESS_TO_LOGGABLE_CSTR(bonded_devices.devices[i]), + ADDRESS_TO_LOGGABLE_CSTR(key.pid_key.identity_addr)); if (bonded_devices.devices[i].IsEmpty() || key.pid_key.identity_addr.IsEmpty()) { - LOG_WARN("Address is empty! Skip"); + log::warn("Address is empty! Skip"); } else { consolidated_devices.emplace_back(bonded_devices.devices[i], key.pid_key.identity_addr); @@ -1065,7 +1067,7 @@ bt_status_t btif_storage_load_bonded_devices(void) { osi_free(devices_list); } - LOG_VERBOSE("Number of bonded devices found=%d", bonded_devices.num_devices); + log::verbose("Number of bonded devices found={}", bonded_devices.num_devices); { for (i = 0; i < bonded_devices.num_devices; i++) { @@ -1174,7 +1176,7 @@ bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr, } } - LOG_WARN("Unknown LE key type: %d", key_type); + log::warn("Unknown LE key type: {}", key_type); return BT_STATUS_FAIL; } @@ -1202,7 +1204,7 @@ bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr, } } - LOG_WARN("Unknown LE key type: %d", key_type); + log::warn("Unknown LE key type: {}", key_type); return BT_STATUS_FAIL; } @@ -1219,8 +1221,8 @@ bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr, bt_status_t btif_storage_remove_ble_bonding_keys( const RawAddress* remote_bd_addr) { std::string bdstr = remote_bd_addr->ToString(); - LOG_INFO("Removing bonding keys for bd addr:%s", - ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); + log::info("Removing bonding keys for bd addr:{}", + ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr)); bool ret = true; for (size_t i = 0; i < std::size(BTIF_STORAGE_LE_KEYS); i++) { auto key_name = BTIF_STORAGE_LE_KEYS[i].name; @@ -1252,7 +1254,7 @@ bt_status_t btif_storage_add_ble_local_key(const Octet16& key_value, return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; } } - LOG_WARN("Unknown LE key type: %d", key_type); + log::warn("Unknown LE key type: {}", key_type); return BT_STATUS_FAIL; } @@ -1272,7 +1274,7 @@ bt_status_t btif_storage_get_ble_local_key(uint8_t key_type, return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; } } - LOG_WARN("Unknown LE key type: %d", key_type); + log::warn("Unknown LE key type: {}", key_type); return BT_STATUS_FAIL; } @@ -1313,7 +1315,7 @@ bt_status_t btif_in_fetch_bonded_ble_device( if ((device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE || btif_has_ble_keys(remote_bd_addr)) { - LOG_VERBOSE("Found a LE device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); + log::verbose("Found a LE device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr)); if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) != BT_STATUS_SUCCESS) { @@ -1332,7 +1334,7 @@ bt_status_t btif_in_fetch_bonded_ble_device( if (p_bonded_devices->num_devices < BTM_SEC_MAX_DEVICE_RECORDS) { p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr; } else { - LOG_WARN("Exceed the max number of bonded devices"); + log::warn("Exceed the max number of bonded devices"); } btif_gatts_add_bonded_dev_from_nv(bd_addr); } @@ -1370,7 +1372,7 @@ void btif_storage_set_remote_addr_type(const RawAddress& remote_bd_addr, if (!btif_config_set_int(remote_bd_addr.ToString(), BTIF_STORAGE_KEY_ADDR_TYPE, static_cast<int>(addr_type))) - LOG_ERROR("Unable to set storage property"); + log::error("Unable to set storage property"); else { #if TARGET_FLOSS // Floss needs to get address type for diagnosis API. @@ -1383,7 +1385,7 @@ void btif_storage_set_remote_device_type(const RawAddress& remote_bd_addr, const tBT_DEVICE_TYPE& device_type) { if (!btif_config_set_int(remote_bd_addr.ToString(), BTIF_STORAGE_KEY_DEV_TYPE, static_cast<int>(device_type))) - LOG_ERROR("Unable to set storage property"); + log::error("Unable to set storage property"); } bool btif_has_ble_keys(const std::string& bdstr) { @@ -1433,9 +1435,10 @@ void btif_storage_set_gatt_sr_supp_feat(const RawAddress& addr, uint8_t feat) { FROM_HERE, Bind( [](const RawAddress& addr, uint8_t feat) { std::string bdstr = addr.ToString(); - VLOG(2) << "GATT server supported features for: " - << ADDRESS_TO_LOGGABLE_STR(addr) - << " features: " << +feat; + log::verbose( + "GATT server supported features for: {} features: " + "{}", + ADDRESS_TO_LOGGABLE_STR(addr), feat); btif_config_set_int( bdstr, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED, feat); }, @@ -1448,8 +1451,8 @@ uint8_t btif_storage_get_sr_supp_feat(const RawAddress& bd_addr) { int value = 0; btif_config_get_int(name, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED, &value); - LOG_VERBOSE("Remote device: %s GATT server supported features 0x%02x", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value); + log::verbose("Remote device: {} GATT server supported features 0x{:02x}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value); return value; } @@ -1496,8 +1499,8 @@ void btif_storage_set_gatt_cl_supp_feat(const RawAddress& bd_addr, FROM_HERE, Bind( [](const RawAddress& bd_addr, uint8_t feat) { std::string bdstr = bd_addr.ToString(); - VLOG(2) << "saving gatt client supported feat: " - << ADDRESS_TO_LOGGABLE_STR(bd_addr); + log::verbose("saving gatt client supported feat: {}", + ADDRESS_TO_LOGGABLE_STR(bd_addr)); btif_config_set_int( bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED, feat); }, @@ -1510,8 +1513,8 @@ uint8_t btif_storage_get_gatt_cl_supp_feat(const RawAddress& bd_addr) { int value = 0; btif_config_get_int(name, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED, &value); - LOG_VERBOSE("Remote device: %s GATT client supported features 0x%02x", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value); + log::verbose("Remote device: {} GATT client supported features 0x{:02x}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value); return value; } diff --git a/system/btif/src/btif_vc.cc b/system/btif/src/btif_vc.cc index 21e8edc77c5..3a29255e438 100644 --- a/system/btif/src/btif_vc.cc +++ b/system/btif/src/btif_vc.cc @@ -20,6 +20,7 @@ #include <base/functional/bind.h> #include <base/location.h> #include <base/logging.h> +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <hardware/bt_vc.h> @@ -34,6 +35,7 @@ using base::Unretained; using bluetooth::vc::ConnectionState; using bluetooth::vc::VolumeControlCallbacks; using bluetooth::vc::VolumeControlInterface; +using namespace bluetooth; namespace { std::unique_ptr<VolumeControlInterface> vc_instance; @@ -119,9 +121,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void Connect(const RawAddress& address) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -132,9 +134,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void Disconnect(const RawAddress& address) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } do_in_main_thread(FROM_HERE, @@ -145,9 +147,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void SetVolume(std::variant<RawAddress, int> addr_or_group_id, uint8_t volume) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -158,9 +160,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void Mute(std::variant<RawAddress, int> addr_or_group_id) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -171,9 +173,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void Unmute(std::variant<RawAddress, int> addr_or_group_id) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -184,9 +186,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void RemoveDevice(const RawAddress& address) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -201,9 +203,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void GetExtAudioOutVolumeOffset(const RawAddress& address, uint8_t ext_output_id) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -217,9 +219,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, uint8_t ext_output_id, int16_t offset_val) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -232,9 +234,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void GetExtAudioOutLocation(const RawAddress& address, uint8_t ext_output_id) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -246,9 +248,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void SetExtAudioOutLocation(const RawAddress& address, uint8_t ext_output_id, uint32_t location) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -260,9 +262,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void GetExtAudioOutDescription(const RawAddress& address, uint8_t ext_output_id) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -275,9 +277,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, uint8_t ext_output_id, std::string descr) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } @@ -288,9 +290,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface, void Cleanup(void) override { if (!initialized || !VolumeControl::IsVolumeControlRunning()) { - VLOG(1) << __func__ - << " call ignored, due to already started cleanup procedure or " - "service being not read"; + log::verbose( + "call ignored, due to already started cleanup procedure or service " + "being not read"); return; } diff --git a/system/btif/src/stack_manager.cc b/system/btif/src/stack_manager.cc index 8fdc1e691ae..d388e6f4c92 100644 --- a/system/btif/src/stack_manager.cc +++ b/system/btif/src/stack_manager.cc @@ -18,6 +18,7 @@ #define LOG_TAG "bt_stack_manager" +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <cstdlib> @@ -109,6 +110,7 @@ void BTA_dm_on_hw_on(); void BTA_dm_on_hw_off(); using bluetooth::common::MessageLoopThread; +using namespace bluetooth; static MessageLoopThread management_thread("bt_stack_manager_thread"); @@ -183,7 +185,7 @@ static void clean_up_stack(ProfileStopCallback stopProfiles) { if (status == std::future_status::ready) { management_thread.ShutDown(); } else { - LOG_ERROR("cleanup could not be completed in time, abandon it"); + log::error("cleanup could not be completed in time, abandon it"); } } @@ -228,7 +230,7 @@ inline const module_t* get_local_module(const char* name) { } } - LOG_ALWAYS_FATAL("Cannot find module %s, aborting", name); + log::fatal("Cannot find module {}, aborting", name); return nullptr; } @@ -256,15 +258,15 @@ static void init_stack_internal(bluetooth::core::CoreInterface* interface) { // Synchronous function to initialize the stack static void event_init_stack(std::promise<void> promise, bluetooth::core::CoreInterface* interface) { - LOG_INFO("is initializing the stack"); + log::info("is initializing the stack"); if (stack_is_initialized) { - LOG_INFO("found the stack already in initialized state"); + log::info("found the stack already in initialized state"); } else { init_stack_internal(interface); } - LOG_INFO("finished"); + log::info("finished"); promise.set_value(); } @@ -272,7 +274,7 @@ static void event_init_stack(std::promise<void> promise, static void ensure_stack_is_initialized( bluetooth::core::CoreInterface* interface) { if (!stack_is_initialized) { - LOG_WARN("found the stack was uninitialized. Initializing now."); + log::warn("found the stack was uninitialized. Initializing now."); // No future needed since we are calling it directly init_stack_internal(interface); } @@ -283,17 +285,17 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface, ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles) { if (stack_is_running) { - LOG_INFO("%s stack already brought up", __func__); + log::info("stack already brought up"); return; } ensure_stack_is_initialized(interface); - LOG_INFO("%s is bringing up the stack", __func__); + log::info("is bringing up the stack"); future_t* local_hack_future = future_new(); hack_future = local_hack_future; - LOG_INFO("%s Gd shim module enabled", __func__); + log::info("Gd shim module enabled"); get_btm_client_interface().lifecycle.btm_init(); module_start_up(get_local_module(BTIF_CONFIG_MODULE)); @@ -323,7 +325,7 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface, BTA_dm_on_hw_on(); if (future_await(local_hack_future) != FUTURE_SUCCESS) { - LOG_ERROR("%s failed to start up the stack", __func__); + log::error("failed to start up the stack"); stack_is_running = true; // So stack shutdown actually happens event_shut_down_stack(stopProfiles); return; @@ -332,18 +334,18 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface, module_start_up(get_local_module(RUST_MODULE)); stack_is_running = true; - LOG_INFO("%s finished", __func__); + log::info("finished"); do_in_jni_thread(FROM_HERE, base::BindOnce(event_signal_stack_up, nullptr)); } // Synchronous function to shut down the stack static void event_shut_down_stack(ProfileStopCallback stopProfiles) { if (!stack_is_running) { - LOG_INFO("%s stack is already brought down", __func__); + log::info("stack is already brought down"); return; } - LOG_INFO("%s is bringing down the stack", __func__); + log::info("is bringing down the stack"); future_t* local_hack_future = future_new(); hack_future = local_hack_future; stack_is_running = false; @@ -383,13 +385,12 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) { hack_future = future_new(); do_in_jni_thread(FROM_HERE, base::BindOnce(event_signal_stack_down, nullptr)); future_await(hack_future); - LOG_INFO("%s finished", __func__); + log::info("finished"); } static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) { if (stack_is_running) { - LOG_WARN("%s found the stack was still running. Bringing it down now.", - __func__); + log::warn("found the stack was still running. Bringing it down now."); event_shut_down_stack(stopProfiles); } } @@ -398,13 +399,13 @@ static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) { static void event_clean_up_stack(std::promise<void> promise, ProfileStopCallback stopProfiles) { if (!stack_is_initialized) { - LOG_INFO("%s found the stack already in a clean state", __func__); + log::info("found the stack already in a clean state"); goto cleanup; } ensure_stack_is_not_running(stopProfiles); - LOG_INFO("%s is cleaning up the stack", __func__); + log::info("is cleaning up the stack"); stack_is_initialized = false; btif_cleanup_bluetooth(); @@ -416,13 +417,13 @@ static void event_clean_up_stack(std::promise<void> promise, module_clean_up(get_local_module(DEVICE_IOT_CONFIG_MODULE)); module_clean_up(get_local_module(OSI_MODULE)); - LOG_INFO("%s Gd shim module disabled", __func__); + log::info("Gd shim module disabled"); module_shut_down(get_local_module(GD_SHIM_MODULE)); main_thread_shut_down(); module_management_stop(); - LOG_INFO("%s finished", __func__); + log::info("finished"); cleanup:; promise.set_value(); @@ -447,7 +448,7 @@ static void ensure_manager_initialized() { management_thread.StartUp(); if (!management_thread.IsRunning()) { - LOG_ERROR("%s unable to start stack management thread", __func__); + log::error("unable to start stack management thread"); return; } } diff --git a/system/include/hardware/bluetooth.h b/system/include/hardware/bluetooth.h index aabe594abce..683fb5525d3 100644 --- a/system/include/hardware/bluetooth.h +++ b/system/include/hardware/bluetooth.h @@ -989,4 +989,20 @@ typedef struct { #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface" +#if __has_include(<bluetooth/log.h>) +#include <bluetooth/log.h> + +namespace fmt { +template <> +struct formatter<bt_status_t> : enum_formatter<bt_status_t> {}; +template <> +struct formatter<bt_scan_mode_t> : enum_formatter<bt_scan_mode_t> {}; +template <> +struct formatter<bt_bond_state_t> : enum_formatter<bt_bond_state_t> {}; +template <> +struct formatter<bt_property_type_t> : enum_formatter<bt_property_type_t> {}; +} // namespace fmt + +#endif // __has_include(<bluetooth/log.h>) + #endif /* ANDROID_INCLUDE_BLUETOOTH_H */ diff --git a/system/include/hardware/bt_av.h b/system/include/hardware/bt_av.h index 2a45af62d82..80512e34ede 100644 --- a/system/include/hardware/bt_av.h +++ b/system/include/hardware/bt_av.h @@ -436,6 +436,11 @@ __END_DECLS namespace fmt { template <> +struct formatter<btav_connection_state_t> + : enum_formatter<btav_connection_state_t> {}; +template <> +struct formatter<btav_audio_state_t> : enum_formatter<btav_audio_state_t> {}; +template <> struct formatter<btav_a2dp_codec_bits_per_sample_t> : enum_formatter<btav_a2dp_codec_bits_per_sample_t> {}; template <> diff --git a/system/include/hardware/bt_hd.h b/system/include/hardware/bt_hd.h index 0566e89455d..732dc6168b3 100644 --- a/system/include/hardware/bt_hd.h +++ b/system/include/hardware/bt_hd.h @@ -126,4 +126,14 @@ typedef struct { __END_DECLS +#if __has_include(<bluetooth/log.h>) +#include <bluetooth/log.h> + +namespace fmt { +template <> +struct formatter<bthd_report_type_t> : enum_formatter<bthd_report_type_t> {}; +} // namespace fmt + +#endif // __has_include(<bluetooth/log.h>) + #endif /* ANDROID_INCLUDE_BT_HD_H */ diff --git a/system/include/hardware/bt_hf.h b/system/include/hardware/bt_hf.h index e69e8412b49..074c896fec9 100644 --- a/system/include/hardware/bt_hf.h +++ b/system/include/hardware/bt_hf.h @@ -144,8 +144,19 @@ namespace fmt { template <> struct formatter<bluetooth::headset::bthf_connection_state_t> : enum_formatter<bluetooth::headset::bthf_connection_state_t> {}; - template <> struct formatter<bluetooth::headset::bthf_audio_state_t> : enum_formatter<bluetooth::headset::bthf_audio_state_t> {}; +template <> +struct formatter<bluetooth::headset::bthf_call_addrtype_t> + : enum_formatter<bluetooth::headset::bthf_call_addrtype_t> {}; +template <> +struct formatter<bluetooth::headset::bthf_call_mode_t> + : enum_formatter<bluetooth::headset::bthf_call_mode_t> {}; +template <> +struct formatter<bluetooth::headset::bthf_call_state_t> + : enum_formatter<bluetooth::headset::bthf_call_state_t> {}; +template <> +struct formatter<bluetooth::headset::bthf_call_direction_t> + : enum_formatter<bluetooth::headset::bthf_call_direction_t> {}; } // namespace fmt diff --git a/system/include/hardware/bt_hh.h b/system/include/hardware/bt_hh.h index 3cedd885660..c9ee0a95f1f 100644 --- a/system/include/hardware/bt_hh.h +++ b/system/include/hardware/bt_hh.h @@ -228,8 +228,14 @@ __END_DECLS #include <bluetooth/log.h> namespace fmt { -template <> struct formatter<bthh_connection_state_t> : -enum_formatter<bthh_connection_state_t> {}; +template <> +struct formatter<bthh_connection_state_t> + : enum_formatter<bthh_connection_state_t> {}; +template <> +struct formatter<bthh_protocol_mode_t> : enum_formatter<bthh_protocol_mode_t> { +}; +template <> +struct formatter<bthh_report_type_t> : enum_formatter<bthh_report_type_t> {}; } // namespace fmt #endif // __has_include(<bluetooth/log.h>) diff --git a/system/include/hardware/bt_rc.h b/system/include/hardware/bt_rc.h index dc3179a292d..84979394417 100644 --- a/system/include/hardware/bt_rc.h +++ b/system/include/hardware/bt_rc.h @@ -727,4 +727,22 @@ typedef struct { __END_DECLS +#if __has_include(<bluetooth/log.h>) +#include <bluetooth/log.h> + +namespace fmt { +template <> +struct formatter<btrc_status_t> : enum_formatter<btrc_status_t> {}; +template <> +struct formatter<btrc_event_id_t> : enum_formatter<btrc_event_id_t> {}; +template <> +struct formatter<btrc_remote_features_t> + : enum_formatter<btrc_remote_features_t> {}; +template <> +struct formatter<btrc_notification_type_t> + : enum_formatter<btrc_notification_type_t> {}; +} // namespace fmt + +#endif // __has_include(<bluetooth/log.h>) + #endif /* ANDROID_INCLUDE_BT_RC_H */ diff --git a/system/include/hardware/bt_sdp.h b/system/include/hardware/bt_sdp.h index 77d00bd43dd..fd4a970e057 100644 --- a/system/include/hardware/bt_sdp.h +++ b/system/include/hardware/bt_sdp.h @@ -178,3 +178,13 @@ typedef struct { } btsdp_interface_t; __END_DECLS + +#if __has_include(<bluetooth/log.h>) +#include <bluetooth/log.h> + +namespace fmt { +template <> +struct formatter<bluetooth_sdp_types> : enum_formatter<bluetooth_sdp_types> {}; +} // namespace fmt + +#endif // __has_include(<bluetooth/log.h>) diff --git a/system/include/hardware/bt_sock.h b/system/include/hardware/bt_sock.h index 7d5060e0059..47e53ca0da9 100644 --- a/system/include/hardware/bt_sock.h +++ b/system/include/hardware/bt_sock.h @@ -110,3 +110,13 @@ typedef struct { } btsock_interface_t; __END_DECLS + +#if __has_include(<bluetooth/log.h>) +#include <bluetooth/log.h> + +namespace fmt { +template <> +struct formatter<btsock_type_t> : enum_formatter<btsock_type_t> {}; +} // namespace fmt + +#endif // __has_include(<bluetooth/log.h>) diff --git a/system/stack/include/btm_sec_api_types.h b/system/stack/include/btm_sec_api_types.h index 341cadc5a03..77985ec4e55 100644 --- a/system/stack/include/btm_sec_api_types.h +++ b/system/stack/include/btm_sec_api_types.h @@ -529,4 +529,6 @@ inline std::string bond_type_text(const tBTM_BOND_TYPE& bond_type) { namespace fmt { template <> struct formatter<tBTM_BLE_SEC_ACT> : enum_formatter<tBTM_BLE_SEC_ACT> {}; +template <> +struct formatter<tBTM_BOND_TYPE> : enum_formatter<tBTM_BOND_TYPE> {}; } // namespace fmt -- GitLab