diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-02-29 21:06:32 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-29 21:06:32 +0000 |
commit | 7be8a4e415a0580fb2fbe3030facacd91a4c91c4 (patch) | |
tree | 6d6ef283876b5ab2560d11d7e58a792b19aee221 | |
parent | 7fec91c0b6b4cf8ba2926d6ba1a42f75aa4a8e4f (diff) | |
parent | 20f03a2966652cf76ea2e7449cebaedb6b457acc (diff) | |
download | weaved-7be8a4e415a0580fb2fbe3030facacd91a4c91c4.tar.gz |
Implement provider::Wifi::GetConnectedSsid()
am: 20f03a2966
* commit '20f03a2966652cf76ea2e7449cebaedb6b457acc':
Implement provider::Wifi::GetConnectedSsid()
-rw-r--r-- | buffet/shill_client.cc | 22 | ||||
-rw-r--r-- | buffet/shill_client.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/buffet/shill_client.cc b/buffet/shill_client.cc index 5649762..8e6e1e9 100644 --- a/buffet/shill_client.cc +++ b/buffet/shill_client.cc @@ -18,6 +18,7 @@ #include <base/message_loop/message_loop.h> #include <base/stl_util.h> +#include <base/strings/string_number_conversions.h> #include <brillo/any.h> #include <brillo/errors/error.h> #include <brillo/variant_dictionary.h> @@ -215,6 +216,27 @@ void ShillClient::StopAccessPoint() { ap_manager_client_->Stop(); } +std::string ShillClient::GetConnectedSsid() const { + for (const auto& kv : devices_) { + VariantDictionary properties; + if (!kv.second.selected_service->GetProperties(&properties, nullptr)) + continue; + + auto property_it = properties.find(shill::kWifiHexSsid); + if (property_it == properties.end()) continue; + + string ssid_hex = property_it->second.TryGet<string>(); + if (ssid_hex.empty()) continue; + + std::vector<uint8_t> data; + if (!base::HexStringToBytes(ssid_hex, &data) || data.empty()) continue; + + return std::string(data.begin(), data.end()); + } + + return ""; +} + void ShillClient::AddConnectionChangedCallback( const ConnectionChangedCallback& listener) { connectivity_listeners_.push_back(listener); diff --git a/buffet/shill_client.h b/buffet/shill_client.h index 517cd91..63cdd98 100644 --- a/buffet/shill_client.h +++ b/buffet/shill_client.h @@ -58,6 +58,7 @@ class ShillClient final : public weave::provider::Network, void StopAccessPoint() override; bool IsWifi24Supported() const override { return is_24_supported_; } bool IsWifi50Supported() const override { return is_50_supported_; } + std::string GetConnectedSsid() const; private: struct DeviceState { |