diff --git a/Package.swift b/Package.swift index 0f344a63..1b8bd4a9 100644 --- a/Package.swift +++ b/Package.swift @@ -423,6 +423,7 @@ let package = Package( "connections/implementation/offline_service_controller_test.cc", "connections/implementation/encryption_runner_test.cc", "connections/implementation/p2p_cluster_pcp_handler_test.cc", + "connections/implementation/p2p_point_to_point_pcp_handler_test.cc", "connections/implementation/base_pcp_handler_test.cc", "connections/implementation/injected_bluetooth_device_store_test.cc", "connections/implementation/internal_payload_factory_test.cc", diff --git a/connections/implementation/BUILD b/connections/implementation/BUILD index 8172d2b9..6aaad6d5 100644 --- a/connections/implementation/BUILD +++ b/connections/implementation/BUILD @@ -220,6 +220,7 @@ cc_test( "offline_frames_validator_test.cc", "offline_service_controller_test.cc", "p2p_cluster_pcp_handler_test.cc", + "p2p_point_to_point_pcp_handler_test.cc", "payload_manager_test.cc", "pcp_manager_test.cc", "service_controller_router_test.cc", diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index 2aed6a52..167b30dc 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -196,7 +196,14 @@ BooleanMediumSelector BasePcpHandler::ComputeIntersectionOfSupportedMediums( their_mediums.push_back(GetDefaultUpgradeMedium()); } + for (auto medium : their_mediums) { + NEARBY_LOGS(VERBOSE) << "Their supported medium name: " + << proto::connections::Medium_Name(medium); + } + for (Medium my_medium : GetConnectionMediumsByPriority()) { + NEARBY_LOGS(VERBOSE) << "Our supported medium name: " + << proto::connections::Medium_Name(my_medium); if (std::find(their_mediums.begin(), their_mediums.end(), my_medium) != their_mediums.end()) { // We use advertising options as a proxy to whether or not the local diff --git a/connections/implementation/bwu_manager.cc b/connections/implementation/bwu_manager.cc index 5e01b698..b3036dee 100644 --- a/connections/implementation/bwu_manager.cc +++ b/connections/implementation/bwu_manager.cc @@ -1213,12 +1213,12 @@ std::vector BwuManager::StripOutUnavailableMediums( for (Medium m : mediums) { bool available = false; switch (m) { - case Medium::WIFI_HOTSPOT: - available = mediums_->GetWifiHotspot().IsAPAvailable(); - break; case Medium::WIFI_LAN: available = mediums_->GetWifiLan().IsAvailable(); break; + case Medium::WIFI_HOTSPOT: + available = mediums_->GetWifiHotspot().IsAPAvailable(); + break; case Medium::WEB_RTC: available = mediums_->GetWebRtc().IsAvailable(); break; diff --git a/connections/implementation/p2p_point_to_point_pcp_handler.cc b/connections/implementation/p2p_point_to_point_pcp_handler.cc index e4035529..a933a291 100644 --- a/connections/implementation/p2p_point_to_point_pcp_handler.cc +++ b/connections/implementation/p2p_point_to_point_pcp_handler.cc @@ -14,6 +14,8 @@ #include "connections/implementation/p2p_point_to_point_pcp_handler.h" +#include + namespace location { namespace nearby { namespace connections { @@ -28,13 +30,13 @@ P2pPointToPointPcpHandler::P2pPointToPointPcpHandler( std::vector P2pPointToPointPcpHandler::GetConnectionMediumsByPriority() { std::vector mediums; + if (mediums_->GetWifiLan().IsAvailable()) { + mediums.push_back(proto::connections::WIFI_LAN); + } if (mediums_->GetWifi().IsAvailable() && mediums_->GetWifiHotspot().IsClientAvailable()) { mediums.push_back(proto::connections::WIFI_HOTSPOT); } - if (mediums_->GetWifiLan().IsAvailable()) { - mediums.push_back(proto::connections::WIFI_LAN); - } if (mediums_->GetWebRtc().IsAvailable()) { mediums.push_back(proto::connections::WEB_RTC); } diff --git a/connections/implementation/p2p_point_to_point_pcp_handler_test.cc b/connections/implementation/p2p_point_to_point_pcp_handler_test.cc new file mode 100644 index 00000000..fdd61f3e --- /dev/null +++ b/connections/implementation/p2p_point_to_point_pcp_handler_test.cc @@ -0,0 +1,30 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "connections/implementation/p2p_point_to_point_pcp_handler.h" + +#include "gmock/gmock.h" +#include "protobuf-matchers/protocol-buffer-matchers.h" +#include "gtest/gtest.h" + +namespace location { +namespace nearby { +namespace connections { + +// TODO(b/257120173): Add Units Test for P2pPointToPointPcpHandler +TEST(P2pPointToPointPcpHandlerTest, CanConnect) {} + +} // namespace connections +} // namespace nearby +} // namespace location diff --git a/connections/implementation/p2p_star_pcp_handler.cc b/connections/implementation/p2p_star_pcp_handler.cc index 2d9d3476..7b65aee4 100644 --- a/connections/implementation/p2p_star_pcp_handler.cc +++ b/connections/implementation/p2p_star_pcp_handler.cc @@ -33,13 +33,13 @@ P2pStarPcpHandler::P2pStarPcpHandler( std::vector P2pStarPcpHandler::GetConnectionMediumsByPriority() { std::vector mediums; + if (mediums_->GetWifiLan().IsAvailable()) { + mediums.push_back(proto::connections::WIFI_LAN); + } if (mediums_->GetWifi().IsAvailable() && mediums_->GetWifiHotspot().IsClientAvailable()) { mediums.push_back(proto::connections::WIFI_HOTSPOT); } - if (mediums_->GetWifiLan().IsAvailable()) { - mediums.push_back(proto::connections::WIFI_LAN); - } if (mediums_->GetWebRtc().IsAvailable()) { mediums.push_back(proto::connections::WEB_RTC); } diff --git a/connections/medium_selector.h b/connections/medium_selector.h index 4fd92590..502ed387 100644 --- a/connections/medium_selector.h +++ b/connections/medium_selector.h @@ -63,8 +63,8 @@ struct MediumSelector { std::vector GetMediums(T value) const { std::vector mediums; // Mediums are sorted in order of decreasing preference. - if (wifi_hotspot == value) mediums.push_back(Medium::WIFI_HOTSPOT); if (wifi_lan == value) mediums.push_back(Medium::WIFI_LAN); + if (wifi_hotspot == value) mediums.push_back(Medium::WIFI_HOTSPOT); if (web_rtc == value) mediums.push_back(Medium::WEB_RTC); if (bluetooth == value) mediums.push_back(Medium::BLUETOOTH); if (ble == value) mediums.push_back(Medium::BLE); diff --git a/internal/platform/implementation/windows/wifi_medium.cc b/internal/platform/implementation/windows/wifi_medium.cc index 19e00463..034a139b 100644 --- a/internal/platform/implementation/windows/wifi_medium.cc +++ b/internal/platform/implementation/windows/wifi_medium.cc @@ -148,7 +148,7 @@ api::WifiInformation& WifiMedium::GetInformation() { wifi_information_.ap_frequency = WifiUtils::ConvertChannelToFrequencyMhz( *channel, api::WifiBandType::kUnknown); - NEARBY_LOGS(INFO) << "Frequency: " << *channel << "; ap_frequency: " + NEARBY_LOGS(INFO) << "Channel: " << *channel << "; ap_frequency: " << wifi_information_.ap_frequency; WlanFreeMemory(channel); channel = NULL;