mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Remove Hotspot native scan logic.
PiperOrigin-RevId: 825154644
This commit is contained in:
committed by
Copybara-Service
parent
5c067f4811
commit
1cd7aa5859
@@ -73,10 +73,6 @@ constexpr auto kEnableMdnsIpv6 =
|
||||
constexpr auto kEnableNewBluetoothRefactor =
|
||||
flags::Flag<bool>(kConfigPackage, "45615156", false);
|
||||
|
||||
// Enable/Disable Wi-Fi hotspot scan in native
|
||||
constexpr auto kEnableWifiHotspotNativeScan =
|
||||
flags::Flag<bool>(kConfigPackage, "45670001", false);
|
||||
|
||||
// The send buffer size of blocking socket
|
||||
constexpr auto kSocketSendBufferSize =
|
||||
flags::Flag<int64_t>(kConfigPackage, "45673785", 524288);
|
||||
|
||||
@@ -410,21 +410,6 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
}
|
||||
}
|
||||
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableWifiHotspotNativeScan)) {
|
||||
if (!wifi_hotspot_native_.Scan(ssid)) {
|
||||
LOG(INFO) << "Hotspot " << ssid << " is not found";
|
||||
|
||||
if (intel_wifi_started) {
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
intel_wifi.ResetScanFilter();
|
||||
intel_wifi.Stop();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool connected =
|
||||
wifi_hotspot_native_.ConnectToWifiNetwork(ssid, password);
|
||||
|
||||
|
||||
@@ -154,53 +154,6 @@ bool WifiHotspotNative::DisconnectWifiNetwork() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WifiHotspotNative::Scan(absl::string_view ssid) {
|
||||
GUID interface_guid = GetInterfaceGuid();
|
||||
if (interface_guid == GUID_NULL) {
|
||||
LOG(ERROR) << __func__ << ": No available WLAN Interface to use.";
|
||||
return false;
|
||||
}
|
||||
WlanNotificationContext context = {
|
||||
.wifi_hotspot_native = *this,
|
||||
};
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!RegisterWlanNotificationCallback(&context)) {
|
||||
LOG(ERROR) << "Failed to register WLAN notification callback.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ssid.length() > DOT11_SSID_MAX_LENGTH) {
|
||||
LOG(ERROR) << "Invalid SSID length.";
|
||||
return false;
|
||||
}
|
||||
|
||||
DOT11_SSID dot11_ssid;
|
||||
dot11_ssid.uSSIDLength = ssid.length();
|
||||
memcpy(dot11_ssid.ucSSID, ssid.data(), dot11_ssid.uSSIDLength);
|
||||
scan_latch_ = std::make_unique<CountDownLatch>(1);
|
||||
scanning_ssid_ = ssid;
|
||||
DWORD result = WlanScan(
|
||||
/*hClientHandle=*/wifi_, /*pInterfaceGuid=*/&interface_guid,
|
||||
/*pDot11Ssid=*/&dot11_ssid, /*pIeData=*/nullptr, /*pReserved=*/nullptr);
|
||||
|
||||
if (result != ERROR_SUCCESS) {
|
||||
LOG(ERROR) << "Failed to scan Wi-Fi network with error " << result;
|
||||
UnregisterWlanNotificationCallback();
|
||||
return false;
|
||||
}
|
||||
|
||||
ExceptionOr<bool> scan_result = scan_latch_->Await(kConnectTimeout);
|
||||
UnregisterWlanNotificationCallback();
|
||||
|
||||
if (!scan_result.ok() || !scan_result.result()) {
|
||||
LOG(ERROR) << "Failed to scan to Wifi network " << ssid;
|
||||
return false;
|
||||
}
|
||||
|
||||
scan_latch_ = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiHotspotNative::TriggerConnected() {
|
||||
if (connect_latch_ == nullptr) {
|
||||
return;
|
||||
@@ -208,44 +161,6 @@ void WifiHotspotNative::TriggerConnected() {
|
||||
connect_latch_->CountDown();
|
||||
}
|
||||
|
||||
void WifiHotspotNative::TriggerNetworkRefreshed() {
|
||||
if (scan_latch_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
GUID interface_guid = GetInterfaceGuid();
|
||||
if (interface_guid == GUID_NULL) {
|
||||
LOG(ERROR) << __func__ << ": No available WLAN Interface to use.";
|
||||
return;
|
||||
}
|
||||
|
||||
PWLAN_AVAILABLE_NETWORK_LIST list = nullptr;
|
||||
DWORD result = WlanGetAvailableNetworkList(
|
||||
/*hClientHandle=*/wifi_, /*pInterfaceGuid=*/&interface_guid,
|
||||
/*dwFlags=*/WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES,
|
||||
/*pReserved=*/nullptr, /*ppAvailableNetworkList=*/&list);
|
||||
if (result != ERROR_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool found_ssid = false;
|
||||
for (int i = 0; i < list->dwNumberOfItems; i++) {
|
||||
std::string ssid = std::string((char*)list->Network[i].dot11Ssid.ucSSID,
|
||||
list->Network[i].dot11Ssid.uSSIDLength);
|
||||
if (ssid == scanning_ssid_) {
|
||||
found_ssid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WlanFreeMemory(list);
|
||||
|
||||
if (found_ssid) {
|
||||
LOG(INFO) << "Found WLAN network " << scanning_ssid_;
|
||||
scan_latch_->CountDown();
|
||||
}
|
||||
}
|
||||
|
||||
void WifiHotspotNative::WlanNotificationCallback(
|
||||
PWLAN_NOTIFICATION_DATA wlan_notification_data, PVOID context) {
|
||||
VLOG(1) << "WlanNotificationCallback is called with notification code "
|
||||
@@ -282,7 +197,6 @@ void WifiHotspotNative::WlanNotificationCallback(
|
||||
}
|
||||
case wlan_notification_acm_scan_list_refresh: {
|
||||
LOG(INFO) << "Scan list refreshed.";
|
||||
wlan_context->wifi_hotspot_native.TriggerNetworkRefreshed();
|
||||
break;
|
||||
}
|
||||
case wlan_notification_acm_disconnecting: {
|
||||
|
||||
@@ -44,8 +44,6 @@ class WifiHotspotNative {
|
||||
|
||||
bool RestoreWifiProfile() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool Scan(absl::string_view ssid) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns true if the interface has a non local scoped IPv4 address.
|
||||
bool HasAssignedAddress();
|
||||
bool RenewIpv4Address() const;
|
||||
@@ -85,15 +83,12 @@ class WifiHotspotNative {
|
||||
bool RemoveWlanProfile(GUID interface_guid, const std::wstring& profile_name)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
void TriggerConnected();
|
||||
void TriggerNetworkRefreshed();
|
||||
|
||||
NetworkInfo& network_info_;
|
||||
mutable absl::Mutex mutex_;
|
||||
|
||||
HANDLE wifi_ = nullptr;
|
||||
std::string scanning_ssid_;
|
||||
std::unique_ptr<CountDownLatch> connect_latch_;
|
||||
std::unique_ptr<CountDownLatch> scan_latch_;
|
||||
std::wstring backup_profile_name_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user