mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Cleanup use of HotspotCredentials.
PiperOrigin-RevId: 824262890
This commit is contained in:
committed by
Copybara-Service
parent
be3e658d75
commit
1210969d04
@@ -217,7 +217,8 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
// Advertiser stop the current WiFi Hotspot
|
||||
bool StopWifiHotspot() override;
|
||||
// Discoverer connects to the Hotspot
|
||||
bool ConnectWifiHotspot(HotspotCredentials* hotspot_credentials) override;
|
||||
bool ConnectWifiHotspot(
|
||||
const HotspotCredentials& hotspot_credentials) override;
|
||||
// Discoverer disconnects from the Hotspot
|
||||
bool DisconnectWifiHotspot() override;
|
||||
|
||||
|
||||
@@ -383,9 +383,11 @@ fire_and_forget WifiHotspotMedium::OnConnectionRequested(
|
||||
}
|
||||
|
||||
bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
HotspotCredentials* hotspot_credentials) {
|
||||
const HotspotCredentials& hotspot_credentials) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
|
||||
std::string ssid = hotspot_credentials.GetSSID();
|
||||
std::string password = hotspot_credentials.GetPassword();
|
||||
try {
|
||||
if (IsConnected()) {
|
||||
LOG(WARNING) << "Already connected to Hotspot, disconnect first.";
|
||||
@@ -398,7 +400,7 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableIntelPieSdk)) {
|
||||
auto channel = WifiUtils::ConvertFrequencyMhzToChannel(
|
||||
hotspot_credentials->GetFrequency());
|
||||
hotspot_credentials.GetFrequency());
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
intel_wifi_started = intel_wifi.Start();
|
||||
if (intel_wifi_started) {
|
||||
@@ -409,9 +411,8 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableWifiHotspotNativeScan)) {
|
||||
if (!wifi_hotspot_native_.Scan(hotspot_credentials->GetSSID())) {
|
||||
LOG(INFO) << "Hotspot " << hotspot_credentials->GetSSID()
|
||||
<< " is not found";
|
||||
if (!wifi_hotspot_native_.Scan(ssid)) {
|
||||
LOG(INFO) << "Hotspot " << ssid << " is not found";
|
||||
|
||||
if (intel_wifi_started) {
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
@@ -423,7 +424,7 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
}
|
||||
|
||||
bool connected =
|
||||
wifi_hotspot_native_.ConnectToWifiNetwork(hotspot_credentials);
|
||||
wifi_hotspot_native_.ConnectToWifiNetwork(ssid, password);
|
||||
|
||||
if (intel_wifi_started) {
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
@@ -486,7 +487,7 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
return false;
|
||||
}
|
||||
medium_status_ |= kMediumStatusConnected;
|
||||
LOG(INFO) << "Connected to hotspot: " << hotspot_credentials->GetSSID();
|
||||
LOG(INFO) << "Connected to hotspot: " << ssid;
|
||||
|
||||
return true;
|
||||
} catch (std::exception exception) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <cstring>
|
||||
#include <cwchar>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -39,7 +38,6 @@
|
||||
#include "internal/platform/implementation/windows/network_info.h"
|
||||
#include "internal/platform/implementation/windows/string_utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
|
||||
namespace nearby::windows {
|
||||
|
||||
@@ -113,8 +111,8 @@ WifiHotspotNative::~WifiHotspotNative() {
|
||||
VLOG(1) << "WifiHotspotNative destroyed successfully.";
|
||||
}
|
||||
|
||||
bool WifiHotspotNative::ConnectToWifiNetwork(
|
||||
HotspotCredentials* hotspot_credentials) {
|
||||
bool WifiHotspotNative::ConnectToWifiNetwork(absl::string_view ssid,
|
||||
absl::string_view password) {
|
||||
GUID interface_guid = GetInterfaceGuid();
|
||||
if (interface_guid == GUID_NULL) {
|
||||
LOG(ERROR) << __func__ << ": No available WLAN Interface to use.";
|
||||
@@ -122,7 +120,7 @@ bool WifiHotspotNative::ConnectToWifiNetwork(
|
||||
}
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!SetWlanProfile(interface_guid, hotspot_credentials)) {
|
||||
if (!SetWlanProfile(interface_guid, ssid, password)) {
|
||||
LOG(ERROR) << "Failed to set WLAN profile.";
|
||||
return false;
|
||||
}
|
||||
@@ -428,9 +426,8 @@ bool WifiHotspotNative::UnregisterWlanNotificationCallback() {
|
||||
}
|
||||
|
||||
bool WifiHotspotNative::SetWlanProfile(
|
||||
GUID interface_guid, HotspotCredentials* hotspot_credentials) {
|
||||
std::wstring profile = BuildWlanProfile(hotspot_credentials->GetSSID(),
|
||||
hotspot_credentials->GetPassword());
|
||||
GUID interface_guid, absl::string_view ssid, absl::string_view password) {
|
||||
std::wstring profile = BuildWlanProfile(ssid, password);
|
||||
DWORD reason = 0;
|
||||
DWORD result = WlanSetProfile(
|
||||
/*hClientHandle=*/wifi_, /*pInterfaceGuid=*/&interface_guid,
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
// clang-format on
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/base/thread_annotations.h"
|
||||
@@ -33,7 +31,6 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/implementation/windows/network_info.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
|
||||
namespace nearby::windows {
|
||||
|
||||
@@ -41,7 +38,7 @@ class WifiHotspotNative {
|
||||
public:
|
||||
WifiHotspotNative();
|
||||
~WifiHotspotNative();
|
||||
bool ConnectToWifiNetwork(HotspotCredentials* hotspot_credentials)
|
||||
bool ConnectToWifiNetwork(absl::string_view ssid, absl::string_view password)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool DisconnectWifiNetwork() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
@@ -80,8 +77,8 @@ class WifiHotspotNative {
|
||||
WlanNotificationContext* absl_nonnull context)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
bool UnregisterWlanNotificationCallback();
|
||||
bool SetWlanProfile(GUID interface_guid,
|
||||
HotspotCredentials* hotspot_credentials)
|
||||
bool SetWlanProfile(GUID interface_guid, absl::string_view ssid,
|
||||
absl::string_view password)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
bool RemoveCreatedWlanProfile(GUID interface_guid)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
@@ -121,7 +121,7 @@ TEST(WifiHotspotMedium, DISABLED_ConnectWifiHotspot) {
|
||||
kEnableIntelPieSdk,
|
||||
true);
|
||||
|
||||
EXPECT_TRUE(hotspot_medium.ConnectWifiHotspot(&hotspot_credentials));
|
||||
EXPECT_TRUE(hotspot_medium.ConnectWifiHotspot(hotspot_credentials));
|
||||
absl::SleepFor(absl::Seconds(1));
|
||||
while (true) {
|
||||
LOG(INFO) << "Enter \"s\" to stop test:";
|
||||
|
||||
Reference in New Issue
Block a user