mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove unused hotspot ssid file.
PiperOrigin-RevId: 816396622
This commit is contained in:
committed by
Copybara-Service
parent
417e1ba714
commit
f915b01b75
@@ -198,7 +198,7 @@ class WifiHotspotServerSocket : public api::WifiHotspotServerSocket {
|
||||
// Container of operations that can be performed over the WifiHotspot medium.
|
||||
class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
public:
|
||||
WifiHotspotMedium();
|
||||
WifiHotspotMedium() = default;
|
||||
~WifiHotspotMedium() override;
|
||||
|
||||
// If the WiFi Adaptor supports to start a Hotspot interface.
|
||||
@@ -235,11 +235,6 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
kMediumStatusConnected = (1 << 2),
|
||||
};
|
||||
|
||||
// Store the Hotspot SSID to local storage
|
||||
void StoreHotspotSsid(std::string ssid);
|
||||
// Get the Hotspot SSID from local storage
|
||||
std::string GetStoredHotspotSsid();
|
||||
|
||||
bool IsIdle() { return medium_status_ == kMediumStatusIdle; }
|
||||
// Advertiser is accepting connection on server socket
|
||||
bool IsAccepting() { return (medium_status_ & kMediumStatusAccepting) != 0; }
|
||||
|
||||
@@ -48,19 +48,8 @@ using ::winrt::Windows::Devices::WiFiDirect::
|
||||
WiFiDirectAdvertisementPublisherStatus;
|
||||
using ::winrt::Windows::Devices::WiFiDirect::WiFiDirectConnectionRequest;
|
||||
using ::winrt::Windows::Security::Credentials::PasswordCredential;
|
||||
|
||||
constexpr absl::string_view kHotspotSsidFileName = "ssid.txt";
|
||||
} // namespace
|
||||
|
||||
WifiHotspotMedium::WifiHotspotMedium() {
|
||||
std::string ssid = GetStoredHotspotSsid();
|
||||
if (!ssid.empty()) {
|
||||
LOG(INFO) << "Get stored Hotspot SSID: " << ssid << " from previous run";
|
||||
wifi_hotspot_native_.DeleteWifiProfile(winrt::to_hstring(ssid).c_str());
|
||||
StoreHotspotSsid({});
|
||||
}
|
||||
}
|
||||
|
||||
WifiHotspotMedium::~WifiHotspotMedium() {
|
||||
StopWifiHotspot();
|
||||
DisconnectWifiHotspot();
|
||||
@@ -393,14 +382,6 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
try {
|
||||
std::string ssid = GetStoredHotspotSsid();
|
||||
if (!ssid.empty()) {
|
||||
LOG(INFO) << "Before connecting to Hotspot, Delete the previous "
|
||||
"Hotspot profile with SSID: "
|
||||
<< ssid;
|
||||
wifi_hotspot_native_.DeleteWifiProfile(winrt::to_hstring(ssid).c_str());
|
||||
StoreHotspotSsid({});
|
||||
}
|
||||
if (IsConnected()) {
|
||||
LOG(WARNING) << "Already connected to Hotspot, disconnect first.";
|
||||
wifi_hotspot_native_.DisconnectWifiNetwork();
|
||||
@@ -510,7 +491,6 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
|
||||
LOG(INFO) << "Got IP address " << ip_address << " from hotspot.";
|
||||
|
||||
StoreHotspotSsid(hotspot_credentials->GetSSID());
|
||||
medium_status_ |= kMediumStatusConnected;
|
||||
LOG(INFO) << "Connected to hotspot: " << hotspot_credentials->GetSSID();
|
||||
|
||||
@@ -543,86 +523,11 @@ bool WifiHotspotMedium::DisconnectWifiHotspot() {
|
||||
}
|
||||
}
|
||||
|
||||
StoreHotspotSsid({});
|
||||
|
||||
medium_status_ &= (~kMediumStatusConnected);
|
||||
LOG(INFO) << __func__ << ": Disconnected to hotspot successfully.";
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiHotspotMedium::StoreHotspotSsid(std::string ssid) {
|
||||
std::unique_ptr<api::OutputFile> ssid_file;
|
||||
try {
|
||||
std::string file_name(kHotspotSsidFileName);
|
||||
std::string full_path =
|
||||
nearby::api::ImplementationPlatform::GetAppDataPath(file_name);
|
||||
ssid_file =
|
||||
nearby::api::ImplementationPlatform::CreateOutputFile(full_path);
|
||||
if (ssid_file == nullptr) {
|
||||
LOG(ERROR) << "Failed to create output file: " << file_name;
|
||||
return;
|
||||
}
|
||||
ByteArray data(ssid);
|
||||
ssid_file->Write(data);
|
||||
} catch (std::exception exception) {
|
||||
LOG(ERROR) << __func__ << ": Failed to store Hotspot SSID. Exception: "
|
||||
<< exception.what();
|
||||
} catch (const winrt::hresult_error& error) {
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Failed to store Hotspot SSID. WinRT exception: "
|
||||
<< error.code() << ": " << winrt::to_string(error.message());
|
||||
} catch (...) {
|
||||
LOG(ERROR) << __func__ << ": unknown error.";
|
||||
}
|
||||
if (ssid_file != nullptr) {
|
||||
ssid_file->Close();
|
||||
}
|
||||
}
|
||||
|
||||
std::string WifiHotspotMedium::GetStoredHotspotSsid() {
|
||||
std::unique_ptr<api::InputFile> ssid_file;
|
||||
try {
|
||||
std::string file_name(kHotspotSsidFileName);
|
||||
std::string full_path =
|
||||
nearby::api::ImplementationPlatform::GetAppDataPath(file_name);
|
||||
std::unique_ptr<api::InputFile> ssid_file =
|
||||
nearby::api::ImplementationPlatform::CreateInputFile(full_path, 0);
|
||||
if (ssid_file == nullptr) {
|
||||
LOG(ERROR) << "Failed to create input file: " << file_name;
|
||||
return {};
|
||||
}
|
||||
auto total_size = ssid_file->GetTotalSize();
|
||||
if (total_size == 0) {
|
||||
LOG(INFO) << __func__ << ": No Hotspot ssid found.";
|
||||
ssid_file->Close();
|
||||
return {};
|
||||
}
|
||||
|
||||
nearby::ExceptionOr<ByteArray> raw_ssid = ssid_file->Read(total_size);
|
||||
|
||||
if (!raw_ssid.ok()) {
|
||||
LOG(ERROR) << __func__ << ": Failed to read Hotspot ssid. Exception: "
|
||||
<< raw_ssid.exception();
|
||||
return {};
|
||||
}
|
||||
return std::string(raw_ssid.GetResult().data());
|
||||
} catch (std::exception exception) {
|
||||
LOG(ERROR) << __func__ << ": Failed to store Hotspot SSID. Exception: "
|
||||
<< exception.what();
|
||||
} catch (const winrt::hresult_error& error) {
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Failed to store Hotspot SSID. WinRT exception: "
|
||||
<< error.code() << ": " << winrt::to_string(error.message());
|
||||
} catch (...) {
|
||||
LOG(ERROR) << __func__ << ": unknown error.";
|
||||
}
|
||||
if (ssid_file != nullptr) {
|
||||
ssid_file->Close();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string WifiHotspotMedium::GetErrorMessage(std::exception_ptr eptr) {
|
||||
try {
|
||||
if (eptr) {
|
||||
|
||||
@@ -171,11 +171,6 @@ std::optional<std::wstring> WifiHotspotNative::GetConnectedProfileName() const {
|
||||
return GetConnectedProfileNameInternal();
|
||||
}
|
||||
|
||||
bool WifiHotspotNative::DeleteWifiProfile(const std::wstring& profile_name) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
return RemoveWlanProfile(profile_name);
|
||||
}
|
||||
|
||||
bool WifiHotspotNative::Scan(absl::string_view ssid) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ class WifiHotspotNative {
|
||||
|
||||
std::optional<std::wstring> GetConnectedProfileName() const
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool DeleteWifiProfile(const std::wstring& profile_name)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool Scan(absl::string_view ssid) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user