From ec0de73e8e78d3665f50ee069100a630b3306e9b Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Thu, 22 Aug 2024 15:21:05 -0700 Subject: [PATCH] internal medium fix PiperOrigin-RevId: 666509363 --- connections/implementation/BUILD | 1 + connections/implementation/base_pcp_handler.cc | 11 +++++++++-- connections/implementation/pcp_manager_test.cc | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/connections/implementation/BUILD b/connections/implementation/BUILD index 7e0146ef..3311e5b9 100644 --- a/connections/implementation/BUILD +++ b/connections/implementation/BUILD @@ -239,6 +239,7 @@ cc_test( ":internal_test", "//connections:core_types", "//connections/v3:v3_types", + "//internal/platform:base", "//internal/platform:test_util", "//internal/platform:types", "//internal/platform/implementation/g3", # build_cleaner: keep diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index da76721c..450622ea 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -2183,8 +2183,15 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client, auto pair = pending_connections_.extract(it); BasePcpHandler::PendingConnectionInfo& connection_info = pair.mapped(); - Medium medium = - channel_manager_->GetChannelForEndpoint(endpoint_id)->GetMedium(); + std::shared_ptr endpint_channel = + channel_manager_->GetChannelForEndpoint(endpoint_id); + if (endpint_channel == nullptr) { + NEARBY_LOGS(WARNING) << "No endpint channel for endpoint_id=" + << endpoint_id; + return; + } + + Medium medium = endpint_channel->GetMedium(); Status response_code; if (is_connection_accepted) { diff --git a/connections/implementation/pcp_manager_test.cc b/connections/implementation/pcp_manager_test.cc index ce2c1698..518e7bdb 100644 --- a/connections/implementation/pcp_manager_test.cc +++ b/connections/implementation/pcp_manager_test.cc @@ -26,7 +26,11 @@ #include "connections/implementation/mock_device.h" #include "connections/implementation/simulation_user.h" #include "connections/medium_selector.h" +#include "connections/out_of_band_connection_metadata.h" +#include "connections/status.h" +#include "connections/strategy.h" #include "connections/v3/connection_listening_options.h" +#include "internal/platform/byte_array.h" #include "internal/platform/count_down_latch.h" #include "internal/platform/medium_environment.h" @@ -243,6 +247,7 @@ TEST_F(PcpManagerTest, InjectEndpoint) { .remote_bluetooth_mac_address = ByteArray(kFakeMacAddress), }); + user_a.StopDiscovery(); user_a.Stop(); env_.Stop(); }