diff --git a/system/gd/common/metric_id_manager.cc b/system/gd/common/metric_id_manager.cc index ef72097b08081464f605947d1a4e9c4ad012c9fa..0815986a4ca3ec578b5957a2737a5528a69a281c 100644 --- a/system/gd/common/metric_id_manager.cc +++ b/system/gd/common/metric_id_manager.cc @@ -69,9 +69,13 @@ bool MetricIdManager::Init( next_id_ = kMinId; for (const auto& p : paired_device_map) { if (p.second < kMinId || p.second > kMaxId) { - LOG_ALWAYS_FATAL("Invalid Bluetooth Metric Id in config. " - "Id %d of %s is out of range [%d, %d]", - p.second, p.first.ToString().c_str(), kMinId, kMaxId); + LOG_ALWAYS_FATAL( + "Invalid Bluetooth Metric Id in config. " + "Id %d of %s is out of range [%d, %d]", + p.second, + ADDRESS_TO_LOGGABLE_CSTR(p.first), + kMinId, + kMaxId); } auto evicted = paired_device_cache_.insert_or_assign(p.first, p.second); if (evicted) { diff --git a/system/gd/hci/acl_manager/acl_scheduler.cc b/system/gd/hci/acl_manager/acl_scheduler.cc index 7fd0611e03cc922f78908ef576ed5fd7bcddd353..a5f22f2bd23535105fdd44cc612ede5fcf59cf3e 100644 --- a/system/gd/hci/acl_manager/acl_scheduler.cc +++ b/system/gd/hci/acl_manager/acl_scheduler.cc @@ -102,7 +102,8 @@ struct AclScheduler::impl { [&]() { cancel_connection.Invoke(); }, [&](auto entry) { cancel_connection_completed.Invoke(); }); if (!ok) { - LOG_ERROR("Attempted to cancel connection to %s that does not exist", address.ToString().c_str()); + LOG_ERROR("Attempted to cancel connection to %s that does not exist", + ADDRESS_TO_LOGGABLE_CSTR(address)); } } @@ -149,7 +150,8 @@ struct AclScheduler::impl { [&]() { cancel_request.Invoke(); }, [](auto entry) { std::get<RemoteNameRequestQueueEntry>(entry).callback_when_cancelled.Invoke(); }); if (!ok) { - LOG_ERROR("Attempted to cancel remote name request to %s that does not exist", address.ToString().c_str()); + LOG_ERROR("Attempted to cancel remote name request " + "to %s that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); } }; @@ -279,4 +281,4 @@ void AclScheduler::Stop() { } // namespace acl_manager } // namespace hci -} // namespace bluetooth \ No newline at end of file +} // namespace bluetooth diff --git a/system/gd/hci/acl_manager/assembler.h b/system/gd/hci/acl_manager/assembler.h index 52ea359d8c27ab7cf3446e96e863a80585a4f5cc..36bedded78102175a0d053a9fd7199b37e48009c 100644 --- a/system/gd/hci/acl_manager/assembler.h +++ b/system/gd/hci/acl_manager/assembler.h @@ -125,7 +125,8 @@ struct assembler { } } if (incoming_queue_.size() > kMaxQueuedPacketsPerConnection) { - LOG_ERROR("Dropping packet from %s due to congestion", address_with_type_.ToString().c_str()); + LOG_ERROR("Dropping packet from %s due to congestion", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type_)); return; } diff --git a/system/gd/hci/acl_manager/classic_impl.h b/system/gd/hci/acl_manager/classic_impl.h index 06a8acb4619c2367d8e238e4307da5fbb4780f2e..fc1af9373709760691a5aeb08318336a9673a2da 100644 --- a/system/gd/hci/acl_manager/classic_impl.h +++ b/system/gd/hci/acl_manager/classic_impl.h @@ -307,7 +307,7 @@ struct classic_impl : public security::ISecurityManagerListener { void actually_create_connection(Address address, std::unique_ptr<CreateConnectionBuilder> packet) { if (is_classic_link_already_connected(address)) { - LOG_WARN("already connected: %s", address.ToString().c_str()); + LOG_WARN("already connected: %s", ADDRESS_TO_LOGGABLE_CSTR(address)); acl_scheduler_->ReportOutgoingAclConnectionFailure(); } acl_connection_interface_->EnqueueCommand( @@ -373,7 +373,8 @@ struct classic_impl : public security::ISecurityManagerListener { if (delayed_role_change_ == nullptr) { callbacks->OnRoleChange(hci::ErrorCode::SUCCESS, current_role); } else if (delayed_role_change_->GetBdAddr() == address) { - LOG_INFO("Sending delayed role change for %s", delayed_role_change_->GetBdAddr().ToString().c_str()); + LOG_INFO("Sending delayed role change for %s", + ADDRESS_TO_LOGGABLE_CSTR(delayed_role_change_->GetBdAddr())); callbacks->OnRoleChange(delayed_role_change_->GetStatus(), delayed_role_change_->GetNewRole()); delayed_role_change_.reset(); } @@ -431,9 +432,12 @@ struct classic_impl : public security::ISecurityManagerListener { ASSERT_LOG( status == ErrorCode::UNKNOWN_CONNECTION, "No prior connection request for %s expecting:%s", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), valid_incoming_addresses.c_str()); - LOG_WARN("No matching connection to %s (%s)", address.ToString().c_str(), ErrorCodeText(status).c_str()); + LOG_WARN( + "No matching connection to %s (%s)", + ADDRESS_TO_LOGGABLE_CSTR(address), + ErrorCodeText(status).c_str()); LOG_WARN("Firmware error after RemoteNameRequestCancel?"); // see b/184239841 if (bluetooth::common::init_flags::gd_remote_name_request_is_enabled()) { ASSERT_LOG( @@ -717,11 +721,13 @@ struct classic_impl : public security::ISecurityManagerListener { }); if (!sent) { if (delayed_role_change_ != nullptr) { - LOG_WARN("Second delayed role change (@%s dropped)", delayed_role_change_->GetBdAddr().ToString().c_str()); + LOG_WARN( + "Second delayed role change (@%s dropped)", + ADDRESS_TO_LOGGABLE_CSTR(delayed_role_change_->GetBdAddr())); } LOG_INFO( "Role change for %s with no matching connection (new role: %s)", - role_change_view.GetBdAddr().ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(role_change_view.GetBdAddr()), RoleText(role_change_view.GetNewRole()).c_str()); delayed_role_change_ = std::make_unique<RoleChangeView>(role_change_view); } diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h index bd02d71d011f9eda7ba30a7a6e8530e591abd308..60d1bc250d1f2a94502161716ce6f9a4ca1db398 100644 --- a/system/gd/hci/acl_manager/le_impl.h +++ b/system/gd/hci/acl_manager/le_impl.h @@ -42,8 +42,6 @@ using bluetooth::crypto_toolbox::Octet16; -#define PRIVATE_ADDRESS_WITH_TYPE(addr) addr.ToString().substr(12U).c_str() - namespace bluetooth { namespace hci { namespace acl_manager { @@ -297,7 +295,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { void on_common_le_connection_complete(AddressWithType address_with_type) { auto connecting_addr_with_type = connecting_le_.find(address_with_type); if (connecting_addr_with_type == connecting_le_.end()) { - LOG_WARN("No prior connection request for %s", address_with_type.ToString().c_str()); + LOG_WARN("No prior connection request for %s", ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); } connecting_le_.clear(); @@ -327,7 +325,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { on_common_le_connection_complete(remote_address); if (status == ErrorCode::UNKNOWN_CONNECTION) { if (remote_address.GetAddress() != Address::kEmpty) { - LOG_INFO("Controller send non-empty address field:%s", remote_address.GetAddress().ToString().c_str()); + LOG_INFO("Controller send non-empty address field:%s", + ADDRESS_TO_LOGGABLE_CSTR(remote_address.GetAddress())); } // direct connect canceled due to connection timeout, start background connect create_le_connection(remote_address, false, false); @@ -379,7 +378,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { if (in_filter_accept_list) { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", - PRIVATE_ADDRESS_WITH_TYPE(remote_address)); + ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); @@ -451,7 +450,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { on_common_le_connection_complete(remote_address); if (status == ErrorCode::UNKNOWN_CONNECTION) { if (remote_address.GetAddress() != Address::kEmpty) { - LOG_INFO("Controller send non-empty address field:%s", remote_address.GetAddress().ToString().c_str()); + LOG_INFO("Controller send non-empty address field:%s", + ADDRESS_TO_LOGGABLE_CSTR(remote_address.GetAddress())); } // direct connect canceled due to connection timeout, start background connect create_le_connection(remote_address, false, false); @@ -504,7 +504,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { if (in_filter_accept_list) { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", - PRIVATE_ADDRESS_WITH_TYPE(remote_address)); + ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); @@ -683,7 +683,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { if (connect_list.find(address_with_type) != connect_list.end()) { LOG_WARN( - "Device already exists in acceptlist and cannot be added:%s", PRIVATE_ADDRESS_WITH_TYPE(address_with_type)); + "Device already exists in acceptlist and cannot be added:%s", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } @@ -699,7 +700,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { void remove_device_from_connect_list(AddressWithType address_with_type) { if (connect_list.find(address_with_type) == connect_list.end()) { - LOG_WARN("Device not in acceptlist and cannot be removed:%s", PRIVATE_ADDRESS_WITH_TYPE(address_with_type)); + LOG_WARN("Device not in acceptlist and cannot be removed:%s", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } connect_list.erase(address_with_type); @@ -973,7 +975,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } void on_create_connection_timeout(AddressWithType address_with_type) { - LOG_INFO("on_create_connection_timeout, address: %s", address_with_type.ToString().c_str()); + LOG_INFO("on_create_connection_timeout, address: %s", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(address_with_type).Cancel(); create_connection_timeout_alarms_.erase(address_with_type); @@ -1193,8 +1196,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { std::map<AddressWithType, os::Alarm> create_connection_timeout_alarms_; }; -#undef PRIVATE_ADDRESS_WITH_TYPE - } // namespace acl_manager } // namespace hci } // namespace bluetooth diff --git a/system/gd/hci/facade/acl_manager_facade.cc b/system/gd/hci/facade/acl_manager_facade.cc index 3df393086a81ec3b91881185c88f41ff54b25d6f..bb713bd73ea646854d9506e18b65bb57f567072c 100644 --- a/system/gd/hci/facade/acl_manager_facade.cc +++ b/system/gd/hci/facade/acl_manager_facade.cc @@ -339,7 +339,8 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect } void on_incoming_acl(std::shared_ptr<ClassicAclConnection> connection, uint16_t handle) { - LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), connection->GetAddress().ToString().c_str()); + LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), + ADDRESS_TO_LOGGABLE_CSTR(connection->GetAddress())); auto packet = connection->GetAclQueueEnd()->TryDequeue(); auto connection_tracker = acl_connections_.find(handle); ASSERT_LOG(connection_tracker != acl_connections_.end(), "handle %d", handle); @@ -351,7 +352,8 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect } void OnConnectSuccess(std::unique_ptr<ClassicAclConnection> connection) override { - LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), connection->GetAddress().ToString().c_str()); + LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), + ADDRESS_TO_LOGGABLE_CSTR(connection->GetAddress())); std::unique_lock<std::mutex> lock(acl_connections_mutex_); std::shared_ptr<ClassicAclConnection> shared_connection = std::move(connection); uint16_t handle = to_handle(current_connection_request_); @@ -375,7 +377,8 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect } void OnConnectFail(Address address, ErrorCode reason, bool locally_initiated) override { - LOG_INFO("addr=%s, reason=%s", address.ToString().c_str(), ErrorCodeText(reason).c_str()); + LOG_INFO("addr=%s, reason=%s", + ADDRESS_TO_LOGGABLE_CSTR(address), ErrorCodeText(reason).c_str()); std::unique_ptr<BasePacketBuilder> builder = ConnectionCompleteBuilder::Create(reason, 0, address, LinkType::ACL, Enable::DISABLED); ConnectionEvent fail; diff --git a/system/gd/hci/facade/le_acl_manager_facade.cc b/system/gd/hci/facade/le_acl_manager_facade.cc index c67c21aba88664d7f958558febf1a163ae9cc52a..4c9f8fd7b565928b95a4c189eb20e2d918af88c6 100644 --- a/system/gd/hci/facade/le_acl_manager_facade.cc +++ b/system/gd/hci/facade/le_acl_manager_facade.cc @@ -264,7 +264,8 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC } void on_incoming_acl(std::shared_ptr<LeAclConnection> connection, uint16_t handle) { - LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), connection->GetRemoteAddress().ToString().c_str()); + LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), + ADDRESS_TO_LOGGABLE_CSTR(connection->GetRemoteAddress())); auto packet = connection->GetAclQueueEnd()->TryDequeue(); auto connection_tracker = acl_connections_.find(handle); ASSERT_LOG(connection_tracker != acl_connections_.end(), "handle %d", handle); @@ -275,7 +276,8 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC } void OnLeConnectSuccess(AddressWithType peer, std::unique_ptr<LeAclConnection> connection) override { - LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), peer.ToString().c_str()); + LOG_INFO("handle=%d, addr=%s", connection->GetHandle(), + ADDRESS_TO_LOGGABLE_CSTR(peer)); std::unique_lock<std::mutex> lock(acl_connections_mutex_); std::shared_ptr<LeAclConnection> shared_connection = std::move(connection); uint16_t handle = shared_connection->GetHandle(); @@ -293,7 +295,9 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC per_connection_events_.emplace(peer, direct_connection_events_); direct_connection_events_.reset(); } else { - ASSERT_LOG(per_connection_events_.count(peer) > 0, "No connection request for %s", peer.ToString().c_str()); + ASSERT_LOG( + per_connection_events_.count(peer) > 0, + "No connection request for %s", ADDRESS_TO_LOGGABLE_CSTR(peer)); } acl_connections_.erase(handle); acl_connections_.emplace( @@ -315,7 +319,8 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC } void OnLeConnectFail(AddressWithType address, ErrorCode reason, bool locally_initiated) override { - LOG_INFO("addr=%s, reason=%s", address.ToString().c_str(), ErrorCodeText(reason).c_str()); + LOG_INFO("addr=%s, reason=%s", + ADDRESS_TO_LOGGABLE_CSTR(address), ErrorCodeText(reason).c_str()); std::unique_ptr<BasePacketBuilder> builder = LeConnectionCompleteBuilder::Create( reason, 0, Role::CENTRAL, address.GetAddressType(), address.GetAddress(), 0, 0, 0, ClockAccuracy::PPM_20); LeConnectionEvent fail; diff --git a/system/gd/hci/facade/le_advertising_manager_facade.cc b/system/gd/hci/facade/le_advertising_manager_facade.cc index 7ecd5ed97fc42b14dc9e7985cd567eaf9ce9e431..c623d4b41de9e2a0521dc95898135a68d57dba5d 100644 --- a/system/gd/hci/facade/le_advertising_manager_facade.cc +++ b/system/gd/hci/facade/le_advertising_manager_facade.cc @@ -450,7 +450,8 @@ class LeAdvertisingManagerFacadeService : public LeAdvertisingManagerFacade::Ser }; void OnOwnAddressRead(uint8_t advertiser_id, uint8_t address_type, Address address) { - LOG_INFO("OnOwnAddressRead Address:%s, address_type:%d", address.ToString().c_str(), address_type); + LOG_INFO("OnOwnAddressRead Address:%s, address_type:%d", + ADDRESS_TO_LOGGABLE_CSTR(address), address_type); AddressMsg msg; msg.set_message_type(AdvertisingCallbackMsgType::OWN_ADDRESS_READ); msg.set_advertiser_id(advertiser_id); diff --git a/system/gd/hci/le_address_manager.cc b/system/gd/hci/le_address_manager.cc index 53c4f85d1929c028413c021bd626afe824719c29..19760a7557eab5b6260ef7e4aebb1ae00ceab432 100644 --- a/system/gd/hci/le_address_manager.cc +++ b/system/gd/hci/le_address_manager.cc @@ -604,7 +604,8 @@ void LeAddressManager::OnCommandComplete(bluetooth::hci::CommandCompleteView vie "Received LE_SET_RANDOM_ADDRESS complete with status %s", ErrorCodeText(complete_view.GetStatus()).c_str()); } else { - LOG_INFO("update random address : %s", cached_address_.GetAddress().ToString().c_str()); + LOG_INFO("update random address : %s", + ADDRESS_TO_LOGGABLE_CSTR(cached_address_.GetAddress())); le_address_ = cached_address_; } } diff --git a/system/gd/hci/le_advertising_manager.cc b/system/gd/hci/le_advertising_manager.cc index fcacc58e58b6e4d011a241436b035509d288e36b..a81ab61529a357cca74696498e4c3c6a08e415c2 100644 --- a/system/gd/hci/le_advertising_manager.cc +++ b/system/gd/hci/le_advertising_manager.cc @@ -1372,7 +1372,7 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb LOG_INFO( "update random address for advertising set %d : %s", advertiser_id, - address_with_type.GetAddress().ToString().c_str()); + ADDRESS_TO_LOGGABLE_CSTR(address_with_type.GetAddress())); advertising_sets_[advertiser_id].current_address = address_with_type; } } diff --git a/system/gd/hci/le_periodic_sync_manager.h b/system/gd/hci/le_periodic_sync_manager.h index c44a2a10756723ded18f7a52364fa9b9f0b4d6e6..c6c5170401261829cf54c703362cd1491862baf4 100644 --- a/system/gd/hci/le_periodic_sync_manager.h +++ b/system/gd/hci/le_periodic_sync_manager.h @@ -103,7 +103,9 @@ class PeriodicSyncManager { "Invalid address type %s", AddressTypeText(address_type).c_str()); periodic_syncs_.emplace_back(request); - LOG_DEBUG("address = %s, sid = %d", request.address_with_type.ToString().c_str(), request.advertiser_sid); + LOG_DEBUG("address = %s, sid = %d", + ADDRESS_TO_LOGGABLE_CSTR(request.address_with_type), + request.advertiser_sid); pending_sync_requests_.emplace_back( request.advertiser_sid, request.address_with_type, skip, sync_timeout, handler_); HandleNextRequest(); @@ -362,7 +364,7 @@ class PeriodicSyncManager { event_view.GetSyncHandle(), event_view.GetAdvertisingSid(), (uint8_t)event_view.GetAdvertiserAddressType(), - event_view.GetAdvertiserAddress().ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(event_view.GetAdvertiserAddress()), advertiser_phy, event_view.GetPeriodicAdvertisingInterval(), (uint8_t)event_view.GetAdvertiserClockAccuracy()); @@ -384,7 +386,7 @@ class PeriodicSyncManager { "%s: sync timeout SID=%04X, bd_addr=%s", __func__, request.advertiser_sid, - request.address_with_type.ToString().c_str()); + ADDRESS_TO_LOGGABLE_CSTR(request.address_with_type)); uint8_t adv_sid = request.advertiser_sid; AddressWithType address_with_type = request.address_with_type; auto sync = GetSyncFromAddressWithTypeAndSid(address_with_type, adv_sid); @@ -475,7 +477,7 @@ class PeriodicSyncManager { LOG_INFO( "executing sync request SID=%04X, bd_addr=%s", request.advertiser_sid, - request.address_with_type.ToString().c_str()); + ADDRESS_TO_LOGGABLE_CSTR(request.address_with_type)); if (request.busy) { LOG_INFO("Request is already busy"); return; @@ -505,7 +507,7 @@ class PeriodicSyncManager { LOG_INFO( "removing connection request SID=%04X, bd_addr=%s, busy=%d", it->advertiser_sid, - it->address_with_type.GetAddress().ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(it->address_with_type), it->busy); it = pending_sync_requests_.erase(it); } else { @@ -525,4 +527,4 @@ class PeriodicSyncManager { }; } // namespace hci -} // namespace bluetooth \ No newline at end of file +} // namespace bluetooth diff --git a/system/gd/l2cap/classic/facade.cc b/system/gd/l2cap/classic/facade.cc index 73eebaaab2c484488f39e43d7eb43e704743cf53..7fe4ae22f131bc8f251f767b2cb70dd0dcb81c6b 100644 --- a/system/gd/l2cap/classic/facade.cc +++ b/system/gd/l2cap/classic/facade.cc @@ -168,7 +168,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service ASSERT(hci::Address::FromString(request->address(), peer)); auto entry = security_link_map_.find(peer); if (entry == security_link_map_.end()) { - LOG_WARN("Unknown address '%s'", peer.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(peer)); } else { entry->second->Hold(); } @@ -183,7 +183,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service ASSERT(hci::Address::FromString(request->address(), peer)); auto entry = security_link_map_.find(peer); if (entry == security_link_map_.end()) { - LOG_WARN("Unknown address '%s'", peer.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(peer)); } else { entry->second->EnsureAuthenticated(); } @@ -199,7 +199,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service outgoing_pairing_remote_devices_.erase(peer); auto entry = security_link_map_.find(peer); if (entry == security_link_map_.end()) { - LOG_WARN("Unknown address '%s'", peer.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(peer)); } else { entry->second->Release(); } @@ -215,7 +215,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service outgoing_pairing_remote_devices_.erase(peer); auto entry = security_link_map_.find(peer); if (entry == security_link_map_.end()) { - LOG_WARN("Unknown address '%s'", peer.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(peer)); } else { entry->second->Disconnect(); } @@ -237,7 +237,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service void OnLinkDisconnected(hci::Address remote) override { auto entry = security_link_map_.find(remote); if (entry == security_link_map_.end()) { - LOG_WARN("Unknown address '%s'", remote.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(remote)); return; } entry->second.reset(); diff --git a/system/gd/l2cap/classic/internal/fixed_channel_impl.cc b/system/gd/l2cap/classic/internal/fixed_channel_impl.cc index d575f668265817aa8fcd04b4a6cc1641e3ab6f1a..2e60b87eef77f83359da07aa1d3d6bdbf5d272fc 100644 --- a/system/gd/l2cap/classic/internal/fixed_channel_impl.cc +++ b/system/gd/l2cap/classic/internal/fixed_channel_impl.cc @@ -47,8 +47,13 @@ void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler, } void FixedChannelImpl::OnClosed(hci::ErrorCode status) { - ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(), - cid_, static_cast<int>(close_reason_), static_cast<int>(status)); + ASSERT_LOG( + !closed_, + "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", + ADDRESS_TO_LOGGABLE_CSTR(device_), + cid_, + static_cast<int>(close_reason_), + static_cast<int>(status)); closed_ = true; close_reason_ = status; acquired_ = false; @@ -66,12 +71,12 @@ void FixedChannelImpl::OnClosed(hci::ErrorCode status) { void FixedChannelImpl::Acquire() { ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods"); if (closed_) { - LOG_WARN("%s is already closed", ToString().c_str()); + LOG_WARN("%s is already closed", ToLoggableStr(*this).c_str()); ASSERT(!acquired_); return; } if (acquired_) { - LOG_INFO("%s was already acquired", ToString().c_str()); + LOG_INFO("%s was already acquired", ToLoggableStr(*this).c_str()); return; } acquired_ = true; @@ -81,12 +86,12 @@ void FixedChannelImpl::Acquire() { void FixedChannelImpl::Release() { ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods"); if (closed_) { - LOG_WARN("%s is already closed", ToString().c_str()); + LOG_WARN("%s is already closed", ToLoggableStr(*this).c_str()); ASSERT(!acquired_); return; } if (!acquired_) { - LOG_INFO("%s was already released", ToString().c_str()); + LOG_INFO("%s was already released", ToLoggableStr(*this).c_str()); return; } acquired_ = false; diff --git a/system/gd/l2cap/classic/internal/fixed_channel_impl.h b/system/gd/l2cap/classic/internal/fixed_channel_impl.h index 37efa1db841257e25be6b12be7aa5a2c138945b1..4c9394a68e276cff86616385e1e2d3d0f7b12e35 100644 --- a/system/gd/l2cap/classic/internal/fixed_channel_impl.h +++ b/system/gd/l2cap/classic/internal/fixed_channel_impl.h @@ -17,6 +17,7 @@ #pragma once #include "common/bidi_queue.h" +#include "common/interfaces/ILoggable.h" #include "l2cap/cid.h" #include "l2cap/classic/fixed_channel.h" #include "l2cap/internal/channel_impl.h" @@ -31,8 +32,9 @@ namespace internal { class Link; -class FixedChannelImpl : public l2cap::internal::ChannelImpl { - public: +class FixedChannelImpl : public l2cap::internal::ChannelImpl, + public bluetooth::common::IRedactableLoggable { + public: FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler); FixedChannelImpl(const FixedChannelImpl&) = delete; @@ -56,9 +58,15 @@ class FixedChannelImpl : public l2cap::internal::ChannelImpl { virtual void OnClosed(hci::ErrorCode status); - virtual std::string ToString() { + std::string ToStringForLogging() const override { std::ostringstream ss; - ss << "Device " << device_ << " Cid 0x" << std::hex << cid_; + ss << "Device " << device_.ToStringForLogging() << " Cid 0x" << std::hex << cid_; + return ss.str(); + } + + std::string ToRedactedStringForLogging() const override { + std::ostringstream ss; + ss << "Device " << device_.ToRedactedStringForLogging() << " Cid 0x" << std::hex << cid_; return ss.str(); } diff --git a/system/gd/l2cap/classic/internal/link.h b/system/gd/l2cap/classic/internal/link.h index 2b61aaebf039453e5944108c3409b20b4d911d39..d30056c6a1421f8a346ac38f09bdce18104104d1 100644 --- a/system/gd/l2cap/classic/internal/link.h +++ b/system/gd/l2cap/classic/internal/link.h @@ -20,6 +20,7 @@ #include <memory> #include <unordered_map> +#include "common/interfaces/ILoggable.h" #include "hci/acl_manager/classic_acl_connection.h" #include "l2cap/classic/dynamic_channel_configuration_option.h" #include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h" @@ -44,7 +45,9 @@ namespace internal { class LinkManager; class DumpsysHelper; -class Link : public l2cap::internal::ILink, public hci::acl_manager::ConnectionManagementCallbacks { +class Link : public l2cap::internal::ILink, + public hci::acl_manager::ConnectionManagementCallbacks, + public bluetooth::common::IRedactableLoggable { public: Link(os::Handler* l2cap_handler, std::unique_ptr<hci::acl_manager::ClassicAclConnection> acl_connection, l2cap::internal::ParameterProvider* parameter_provider, @@ -151,6 +154,14 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::ConnectionM return GetDevice().ToString(); } + std::string ToStringForLogging() const override { + return GetDevice().ToStringForLogging(); + } + + std::string ToRedactedStringForLogging() const override { + return GetDevice().ToRedactedStringForLogging(); + } + void SendLeCredit(Cid local_cid, uint16_t credit) override {} // ConnectionManagementCallbacks diff --git a/system/gd/l2cap/classic/internal/link_manager.cc b/system/gd/l2cap/classic/internal/link_manager.cc index a34f4f4070d7709b4e377aaddc6d73657675a76f..b9c6af444fce985326e4976ef1b38dd05b7090e4 100644 --- a/system/gd/l2cap/classic/internal/link_manager.cc +++ b/system/gd/l2cap/classic/internal/link_manager.cc @@ -105,7 +105,7 @@ void LinkManager::ConnectDynamicChannelServices( void LinkManager::InitiateConnectionForSecurity(hci::Address remote) { auto* link = GetLink(remote); if (link != nullptr) { - LOG_ERROR("Link already exists for %s", remote.ToString().c_str()); + LOG_ERROR("Link already exists for %s", ADDRESS_TO_LOGGABLE_CSTR(remote)); } acl_manager_->CreateConnection(remote); } @@ -240,8 +240,10 @@ class LinkSecurityInterfaceImpl : public LinkSecurityInterface { void LinkManager::OnConnectSuccess(std::unique_ptr<hci::acl_manager::ClassicAclConnection> acl_connection) { // Same link should not be connected twice hci::Address device = acl_connection->GetAddress(); - ASSERT_LOG(GetLink(device) == nullptr, "%s is connected twice without disconnection", - acl_connection->GetAddress().ToString().c_str()); + ASSERT_LOG( + GetLink(device) == nullptr, + "%s is connected twice without disconnection", + ADDRESS_TO_LOGGABLE_CSTR(acl_connection->GetAddress())); links_.try_emplace(device, l2cap_handler_, std::move(acl_connection), parameter_provider_, dynamic_channel_service_manager_, fixed_channel_service_manager_, this); auto* link = GetLink(device); @@ -291,7 +293,7 @@ void LinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason, bool // There is no pending link, exit LOG_INFO( "Connection to %s failed without a pending link; reason: %s", - device.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(device), hci::ErrorCodeText(reason).c_str()); if (pending_dynamic_channels_callbacks_.find(device) != pending_dynamic_channels_callbacks_.end()) { for (Link::PendingDynamicChannelConnection& callbacks : pending_dynamic_channels_callbacks_[device]) { @@ -324,8 +326,11 @@ void LinkManager::HACK_OnScoConnectRequest(hci::Address device, hci::ClassOfDevi void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) { auto* link = GetLink(device); - ASSERT_LOG(link != nullptr, "Device %s is disconnected with reason 0x%x, but not in local database", - device.ToString().c_str(), static_cast<uint8_t>(status)); + ASSERT_LOG( + link != nullptr, + "Device %s is disconnected with reason 0x%x, but not in local database", + ADDRESS_TO_LOGGABLE_CSTR(device), + static_cast<uint8_t>(status)); if (link_security_interface_listener_handler_ != nullptr) { link_security_interface_listener_handler_->CallOn( link_security_interface_listener_, &LinkSecurityInterfaceListener::OnLinkDisconnected, device); diff --git a/system/gd/l2cap/internal/dynamic_channel_allocator.cc b/system/gd/l2cap/internal/dynamic_channel_allocator.cc index 881249238f0967f625766557dfec4206a42d2833..537629241511c0d95f7b5c4f79d01bfd468a5376 100644 --- a/system/gd/l2cap/internal/dynamic_channel_allocator.cc +++ b/system/gd/l2cap/internal/dynamic_channel_allocator.cc @@ -42,8 +42,11 @@ std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::AllocateChannel(Psm } auto elem = channels_.try_emplace(cid, std::make_shared<DynamicChannelImpl>(psm, cid, remote_cid, link_, l2cap_handler_)); - ASSERT_LOG(elem.second, "Failed to create channel for psm 0x%x device %s", psm, - link_->GetDevice().ToString().c_str()); + ASSERT_LOG( + elem.second, + "Failed to create channel for psm 0x%x device %s", + psm, + ADDRESS_TO_LOGGABLE_CSTR(link_->GetDevice())); ASSERT(elem.first->second != nullptr); used_remote_cid_.insert(remote_cid); used_cid_.insert(cid); @@ -58,8 +61,11 @@ std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::AllocateReservedCha } auto elem = channels_.try_emplace( reserved_cid, std::make_shared<DynamicChannelImpl>(psm, reserved_cid, remote_cid, link_, l2cap_handler_)); - ASSERT_LOG(elem.second, "Failed to create channel for psm 0x%x device %s", psm, - link_->GetDevice().ToString().c_str()); + ASSERT_LOG( + elem.second, + "Failed to create channel for psm 0x%x device %s", + psm, + ADDRESS_TO_LOGGABLE_CSTR(link_->GetDevice())); ASSERT(elem.first->second != nullptr); used_remote_cid_.insert(remote_cid); return elem.first->second; @@ -82,7 +88,8 @@ void DynamicChannelAllocator::FreeChannel(Cid cid) { used_cid_.erase(cid); auto channel = FindChannelByCid(cid); if (channel == nullptr) { - LOG_INFO("Channel is not in use: cid %d, device %s", cid, link_->GetDevice().ToString().c_str()); + LOG_INFO("Channel is not in use: cid %d, device %s", cid, + ADDRESS_TO_LOGGABLE_CSTR(link_->GetDevice())); return; } used_remote_cid_.erase(channel->GetRemoteCid()); diff --git a/system/gd/l2cap/internal/dynamic_channel_impl.cc b/system/gd/l2cap/internal/dynamic_channel_impl.cc index 6a3ecc5d80f5ae6223dbd1056d572055e9c061ca..6ce480b45c60a1f7ac9ed65f057fd80a6be205a2 100644 --- a/system/gd/l2cap/internal/dynamic_channel_impl.cc +++ b/system/gd/l2cap/internal/dynamic_channel_impl.cc @@ -62,8 +62,13 @@ void DynamicChannelImpl::Close() { } void DynamicChannelImpl::OnClosed(hci::ErrorCode status) { - ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(), - cid_, static_cast<int>(close_reason_), static_cast<int>(status)); + ASSERT_LOG( + !closed_, + "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", + ADDRESS_TO_LOGGABLE_CSTR(device_), + cid_, + static_cast<int>(close_reason_), + static_cast<int>(status)); closed_ = true; close_reason_ = status; link_ = nullptr; @@ -72,12 +77,6 @@ void DynamicChannelImpl::OnClosed(hci::ErrorCode status) { on_close_callback_ = {}; } -std::string DynamicChannelImpl::ToString() { - std::ostringstream ss; - ss << "Device " << device_ << "Psm 0x" << std::hex << psm_ << " Cid 0x" << std::hex << cid_; - return ss.str(); -} - } // namespace internal } // namespace l2cap } // namespace bluetooth diff --git a/system/gd/l2cap/internal/dynamic_channel_impl.h b/system/gd/l2cap/internal/dynamic_channel_impl.h index 4ae959f2e6f2cdea29de19f6962cb81a114d9451..7f34551a86c1d8faa3148e29a03e150f05c879d2 100644 --- a/system/gd/l2cap/internal/dynamic_channel_impl.h +++ b/system/gd/l2cap/internal/dynamic_channel_impl.h @@ -47,7 +47,6 @@ class DynamicChannelImpl : public l2cap::internal::ChannelImpl { virtual void Close(); virtual void OnClosed(hci::ErrorCode status); - virtual std::string ToString(); common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() { return channel_queue_.GetUpEnd(); diff --git a/system/gd/l2cap/internal/fixed_channel_allocator.h b/system/gd/l2cap/internal/fixed_channel_allocator.h index 14151ca43c817f72ff66fb8d573a01f83caa17f5..4300e522509baf03b3335fe86f435b66ef0b9487 100644 --- a/system/gd/l2cap/internal/fixed_channel_allocator.h +++ b/system/gd/l2cap/internal/fixed_channel_allocator.h @@ -50,17 +50,27 @@ class FixedChannelAllocator { // Allocates a channel. If cid is used, return nullptr. NOTE: The returned BaseFixedChannelImpl object is still // owned by the channel allocator, NOT the client. virtual std::shared_ptr<FixedChannelImplType> AllocateChannel(Cid cid) { - ASSERT_LOG(!IsChannelAllocated((cid)), "Cid 0x%x for link %s is already in use", cid, link_->ToString().c_str()); + ASSERT_LOG(!IsChannelAllocated(cid), + "Cid 0x%x for link %s is already in use", + cid, ToLoggableStr(*link_).c_str()); + ASSERT_LOG(cid >= kFirstFixedChannel && cid <= kLastFixedChannel, "Cid %d out of bound", cid); auto elem = channels_.try_emplace(cid, std::make_shared<FixedChannelImplType>(cid, link_, l2cap_handler_)); - ASSERT_LOG(elem.second, "Failed to create channel for cid 0x%x link %s", cid, link_->ToString().c_str()); + ASSERT_LOG( + elem.second, + "Failed to create channel for cid 0x%x link %s", + cid, + ToLoggableStr(*link_).c_str()); // TODO RENAME ADDRESS_TO_LOGGABLE_CSTR ASSERT(elem.first->second != nullptr); return elem.first->second; } // Frees a channel. If cid doesn't exist, it will crash virtual void FreeChannel(Cid cid) { - ASSERT_LOG(IsChannelAllocated(cid), "Channel is not in use: cid %d, link %s", cid, link_->ToString().c_str()); + ASSERT_LOG(IsChannelAllocated(cid), + "Channel is not in use: cid %d, link %s", + cid, ToLoggableStr(*link_).c_str()); + channels_.erase(cid); } @@ -69,7 +79,10 @@ class FixedChannelAllocator { } virtual std::shared_ptr<FixedChannelImplType> FindChannel(Cid cid) { - ASSERT_LOG(IsChannelAllocated(cid), "Channel is not in use: cid %d, link %s", cid, link_->ToString().c_str()); + ASSERT_LOG(IsChannelAllocated(cid), + "Channel is not in use: cid %d, link %s", + cid, ToLoggableStr(*link_).c_str()); + return channels_.find(cid)->second; } diff --git a/system/gd/l2cap/le/internal/fixed_channel_impl.cc b/system/gd/l2cap/le/internal/fixed_channel_impl.cc index da5dbfa3b21fc53a9653582819cee859e7cd4195..7dd524abae7614077202a2bab3a2c76621c438c3 100644 --- a/system/gd/l2cap/le/internal/fixed_channel_impl.cc +++ b/system/gd/l2cap/le/internal/fixed_channel_impl.cc @@ -56,8 +56,13 @@ void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler, } void FixedChannelImpl::OnClosed(hci::ErrorCode status) { - ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(), - cid_, static_cast<int>(close_reason_), static_cast<int>(status)); + ASSERT_LOG( + !closed_, + "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", + ADDRESS_TO_LOGGABLE_CSTR(device_), + cid_, + static_cast<int>(close_reason_), + static_cast<int>(status)); closed_ = true; close_reason_ = status; acquired_ = false; @@ -75,12 +80,12 @@ void FixedChannelImpl::OnClosed(hci::ErrorCode status) { void FixedChannelImpl::Acquire() { ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods"); if (closed_) { - LOG_WARN("%s is already closed", ToString().c_str()); + LOG_WARN("%s is already closed", ToLoggableStr(*this).c_str()); ASSERT(!acquired_); return; } if (acquired_) { - LOG_INFO("%s was already acquired", ToString().c_str()); + LOG_INFO("%s was already acquired", ToLoggableStr(*this).c_str()); return; } acquired_ = true; @@ -90,12 +95,12 @@ void FixedChannelImpl::Acquire() { void FixedChannelImpl::Release() { ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods"); if (closed_) { - LOG_WARN("%s is already closed", ToString().c_str()); + LOG_WARN("%s is already closed", ToLoggableStr(*this).c_str()); ASSERT(!acquired_); return; } if (!acquired_) { - LOG_INFO("%s was already released", ToString().c_str()); + LOG_INFO("%s was already released", ToLoggableStr(*this).c_str()); return; } acquired_ = false; diff --git a/system/gd/l2cap/le/internal/fixed_channel_impl.h b/system/gd/l2cap/le/internal/fixed_channel_impl.h index 59a68add8930352cbafd434088fc8ec8b951107c..12ce4a670b28c7b1ba61498d075960fd33d3a7ca 100644 --- a/system/gd/l2cap/le/internal/fixed_channel_impl.h +++ b/system/gd/l2cap/le/internal/fixed_channel_impl.h @@ -17,6 +17,7 @@ #pragma once #include "common/bidi_queue.h" +#include "common/interfaces/ILoggable.h" #include "hci/acl_manager/le_acl_connection.h" #include "l2cap/cid.h" #include "l2cap/internal/channel_impl.h" @@ -24,7 +25,6 @@ #include "l2cap/le/link_options.h" #include "os/handler.h" #include "os/log.h" - namespace bluetooth { namespace l2cap { namespace le { @@ -32,7 +32,8 @@ namespace internal { class Link; -class FixedChannelImpl : public l2cap::internal::ChannelImpl { +class FixedChannelImpl : public l2cap::internal::ChannelImpl, + public bluetooth::common::IRedactableLoggable { public: FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler); @@ -70,6 +71,18 @@ class FixedChannelImpl : public l2cap::internal::ChannelImpl { return ss.str(); } + std::string ToStringForLogging() const override { + std::ostringstream ss; + ss << "Device " << device_.ToStringForLogging() << " Cid 0x" << std::hex << cid_; + return ss.str(); + } + + std::string ToRedactedStringForLogging() const override { + std::ostringstream ss; + ss << "Device " << device_.ToRedactedStringForLogging() << " Cid 0x" << std::hex << cid_; + return ss.str(); + } + common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() { return channel_queue_.GetUpEnd(); } diff --git a/system/gd/l2cap/le/internal/link.h b/system/gd/l2cap/le/internal/link.h index f0d90aa978993e959284fedcbd90bc9620e37c30..a38a5ab9159bc595136ab6ffc0166d2e34b4dbf6 100644 --- a/system/gd/l2cap/le/internal/link.h +++ b/system/gd/l2cap/le/internal/link.h @@ -20,6 +20,7 @@ #include <chrono> #include <memory> +#include "common/interfaces/ILoggable.h" #include "hci/acl_manager/le_acl_connection.h" #include "l2cap/internal/data_pipeline_manager.h" #include "l2cap/internal/dynamic_channel_allocator.h" @@ -42,7 +43,9 @@ namespace internal { class LinkManager; -class Link : public l2cap::internal::ILink, public hci::acl_manager::LeConnectionManagementCallbacks { +class Link : public l2cap::internal::ILink, + public hci::acl_manager::LeConnectionManagementCallbacks, + public bluetooth::common::IRedactableLoggable { public: Link(os::Handler* l2cap_handler, std::unique_ptr<hci::acl_manager::LeAclConnection> acl_connection, l2cap::internal::ParameterProvider* parameter_provider, @@ -150,6 +153,14 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::LeConnectio return GetDevice().ToString(); } + std::string ToStringForLogging() const override { + return GetDevice().ToStringForLogging(); + } + + std::string ToRedactedStringForLogging() const override { + return GetDevice().ToRedactedStringForLogging(); + } + virtual uint16_t GetMps() const; virtual uint16_t GetInitialCredit() const; diff --git a/system/gd/l2cap/le/internal/link_manager.cc b/system/gd/l2cap/le/internal/link_manager.cc index 09b6c3410771c70a8ffceb403f0e588917628e01..aaaae79aa7a27342fa731d0f90034472594146fb 100644 --- a/system/gd/l2cap/le/internal/link_manager.cc +++ b/system/gd/l2cap/le/internal/link_manager.cc @@ -106,8 +106,10 @@ void LinkManager::OnLeConnectSuccess(hci::AddressWithType connecting_address_wit // Same link should not be connected twice hci::AddressWithType connected_address_with_type = acl_connection->GetRemoteAddress(); uint16_t handle = acl_connection->GetHandle(); - ASSERT_LOG(GetLink(connected_address_with_type) == nullptr, "%s is connected twice without disconnection", - acl_connection->GetRemoteAddress().ToString().c_str()); + ASSERT_LOG( + GetLink(connected_address_with_type) == nullptr, + "%s is connected twice without disconnection", + ADDRESS_TO_LOGGABLE_CSTR(acl_connection->GetRemoteAddress())); links_.try_emplace(connected_address_with_type, l2cap_handler_, std::move(acl_connection), parameter_provider_, dynamic_channel_service_manager_, fixed_channel_service_manager_, this); auto* link = GetLink(connected_address_with_type); @@ -133,7 +135,8 @@ void LinkManager::OnLeConnectFail( auto pending_link = pending_links_.find(address_with_type); if (pending_link == pending_links_.end()) { // There is no pending link, exit - LOG_INFO("Connection to %s failed without a pending link", address_with_type.ToString().c_str()); + LOG_INFO("Connection to %s failed without a pending link", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) { @@ -148,8 +151,10 @@ void LinkManager::OnLeConnectFail( void LinkManager::OnDisconnect(bluetooth::hci::AddressWithType address_with_type) { auto* link = GetLink(address_with_type); - ASSERT_LOG(link != nullptr, "Device %s is disconnected but not in local database", - address_with_type.ToString().c_str()); + ASSERT_LOG( + link != nullptr, + "Device %s is disconnected but not in local database", + ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); if (links_with_pending_packets_.count(address_with_type) != 0) { disconnected_links_.emplace(address_with_type); } else { diff --git a/system/gd/neighbor/inquiry.cc b/system/gd/neighbor/inquiry.cc index f814fd028663200893b5a59e33f76e8f59411f86..7706b37dc1bf194d6128270833c48405b0c2a619 100644 --- a/system/gd/neighbor/inquiry.cc +++ b/system/gd/neighbor/inquiry.cc @@ -224,7 +224,7 @@ void neighbor::InquiryModule::impl::OnEvent(hci::EventView view) { ASSERT(packet.IsValid()); LOG_INFO( "Extended inquiry result addr:%s repetition_mode:%s cod:%s clock_offset:%d rssi:%hhd", - packet.GetAddress().ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(packet.GetAddress()), hci::PageScanRepetitionModeText(packet.GetPageScanRepetitionMode()).c_str(), packet.GetClassOfDevice().ToString().c_str(), packet.GetClockOffset(), diff --git a/system/gd/os/android/metrics.cc b/system/gd/os/android/metrics.cc index 972a6eec21bade9aa60ababa32f7e32e27703b2b..9d081522f52636d281cb413b10a62b93ce5e6b96 100644 --- a/system/gd/os/android/metrics.cc +++ b/system/gd/os/android/metrics.cc @@ -77,7 +77,7 @@ void LogMetricLinkLayerConnectionEvent( common::ToHexString(hci_cmd).c_str(), common::ToHexString(hci_event).c_str(), common::ToHexString(hci_ble_event).c_str(), - address ? address->ToString().c_str() : "(NULL)", + address ? ADDRESS_TO_LOGGABLE_CSTR(*address) : "(NULL)", connection_handle, common::ToHexString(link_type).c_str(), ret); @@ -118,7 +118,7 @@ void LogMetricA2dpAudioUnderrunEvent( if (ret < 0) { LOG_WARN( "Failed for %s, encoding_interval_nanos %s, num_missing_pcm_bytes %d, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), std::to_string(encoding_interval_nanos).c_str(), num_missing_pcm_bytes, ret); @@ -149,7 +149,7 @@ void LogMetricA2dpAudioOverrunEvent( LOG_WARN( "Failed to log for %s, encoding_interval_nanos %s, num_dropped_buffers %d, " "num_dropped_encoded_frames %d, num_dropped_encoded_bytes %d, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), std::to_string(encoding_interval_nanos).c_str(), num_dropped_buffers, num_dropped_encoded_frames, @@ -168,7 +168,7 @@ void LogMetricA2dpPlaybackEvent(const Address& address, int playback_state, int if (ret < 0) { LOG_WARN( "Failed to log for %s, playback_state %d, audio_coding_mode %d,error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), playback_state, audio_coding_mode, ret); @@ -184,7 +184,7 @@ void LogMetricReadRssiResult(const Address& address, uint16_t handle, uint32_t c if (ret < 0) { LOG_WARN( "Failed for %s, handle %d, status %s, rssi %d dBm, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), handle, common::ToHexString(cmd_status).c_str(), rssi, @@ -208,7 +208,7 @@ void LogMetricReadFailedContactCounterResult( if (ret < 0) { LOG_WARN( "Failed for %s, handle %d, status %s, failed_contact_counter %d packets, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), handle, common::ToHexString(cmd_status).c_str(), failed_contact_counter, @@ -227,7 +227,7 @@ void LogMetricReadTxPowerLevelResult( if (ret < 0) { LOG_WARN( "Failed for %s, handle %d, status %s, transmit_power_level %d packets, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), handle, common::ToHexString(cmd_status).c_str(), transmit_power_level, @@ -246,7 +246,7 @@ void LogMetricSmpPairingEvent( if (ret < 0) { LOG_WARN( "Failed for %s, smp_cmd %s, direction %d, smp_fail_reason %s, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), common::ToHexString(smp_cmd).c_str(), direction, common::ToHexString(smp_fail_reason).c_str(), @@ -280,7 +280,7 @@ void LogMetricClassicPairingEvent( LOG_WARN( "Failed for %s, handle %d, hci_cmd %s, hci_event %s, cmd_status %s, " "reason %s, event_value %s, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), handle, common::ToHexString(hci_cmd).c_str(), common::ToHexString(hci_event).c_str(), @@ -311,7 +311,7 @@ void LogMetricSdpAttribute( if (ret < 0) { LOG_WARN( "Failed for %s, protocol_uuid %s, attribute_id %s, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), common::ToHexString(protocol_uuid).c_str(), common::ToHexString(attribute_id).c_str(), ret); @@ -348,7 +348,7 @@ void LogMetricSocketConnectionState( LOG_WARN( "Failed for %s, port %d, type %d, state %d, tx_bytes %s, rx_bytes %s, uid %d, server_port %d, " "socket_role %d, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), port, type, connection_state, @@ -393,7 +393,7 @@ void LogMetricManufacturerInfo( "Failed for %s, source_type %d, source_name %s, manufacturer %s, model %s, " "hardware_version %s, " "software_version %s, MAC address type %d MAC address prefix %d %d %d, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), source_type, source_name.c_str(), manufacturer.c_str(), @@ -417,7 +417,7 @@ void LogMetricBluetoothHalCrashReason( if (ret < 0) { LOG_WARN( "Failed for %s, error_code %s, vendor_error_code %s, error %d", - address.ToString().c_str(), + ADDRESS_TO_LOGGABLE_CSTR(address), common::ToHexString(error_code).c_str(), common::ToHexString(vendor_error_code).c_str(), ret); diff --git a/system/gd/rust/topshim/hfp/hfp_shim.cc b/system/gd/rust/topshim/hfp/hfp_shim.cc index 48a5755911a62a8d771c3b49d2b15f806ed0b763..597991cc8c0b52470a975887790be1fc5d52aa41 100644 --- a/system/gd/rust/topshim/hfp/hfp_shim.cc +++ b/system/gd/rust/topshim/hfp/hfp_shim.cc @@ -60,12 +60,12 @@ class DBusHeadsetCallbacks : public headset::Callbacks { // headset::Callbacks void ConnectionStateCallback(headset::bthf_connection_state_t state, RawAddress* bd_addr) override { - LOG_INFO("ConnectionStateCallback from %s", bd_addr->ToString().c_str()); + LOG_INFO("ConnectionStateCallback from %s", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); topshim::rust::internal::connection_state_cb(state, bd_addr); } void AudioStateCallback(headset::bthf_audio_state_t state, RawAddress* bd_addr) override { - LOG_INFO("AudioStateCallback %u from %s", state, bd_addr->ToString().c_str()); + LOG_INFO("AudioStateCallback %u from %s", state, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); topshim::rust::internal::audio_state_cb(state, bd_addr); switch (state) { @@ -90,7 +90,7 @@ class DBusHeadsetCallbacks : public headset::Callbacks { void VolumeControlCallback(headset::bthf_volume_type_t type, int volume, RawAddress* bd_addr) override { if (type != headset::bthf_volume_type_t::BTHF_VOLUME_TYPE_SPK || volume < 0) return; if (volume > 15) volume = 15; - LOG_INFO("VolumeControlCallback %d from %s", volume, bd_addr->ToString().c_str()); + LOG_INFO("VolumeControlCallback %d from %s", volume, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); topshim::rust::internal::volume_update_cb(volume, bd_addr); } @@ -102,7 +102,7 @@ class DBusHeadsetCallbacks : public headset::Callbacks { [[maybe_unused]] headset::bthf_nrec_t nrec, [[maybe_unused]] RawAddress* bd_addr) override {} void WbsCallback(headset::bthf_wbs_config_t wbs, RawAddress* addr) override { - LOG_INFO("WbsCallback %d from %s", wbs, addr->ToString().c_str()); + LOG_INFO("WbsCallback %d from %s", wbs, ADDRESS_TO_LOGGABLE_CSTR(*addr)); rusty::hfp_caps_update_callback(wbs == headset::BTHF_WBS_YES, *addr); } @@ -113,7 +113,8 @@ class DBusHeadsetCallbacks : public headset::Callbacks { void AtCindCallback(RawAddress* bd_addr) override { // This is required to setup the SLC, the format of the response should be // +CIND: <call>,<callsetup>,<service>,<signal>,<roam>,<battery>,<callheld> - LOG_WARN("Respond +CIND: 0,0,1,5,0,5,0 to AT+CIND? from %s", bd_addr->ToString().c_str()); + LOG_WARN("Respond +CIND: 0,0,1,5,0,5,0 to AT+CIND? from %s", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); // headset::Interface::CindResponse's parameters are similar but different // from the actual CIND response. It will construct the final response for @@ -125,7 +126,8 @@ class DBusHeadsetCallbacks : public headset::Callbacks { } void AtCopsCallback(RawAddress* bd_addr) override { - LOG_WARN("Respond +COPS: 0 to AT+COPS? from %s", bd_addr->ToString().c_str()); + LOG_WARN("Respond +COPS: 0 to AT+COPS? from %s", + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); headset_->CopsResponse("", bd_addr); } @@ -156,7 +158,9 @@ class DBusHeadsetCallbacks : public headset::Callbacks { void AtBindCallback(char* at_string, RawAddress* bd_addr) override { LOG_WARN( - "AT+BIND %s from addr %s: Bluetooth HF Indicators is not supported.", at_string, bd_addr->ToString().c_str()); + "AT+BIND %s from addr %s: Bluetooth HF Indicators is not supported.", + at_string, + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); } void AtBievCallback(headset::bthf_hf_ind_type_t ind_id, int ind_value, RawAddress* bd_addr) override { @@ -174,13 +178,14 @@ class DBusHeadsetCallbacks : public headset::Callbacks { "AT+BIEV indicator %i with value %i from addr %s", ind_id, ind_value, - bd_addr->ToString().c_str()); + ADDRESS_TO_LOGGABLE_CSTR(*bd_addr) ); return; } } void AtBiaCallback(bool service, bool roam, bool signal, bool battery, RawAddress* bd_addr) override { - LOG_WARN("AT+BIA=,,%d,%d,%d,%d,from addr %s", service, signal, roam, battery, bd_addr->ToString().c_str()); + LOG_WARN("AT+BIA=,,%d,%d,%d,%d,from addr %s", service, signal, roam, + battery, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr)); } private: diff --git a/system/gd/rust/topshim/src/btif.rs b/system/gd/rust/topshim/src/btif.rs index 353fb264f83f446e349dd709f8b195906e06ccdb..b5f9eab13a56370e5ecd2f50b4d374802622bb06 100644 --- a/system/gd/rust/topshim/src/btif.rs +++ b/system/gd/rust/topshim/src/btif.rs @@ -766,6 +766,7 @@ impl Hash for RawAddress { } } +// TODO (b/264603574): Handling address hiding in rust logging statements impl ToString for RawAddress { fn to_string(&self) -> String { String::from(format!( diff --git a/system/gd/security/channel/security_manager_channel.cc b/system/gd/security/channel/security_manager_channel.cc index 8c90a360bbb736046eb1a7a0cf2247949c8c59db..94fa9370aeaff211fa74564ca9ade5b9f54a5778 100644 --- a/system/gd/security/channel/security_manager_channel.cc +++ b/system/gd/security/channel/security_manager_channel.cc @@ -43,7 +43,7 @@ void SecurityManagerChannel::Connect(hci::Address address) { ASSERT_LOG(l2cap_security_interface_ != nullptr, "L2cap Security Interface is null!"); auto entry = link_map_.find(address); if (entry != link_map_.end()) { - LOG_WARN("Already connected to '%s'", address.ToString().c_str()); + LOG_WARN("Already connected to '%s'", ADDRESS_TO_LOGGABLE_CSTR(address)); entry->second->Hold(); entry->second->EnsureAuthenticated(); return; @@ -55,7 +55,7 @@ void SecurityManagerChannel::Connect(hci::Address address) { void SecurityManagerChannel::Release(hci::Address address) { auto entry = link_map_.find(address); if (entry == link_map_.end()) { - LOG_WARN("Unknown address '%s'", address.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(address)); return; } entry->second->Release(); @@ -65,7 +65,7 @@ void SecurityManagerChannel::Disconnect(hci::Address address) { outgoing_pairing_remote_devices_.erase(address); auto entry = link_map_.find(address); if (entry == link_map_.end()) { - LOG_WARN("Unknown address '%s'", address.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(address)); return; } entry->second->Disconnect(); @@ -105,7 +105,7 @@ void SecurityManagerChannel::OnLinkConnected(std::unique_ptr<l2cap::classic::Lin void SecurityManagerChannel::OnLinkDisconnected(hci::Address address) { auto entry = link_map_.find(address); if (entry == link_map_.end()) { - LOG_WARN("Unknown address '%s'", address.ToString().c_str()); + LOG_WARN("Unknown address '%s'", ADDRESS_TO_LOGGABLE_CSTR(address)); return; } entry->second.reset(); diff --git a/system/gd/security/facade.cc b/system/gd/security/facade.cc index 1b1831419283751bf03e47b7beb46c6b217fc7b5..19b303462c667e376423e92d00339b90a3facb39 100644 --- a/system/gd/security/facade.cc +++ b/system/gd/security/facade.cc @@ -474,14 +474,14 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, } void DisconnectEventOccurred(bluetooth::hci::AddressWithType peer) { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); DisconnectMsg msg; *msg.mutable_address() = ToFacadeAddressWithType(peer); disconnect_events_.OnIncomingEvent(msg); } void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& peer, std::string name) { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); UiMsg display_yes_no; *display_yes_no.mutable_peer() = ToFacadeAddressWithType(peer); display_yes_no.set_message_type(UiMsgType::DISPLAY_PAIRING_PROMPT); @@ -493,7 +493,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType(); std::string name = data.GetName(); uint32_t numeric_value = data.GetNumericValue(); - LOG_INFO("%s value = 0x%x", peer.ToString().c_str(), numeric_value); + LOG_INFO("%s value = 0x%x", ADDRESS_TO_LOGGABLE_CSTR(peer), numeric_value); UiMsg display_with_value; *display_with_value.mutable_peer() = ToFacadeAddressWithType(peer); display_with_value.set_message_type(UiMsgType::DISPLAY_YES_NO_WITH_VALUE); @@ -505,7 +505,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, void DisplayYesNoDialog(ConfirmationData data) override { const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType(); std::string name = data.GetName(); - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); UiMsg display_yes_no; *display_yes_no.mutable_peer() = ToFacadeAddressWithType(peer); display_yes_no.set_message_type(UiMsgType::DISPLAY_YES_NO); @@ -517,7 +517,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType(); std::string name = data.GetName(); uint32_t passkey = data.GetNumericValue(); - LOG_INFO("%s value = 0x%x", peer.ToString().c_str(), passkey); + LOG_INFO("%s value = 0x%x", ADDRESS_TO_LOGGABLE_CSTR(peer), passkey); UiMsg display_passkey; *display_passkey.mutable_peer() = ToFacadeAddressWithType(peer); display_passkey.set_message_type(UiMsgType::DISPLAY_PASSKEY); @@ -529,7 +529,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, void DisplayEnterPasskeyDialog(ConfirmationData data) override { const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType(); std::string name = data.GetName(); - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); UiMsg display_passkey_input; *display_passkey_input.mutable_peer() = ToFacadeAddressWithType(peer); display_passkey_input.set_message_type(UiMsgType::DISPLAY_PASSKEY_ENTRY); @@ -540,7 +540,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, void DisplayEnterPinDialog(ConfirmationData data) override { const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType(); std::string name = data.GetName(); - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); UiMsg display_pin_input; *display_pin_input.mutable_peer() = ToFacadeAddressWithType(peer); display_pin_input.set_message_type(UiMsgType::DISPLAY_PIN_ENTRY); @@ -549,7 +549,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, } void Cancel(const bluetooth::hci::AddressWithType& peer) override { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); UiMsg display_cancel; *display_cancel.mutable_peer() = ToFacadeAddressWithType(peer); display_cancel.set_message_type(UiMsgType::DISPLAY_CANCEL); @@ -558,7 +558,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, } void OnDeviceBonded(hci::AddressWithType peer) override { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); BondMsg bonded; *bonded.mutable_peer() = ToFacadeAddressWithType(peer); bonded.set_message_type(BondMsgType::DEVICE_BONDED); @@ -568,7 +568,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, void OnEncryptionStateChanged(hci::EncryptionChangeView encryption_change_view) override {} void OnDeviceUnbonded(hci::AddressWithType peer) override { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); BondMsg unbonded; *unbonded.mutable_peer() = ToFacadeAddressWithType(peer); unbonded.set_message_type(BondMsgType::DEVICE_UNBONDED); @@ -576,7 +576,7 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, } void OnDeviceBondFailed(hci::AddressWithType peer, PairingFailure status) override { - LOG_INFO("%s", peer.ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(peer)); BondMsg bond_failed; *bond_failed.mutable_peer() = ToFacadeAddressWithType(peer); bond_failed.set_message_type(BondMsgType::DEVICE_BOND_FAILED); diff --git a/system/gd/security/internal/security_manager_impl.cc b/system/gd/security/internal/security_manager_impl.cc index 7a540b34f1d57e6f7b18e39bd13c5d12a994c3d9..659db7c22e5f8ee4408f2f98fa802bf331d1b417 100644 --- a/system/gd/security/internal/security_manager_impl.cc +++ b/system/gd/security/internal/security_manager_impl.cc @@ -258,8 +258,10 @@ void SecurityManagerImpl::HandleEvent(T packet) { if (event_code != hci::EventCode::LINK_KEY_REQUEST && event_code != hci::EventCode::PIN_CODE_REQUEST && event_code != hci::EventCode::IO_CAPABILITY_RESPONSE) { - LOG_ERROR("No classic pairing handler for device '%s' ready for command %s ", bd_addr.ToString().c_str(), - hci::EventCodeText(event_code).c_str()); + LOG_ERROR( + "No classic pairing handler for device '%s' ready for command %s ", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), + hci::EventCodeText(event_code).c_str()); return; } @@ -342,7 +344,7 @@ void SecurityManagerImpl::OnHciEventReceived(hci::EventView packet) { void SecurityManagerImpl::OnConnectionClosed(hci::Address address) { auto entry = pairing_handler_map_.find(address); if (entry != pairing_handler_map_.end()) { - LOG_INFO("Cancelling pairing handler for '%s'", address.ToString().c_str()); + LOG_INFO("Cancelling pairing handler for '%s'", ADDRESS_TO_LOGGABLE_CSTR(address)); entry->second->Cancel(); } auto record = security_database_.FindOrCreate(hci::AddressWithType(address, hci::AddressType::PUBLIC_DEVICE_ADDRESS)); @@ -415,10 +417,10 @@ void SecurityManagerImpl::OnPasskeyEntry(const bluetooth::hci::AddressWithType& void SecurityManagerImpl::OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) { auto entry = pairing_handler_map_.find(address.GetAddress()); if (entry != pairing_handler_map_.end()) { - LOG_INFO("PIN for %s", address.ToString().c_str()); + LOG_INFO("PIN for %s", ADDRESS_TO_LOGGABLE_CSTR(address)); entry->second->OnPinEntry(address, pin); } else { - LOG_WARN("No handler found for PIN for %s", address.ToString().c_str()); + LOG_WARN("No handler found for PIN for %s", ADDRESS_TO_LOGGABLE_CSTR(address)); // TODO(jpawlowski): Implement LE version } } @@ -705,7 +707,7 @@ void SecurityManagerImpl::OnPairingFinished(security::PairingResultOrFailure pai } auto result = std::get<PairingResult>(pairing_result); - LOG_INFO("Pairing with %s was successful", result.connection_address.ToString().c_str()); + LOG_INFO("Pairing with %s was successful", ADDRESS_TO_LOGGABLE_CSTR(result.connection_address)); // TODO: ensure that the security level is not weaker than what we already have. auto record = this->security_database_.FindOrCreate(result.connection_address); @@ -828,7 +830,7 @@ void SecurityManagerImpl::InternalEnforceSecurityPolicy( void SecurityManagerImpl::UpdateLinkSecurityCondition(hci::AddressWithType remote) { auto entry = enforce_security_policy_callback_map_.find(remote); if (entry == enforce_security_policy_callback_map_.end()) { - LOG_ERROR("No L2CAP security policy callback pending for %s", remote.ToString().c_str()); + LOG_ERROR("No L2CAP security policy callback pending for %s", ADDRESS_TO_LOGGABLE_CSTR(remote)); return; } std::move(entry->second.callback_).Invoke(IsSecurityRequirementSatisfied(remote, entry->second.policy_)); diff --git a/system/gd/security/pairing/classic_pairing_handler.cc b/system/gd/security/pairing/classic_pairing_handler.cc index f49f7838fb743588281b9b31426393d7f7a95a57..82ac61a9e202df07b7f58cb2cdb6252e12e2fdf3 100644 --- a/system/gd/security/pairing/classic_pairing_handler.cc +++ b/system/gd/security/pairing/classic_pairing_handler.cc @@ -97,7 +97,7 @@ void ClassicPairingHandler::OnPinEntry(const bluetooth::hci::AddressWithType& ad for (size_t i = 0; i < 16 && i < pin.size(); i++) { padded_pin[i] = pin[i]; } - LOG_INFO("%s", address.GetAddress().ToString().c_str()); + LOG_INFO("%s", ADDRESS_TO_LOGGABLE_CSTR(address.GetAddress())); GetChannel()->SendCommand(hci::PinCodeRequestReplyBuilder::Create(address.GetAddress(), pin.size(), padded_pin)); } diff --git a/system/gd/security/record/security_record_storage.cc b/system/gd/security/record/security_record_storage.cc index ae7128f316a3283dcd28f336a15d8c4de20013ac..021759dcca36eef135b4fe645f3a24743185ef98 100644 --- a/system/gd/security/record/security_record_storage.cc +++ b/system/gd/security/record/security_record_storage.cc @@ -117,7 +117,7 @@ void SecurityRecordStorage::SaveSecurityRecords(std::set<std::shared_ptr<record: mutation.Add(device.SetDeviceType(hci::DeviceType::LE)); LOG_WARN( "Cannot determine device type from security record for '%s'; defaulting to LE", - record->GetPseudoAddress()->ToString().c_str()); + ADDRESS_TO_LOGGABLE_CSTR(*record->GetPseudoAddress())); } mutation.Commit(); SetClassicData(mutation, record, device); diff --git a/system/gd/security/test/pairing_handler_le_pair_test.cc b/system/gd/security/test/pairing_handler_le_pair_test.cc index 434e638095a55ae3e972f9b6d2b9fbe6abb579b4..2847a48b06320d13476de189824f81c76cb286ca 100644 --- a/system/gd/security/test/pairing_handler_le_pair_test.cc +++ b/system/gd/security/test/pairing_handler_le_pair_test.cc @@ -103,7 +103,9 @@ std::optional<PairingResultOrFailure> pairing_result_peripheral; void OnPairingFinishedCentral(PairingResultOrFailure r) { pairing_result_central = r; if (std::holds_alternative<PairingResult>(r)) { - LOG_INFO("pairing finished successfully with %s", std::get<PairingResult>(r).connection_address.ToString().c_str()); + LOG_INFO( + "pairing finished successfully with %s", + ADDRESS_TO_LOGGABLE_CSTR(std::get<PairingResult>(r).connection_address)); } else { LOG_INFO("pairing with ... failed: %s", std::get<PairingFailure>(r).message.c_str()); } @@ -112,7 +114,9 @@ void OnPairingFinishedCentral(PairingResultOrFailure r) { void OnPairingFinishedPeripheral(PairingResultOrFailure r) { pairing_result_peripheral = r; if (std::holds_alternative<PairingResult>(r)) { - LOG_INFO("pairing finished successfully with %s", std::get<PairingResult>(r).connection_address.ToString().c_str()); + LOG_INFO( + "pairing finished successfully with %s", + ADDRESS_TO_LOGGABLE_CSTR(std::get<PairingResult>(r).connection_address)); } else { LOG_INFO("pairing with ... failed: %s", std::get<PairingFailure>(r).message.c_str()); }