From ccdcd15e83812ea860391e3a0db5568f16f344f1 Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Wed, 16 Oct 2024 05:23:32 -0700 Subject: [PATCH] Add WEB_RTC_NON_CELLULAR enum, V PiperOrigin-RevId: 686470433 --- .../implementation/base_pcp_handler.cc | 7 ++++++ connections/implementation/bwu_manager.cc | 24 ++++++++++++++----- .../implementation/mediums/webrtc_stub.cc | 2 ++ .../implementation/mediums/webrtc_stub.h | 2 ++ connections/implementation/offline_frames.cc | 8 +++++++ .../service_controller_router.cc | 1 + 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index d90cd8ae..15a7d566 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -2273,6 +2273,13 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client, client->OnConnectionAccepted(endpoint_id); // Report the current bandwidth to the client + if (FeatureFlags::GetInstance() + .GetFlags() + .support_web_rtc_non_cellular_medium) { + if (medium == Medium::WEB_RTC && !mediums_->GetWebRtc().IsUsingCellular()) { + medium = Medium::WEB_RTC_NON_CELLULAR; + } + } client->OnBandwidthChanged(endpoint_id, medium); NEARBY_LOGS(INFO) << "Connection accepted on Medium:" diff --git a/connections/implementation/bwu_manager.cc b/connections/implementation/bwu_manager.cc index 950a2269..28f37f2c 100644 --- a/connections/implementation/bwu_manager.cc +++ b/connections/implementation/bwu_manager.cc @@ -15,11 +15,13 @@ #include "connections/implementation/bwu_manager.h" #include +#include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/functional/bind_front.h" #include "absl/time/time.h" #include "connections/implementation/analytics/connection_attempt_metadata_params.h" @@ -28,10 +30,9 @@ #include "connections/implementation/client_proxy.h" #include "connections/implementation/endpoint_channel.h" #include "connections/implementation/endpoint_channel_manager.h" -#include "connections/implementation/flags/nearby_connections_feature_flags.h" +#include "connections/implementation/endpoint_manager.h" #include "connections/implementation/offline_frames.h" #include "connections/implementation/service_id_constants.h" -#include "internal/platform/implementation/system_clock.h" #ifdef NO_WEBRTC #include "connections/implementation/webrtc_bwu_handler_stub.h" #else @@ -40,11 +41,14 @@ #include "connections/implementation/wifi_direct_bwu_handler.h" #include "connections/implementation/wifi_hotspot_bwu_handler.h" #include "connections/implementation/wifi_lan_bwu_handler.h" -#include "internal/flags/nearby_flags.h" +#include "connections/medium_selector.h" #include "internal/platform/byte_array.h" +#include "internal/platform/cancelable_alarm.h" #include "internal/platform/count_down_latch.h" #include "internal/platform/feature_flags.h" +#include "internal/platform/implementation/system_clock.h" #include "internal/platform/logging.h" +#include "internal/platform/runnable.h" #include "proto/connections_enums.pb.h" namespace nearby { @@ -472,7 +476,7 @@ BwuHandler* BwuManager::GetHandlerForMedium(Medium medium) const { void BwuManager::OnBwuNegotiationFrame(ClientProxy* client, const BwuNegotiationFrame frame, - const string& endpoint_id) { + const std::string& endpoint_id) { NEARBY_LOGS(INFO) << "OnBwuNegotiationFrame: processing incoming " << BwuNegotiationFrame::EventType_Name(frame.event_type()) << " frame for endpoint " << endpoint_id; @@ -691,7 +695,7 @@ void BwuManager::RunUpgradeProtocol( // Outgoing BWU session. void BwuManager::ProcessBwuPathAvailableEvent( - ClientProxy* client, const string& endpoint_id, + ClientProxy* client, const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) { Medium upgrade_medium = parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium()); @@ -1191,7 +1195,15 @@ void BwuManager::ProcessSafeToClosePriorChannelEvent( channel->Resume(); // Report the success to the client - client->OnBandwidthChanged(endpoint_id, channel->GetMedium()); + Medium medium = channel->GetMedium(); + if (FeatureFlags::GetInstance() + .GetFlags() + .support_web_rtc_non_cellular_medium) { + if (medium == Medium::WEB_RTC && !mediums_->GetWebRtc().IsUsingCellular()) { + medium = Medium::WEB_RTC_NON_CELLULAR; + } + } + client->OnBandwidthChanged(endpoint_id, medium); in_progress_upgrades_.erase(endpoint_id); } diff --git a/connections/implementation/mediums/webrtc_stub.cc b/connections/implementation/mediums/webrtc_stub.cc index 425cce4c..f13e43fc 100644 --- a/connections/implementation/mediums/webrtc_stub.cc +++ b/connections/implementation/mediums/webrtc_stub.cc @@ -57,6 +57,8 @@ WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id, return WebRtcSocketWrapper(); } +bool WebRtc::IsUsingCellular() { return false; } + } // namespace mediums } // namespace connections } // namespace nearby diff --git a/connections/implementation/mediums/webrtc_stub.h b/connections/implementation/mediums/webrtc_stub.h index 3bc01fe7..76223d88 100644 --- a/connections/implementation/mediums/webrtc_stub.h +++ b/connections/implementation/mediums/webrtc_stub.h @@ -72,6 +72,8 @@ class WebRtc { const std::string& service_id, const WebrtcPeerId& peer_id, const location::nearby::connections::LocationHint& location_hint, CancellationFlag* cancellation_flag); + + bool IsUsingCellular(); }; } // namespace mediums diff --git a/connections/implementation/offline_frames.cc b/connections/implementation/offline_frames.cc index 925025ab..e9084d83 100644 --- a/connections/implementation/offline_frames.cc +++ b/connections/implementation/offline_frames.cc @@ -536,6 +536,8 @@ UpgradePathInfo::Medium MediumToUpgradePathInfoMedium(Medium medium) { return UpgradePathInfo::WIFI_DIRECT; case Medium::WEB_RTC: return UpgradePathInfo::WEB_RTC; + case Medium::WEB_RTC_NON_CELLULAR: + return UpgradePathInfo::WEB_RTC_NON_CELLULAR; default: return UpgradePathInfo::UNKNOWN_MEDIUM; } @@ -561,6 +563,8 @@ Medium UpgradePathInfoMediumToMedium(UpgradePathInfo::Medium medium) { return Medium::WIFI_DIRECT; case UpgradePathInfo::WEB_RTC: return Medium::WEB_RTC; + case UpgradePathInfo::WEB_RTC_NON_CELLULAR: + return Medium::WEB_RTC_NON_CELLULAR; default: return Medium::UNKNOWN_MEDIUM; } @@ -586,6 +590,8 @@ ConnectionRequestFrame::Medium MediumToConnectionRequestMedium(Medium medium) { return ConnectionRequestFrame::WIFI_DIRECT; case Medium::WEB_RTC: return ConnectionRequestFrame::WEB_RTC; + case Medium::WEB_RTC_NON_CELLULAR: + return ConnectionRequestFrame::WEB_RTC_NON_CELLULAR; default: return ConnectionRequestFrame::UNKNOWN_MEDIUM; } @@ -611,6 +617,8 @@ Medium ConnectionRequestMediumToMedium(ConnectionRequestFrame::Medium medium) { return Medium::WIFI_DIRECT; case ConnectionRequestFrame::WEB_RTC: return Medium::WEB_RTC; + case ConnectionRequestFrame::WEB_RTC_NON_CELLULAR: + return Medium::WEB_RTC_NON_CELLULAR; default: return Medium::UNKNOWN_MEDIUM; } diff --git a/connections/implementation/service_controller_router.cc b/connections/implementation/service_controller_router.cc index 0a1edb5a..d57ccbed 100644 --- a/connections/implementation/service_controller_router.cc +++ b/connections/implementation/service_controller_router.cc @@ -78,6 +78,7 @@ v3::Quality ServiceControllerRouter::GetMediumQuality(Medium medium) { case location::nearby::proto::connections::WIFI_AWARE: case location::nearby::proto::connections::WIFI_DIRECT: case location::nearby::proto::connections::WEB_RTC: + case location::nearby::proto::connections::WEB_RTC_NON_CELLULAR: return v3::Quality::kHigh; default: return v3::Quality::kUnknown;