mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Cleanup use of HotspotCredentials.
PiperOrigin-RevId: 824262890
This commit is contained in:
committed by
Copybara-Service
parent
be3e658d75
commit
1210969d04
@@ -72,7 +72,7 @@ const char kIPAddress[] = "192.168.1.2";
|
||||
hotspotCredentials.SetSSID("TestSSID");
|
||||
hotspotCredentials.SetPassword("TestPassword");
|
||||
|
||||
XCTAssertFalse(_hotspotMedium->ConnectWifiHotspot(&hotspotCredentials));
|
||||
XCTAssertFalse(_hotspotMedium->ConnectWifiHotspot(hotspotCredentials));
|
||||
}
|
||||
|
||||
- (void)testListenForService {
|
||||
|
||||
@@ -103,7 +103,7 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
*
|
||||
* @param hotspot_credentials_ The credentials of the Wifi Hotspot to connect to.
|
||||
*/
|
||||
bool ConnectWifiHotspot(HotspotCredentials* hotspot_credentials_) override;
|
||||
bool ConnectWifiHotspot(const HotspotCredentials& hotspot_credentials_) override;
|
||||
|
||||
/**
|
||||
* @brief Disconnects from the currently connected Wifi Hotspot.
|
||||
|
||||
@@ -110,9 +110,9 @@ WifiHotspotMedium::WifiHotspotMedium(GNCHotspotMedium* hotspot_medium) : medium_
|
||||
|
||||
WifiHotspotMedium::~WifiHotspotMedium() { DisconnectWifiHotspot(); }
|
||||
|
||||
bool WifiHotspotMedium::ConnectWifiHotspot(HotspotCredentials* hotspot_credentials_) {
|
||||
NSString* ssid = [[NSString alloc] initWithUTF8String:hotspot_credentials_->GetSSID().c_str()];
|
||||
std::string hotspot_password = hotspot_credentials_->GetPassword();
|
||||
bool WifiHotspotMedium::ConnectWifiHotspot(const HotspotCredentials& hotspot_credentials_) {
|
||||
NSString* ssid = [[NSString alloc] initWithUTF8String:hotspot_credentials_.GetSSID().c_str()];
|
||||
std::string hotspot_password = hotspot_credentials_.GetPassword();
|
||||
NSString* password = [[NSString alloc] initWithUTF8String:hotspot_password.c_str()];
|
||||
|
||||
GNCLoggerInfo(@"ConnectWifiHotspot SSID: %@ Password: %s", ssid,
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "internal/platform/implementation/g3/wifi_hotspot.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -158,23 +157,23 @@ bool WifiHotspotMedium::StopWifiHotspot() {
|
||||
}
|
||||
|
||||
bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
HotspotCredentials* hotspot_credentials) {
|
||||
const HotspotCredentials& hotspot_credentials) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
|
||||
LOG(INFO) << "G3 ConnectWifiHotspot: ssid=" << hotspot_credentials->GetSSID()
|
||||
<< ", password:" << hotspot_credentials->GetPassword();
|
||||
LOG(INFO) << "G3 ConnectWifiHotspot: ssid=" << hotspot_credentials.GetSSID()
|
||||
<< ", password:" << hotspot_credentials.GetPassword();
|
||||
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
auto* remote_medium = static_cast<WifiHotspotMedium*>(
|
||||
env.GetWifiHotspotMedium(hotspot_credentials->GetSSID(), {}));
|
||||
env.GetWifiHotspotMedium(hotspot_credentials.GetSSID(), ""));
|
||||
if (!remote_medium) {
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, &hotspot_credentials,
|
||||
/*is_ap=*/false,
|
||||
/*enabled=*/false);
|
||||
return false;
|
||||
}
|
||||
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, &hotspot_credentials,
|
||||
/*is_ap=*/false,
|
||||
/*enabled=*/true);
|
||||
return true;
|
||||
|
||||
@@ -158,7 +158,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;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/listeners.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
|
||||
@@ -101,7 +100,8 @@ class WifiHotspotMedium {
|
||||
virtual bool StopWifiHotspot() = 0;
|
||||
|
||||
// Client device connect to a softAP with specified credential.
|
||||
virtual bool ConnectWifiHotspot(HotspotCredentials* hotspot_credentials) = 0;
|
||||
virtual bool ConnectWifiHotspot(
|
||||
const HotspotCredentials& hotspot_credentials) = 0;
|
||||
virtual bool DisconnectWifiHotspot() = 0;
|
||||
|
||||
// Returns the port range as a pair of min and max port.
|
||||
|
||||
@@ -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:";
|
||||
|
||||
@@ -1056,8 +1056,8 @@ api::WifiHotspotMedium* MediumEnvironment::GetWifiHotspotMedium(
|
||||
}
|
||||
|
||||
void MediumEnvironment::UpdateWifiHotspotMediumForStartOrConnect(
|
||||
api::WifiHotspotMedium& medium, HotspotCredentials* hotspot_credentials,
|
||||
bool is_ap, bool enabled) {
|
||||
api::WifiHotspotMedium& medium,
|
||||
const HotspotCredentials* hotspot_credentials, bool is_ap, bool enabled) {
|
||||
if (!enabled_) return;
|
||||
|
||||
CountDownLatch latch(1);
|
||||
|
||||
@@ -325,8 +325,8 @@ class MediumEnvironment {
|
||||
// Updates credential and Medium role(AP or STA) to indicate the current
|
||||
// medium is exposing Start Hotspot event.
|
||||
void UpdateWifiHotspotMediumForStartOrConnect(
|
||||
api::WifiHotspotMedium& medium, HotspotCredentials* hotspot_credentials,
|
||||
bool is_ap, bool enabled);
|
||||
api::WifiHotspotMedium& medium,
|
||||
const HotspotCredentials* hotspot_credentials, bool is_ap, bool enabled);
|
||||
|
||||
// Removes medium-related info. This should correspond to device stopped or
|
||||
// disconnected.
|
||||
@@ -435,7 +435,7 @@ class MediumEnvironment {
|
||||
bool is_ap = true;
|
||||
// Set "true" when SoftAP is started or STA is connected
|
||||
bool is_active = false;
|
||||
HotspotCredentials* hotspot_credentials;
|
||||
const HotspotCredentials* hotspot_credentials;
|
||||
};
|
||||
|
||||
struct BluetoothPairingContext {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
@@ -187,7 +186,7 @@ class WifiHotspotMedium {
|
||||
bool ConnectWifiHotspot(const HotspotCredentials& hotspot_credentials) {
|
||||
MutexLock lock(&mutex_);
|
||||
hotspot_credentials_ = hotspot_credentials;
|
||||
return impl_->ConnectWifiHotspot(&hotspot_credentials_);
|
||||
return impl_->ConnectWifiHotspot(hotspot_credentials);
|
||||
}
|
||||
bool DisconnectWifiHotspot() { return impl_->DisconnectWifiHotspot(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user