From 9cd75f8e27ee6d3b2e2b0c9f5d4ba9b8645ad68e Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 24 Feb 2025 19:52:44 -0800 Subject: [PATCH] [NearbyConnections] Update ios BLE discovery related logs PiperOrigin-RevId: 730693835 --- connections/implementation/ble_advertisement.h | 11 +++++++++++ .../mediums/ble_v2/ble_advertisement.h | 14 ++++++++++++++ .../ble_v2/discovered_peripheral_tracker.cc | 12 ++---------- .../implementation/p2p_cluster_pcp_handler.cc | 15 ++++----------- internal/platform/BUILD | 1 + internal/platform/ble_v2.cc | 3 --- internal/platform/ble_v2.h | 10 ++++++++++ 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/connections/implementation/ble_advertisement.h b/connections/implementation/ble_advertisement.h index d50ebf94..b27d1482 100644 --- a/connections/implementation/ble_advertisement.h +++ b/connections/implementation/ble_advertisement.h @@ -14,8 +14,11 @@ #ifndef CORE_INTERNAL_BLE_ADVERTISEMENT_H_ #define CORE_INTERNAL_BLE_ADVERTISEMENT_H_ +#include #include "absl/status/statusor.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_format.h" #include "connections/implementation/base_pcp_handler.h" #include "connections/implementation/pcp.h" #include "internal/platform/bluetooth_utils.h" @@ -98,6 +101,14 @@ class BleAdvertisement { std::string GetBluetoothMacAddress() const { return bluetooth_mac_address_; } ByteArray GetUwbAddress() const { return uwb_address_; } WebRtcState GetWebRtcState() const { return web_rtc_state_; } + std::string ToReadableString() const { + return absl::StrFormat( + "BleAdvertisement { version=%d, pcp=%d, fast_advertisement=%v, " + "service_id_hash=%s, endpoint_id=%s, endpoint_info_=%s}", + static_cast(version_), static_cast(pcp_), fast_advertisement_, + absl::BytesToHexString(service_id_hash_.AsStringView()), endpoint_id_, + absl::BytesToHexString(endpoint_info_.AsStringView())); + } private: void DoInitialize(bool fast_advertisement, Version version, Pcp pcp, diff --git a/connections/implementation/mediums/ble_v2/ble_advertisement.h b/connections/implementation/mediums/ble_v2/ble_advertisement.h index 5a470584..232d4d08 100644 --- a/connections/implementation/mediums/ble_v2/ble_advertisement.h +++ b/connections/implementation/mediums/ble_v2/ble_advertisement.h @@ -15,9 +15,12 @@ #ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_H_ #define CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_H_ +#include #include #include "absl/status/statusor.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_format.h" #include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h" #include "internal/platform/byte_array.h" @@ -101,6 +104,17 @@ class BleAdvertisement { ByteArray GetDeviceToken() const { return device_token_; } int GetPsm() const { return psm_; } void SetPsm(int psm) { psm_ = psm; } + std::string ToReadableString() const { + return absl::StrFormat( + "BleAdvertisement { version=%d, socket_version=%d, " + "fast_advertisement=%v, service_id_hash=%s, data=%s, device_token=%s, " + "psm=%d }", + static_cast(version_), static_cast(socket_version_), + fast_advertisement_, + absl::BytesToHexString(service_id_hash_.AsStringView()), + absl::BytesToHexString(data_.AsStringView()), + absl::BytesToHexString(device_token_.AsStringView()), psm_); + } private: // Represents the extra fields of the `BleAdvertisement` used in Advertising + diff --git a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc index 1bcafb81..450aa8a2 100644 --- a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc +++ b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc @@ -167,9 +167,6 @@ bool DiscoveredPeripheralTracker::HandleOnLostAdvertisementLocked( return false; } - LOG(INFO) << __func__ << ": Found OnLost advertisement for hash:" - << absl::BytesToHexString(on_lost_advertisement->ToBytes()); - for (const auto& hash : on_lost_advertisement->hashes()) { for (const auto& it : gatt_advertisement_infos_) { if (it.second.advertisement_header.GetAdvertisementHash().string_data() == @@ -449,13 +446,8 @@ BleAdvertisementHeader DiscoveredPeripheralTracker::HandleRawGattAdvertisements( continue; } - LOG(INFO) - << "Report new peripheral for the advertisement header with hash " - << absl::BytesToHexString( - new_advertisement_header.GetAdvertisementHash() - .AsStringView()) - << ", IsFastAdvertisement " - << gatt_advertisement.IsFastAdvertisement(); + LOG(INFO) << "Found new GATT advertisement : " + << gatt_advertisement.ToReadableString(); sii_it->second.discovered_peripheral_callback.peripheral_discovered_cb( std::move(discovered_peripheral), service_id, gatt_advertisement.GetData(), diff --git a/connections/implementation/p2p_cluster_pcp_handler.cc b/connections/implementation/p2p_cluster_pcp_handler.cc index 71467b4c..b66b6806 100644 --- a/connections/implementation/p2p_cluster_pcp_handler.cc +++ b/connections/implementation/p2p_cluster_pcp_handler.cc @@ -787,13 +787,7 @@ void P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler( ble_endpoint_state.ble = true; found_endpoints_in_ble_discover_cb_[peripheral_id] = ble_endpoint_state; - LOG(INFO) << "Found BleAdvertisement " - << absl::BytesToHexString(advertisement_bytes.data()) - << " (with endpoint_id=" << advertisement.GetEndpointId() - << ", and endpoint_info=" - << absl::BytesToHexString( - advertisement.GetEndpointInfo().data()) - << ")."; + LOG(INFO) << "Found " << advertisement.ToReadableString(); StopEndpointLostByMediumAlarm(advertisement.GetEndpointId(), BLE); OnEndpointFound( client, @@ -2620,12 +2614,11 @@ ErrorOr P2pClusterPcpHandler::StartBleV2Scanning( BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl( ClientProxy* client, BleV2Endpoint* endpoint) { - VLOG(1) << "Client " << client->GetClientId() - << " is attempting to connect to endpoint(id=" - << endpoint->endpoint_id << ") over BLE."; - BleV2Peripheral& peripheral = endpoint->ble_peripheral; + VLOG(1) << "Client " << client->GetClientId() + << " is attempting to connect to (" << peripheral.ToReadableString() + << ") over BLE."; ErrorOr ble_socket_result = ble_v2_medium_.Connect( endpoint->service_id, peripheral, client->GetCancellationFlag(endpoint->endpoint_id)); diff --git a/internal/platform/BUILD b/internal/platform/BUILD index 792154af..46e7041e 100644 --- a/internal/platform/BUILD +++ b/internal/platform/BUILD @@ -339,6 +339,7 @@ cc_library( "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:optional", ], ) diff --git a/internal/platform/ble_v2.cc b/internal/platform/ble_v2.cc index 2a0e9593..3a5a52fe 100644 --- a/internal/platform/ble_v2.cc +++ b/internal/platform/ble_v2.cc @@ -75,9 +75,6 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid, } BleV2Peripheral proxy(*this, peripheral); - NEARBY_LOGS(INFO) - << "New peripheral imp=" << &peripheral - << ", callback the proxy peripheral=" << &proxy; if (!scanning_enabled_) return; scan_callback_.advertisement_found_cb(std::move(proxy), advertisement_data); diff --git a/internal/platform/ble_v2.h b/internal/platform/ble_v2.h index b4a5b3d3..7cb0aa74 100644 --- a/internal/platform/ble_v2.h +++ b/internal/platform/ble_v2.h @@ -22,6 +22,8 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "internal/platform/bluetooth_adapter.h" @@ -63,6 +65,14 @@ class BleV2Peripheral final { explicit operator bool() const { return IsValid(); } bool GetImpl(ImplCallback callback) const; + std::string ToReadableString() const { + if (!IsValid()) { + return "BleV2Peripheral { invalid }"; + } + return absl::StrFormat("BleV2Peripheral { id=%s, psm=%d}", + absl::BytesToHexString(GetId().AsStringView()), + GetPsm()); + } private: BleV2Medium* medium_ = nullptr;