buffet: XmppChannel listens for connectivity changes
ShillClent provides notifications for network changes.
XmppChannel issue XMPP ping on every network change and restart if
failed. Only exception is soon scheduled upcoming reconnect.
BUG=brillo:1139
TEST=register device, disconnect network, wait device is offline in
GCD dashboard, connect network.
Dashboard should show device as online in less then 60 seconds.
Change-Id: I73dffc54400777b2325c26fb8aaf259b515174ce
Reviewed-on: https://chromium-review.googlesource.com/281413
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/privet/privet_manager.cc b/buffet/privet/privet_manager.cc
index 2f0dd37..bdea47a 100644
--- a/buffet/privet/privet_manager.cc
+++ b/buffet/privet/privet_manager.cc
@@ -63,6 +63,7 @@
void Manager::Start(const Options& options,
const scoped_refptr<dbus::Bus>& bus,
+ ShillClient* shill_client,
buffet::DeviceRegistrationInfo* device,
buffet::CommandManager* command_manager,
buffet::StateManager* state_manager,
@@ -75,15 +76,14 @@
security_.reset(new SecurityManager(device->GetConfig().pairing_modes(),
device->GetConfig().embedded_code_path(),
disable_security_));
- shill_client_.reset(new ShillClient(bus, options.device_whitelist));
- shill_client_->RegisterConnectivityListener(
+ shill_client->RegisterConnectivityListener(
base::Bind(&Manager::OnConnectivityChanged, base::Unretained(this)));
ap_manager_client_.reset(new ApManagerClient(bus));
if (device->GetConfig().wifi_auto_setup_enabled()) {
VLOG(1) << "Enabling WiFi bootstrapping.";
wifi_bootstrap_manager_.reset(new WifiBootstrapManager(
- device->GetConfig().last_configured_ssid(), shill_client_.get(),
+ device->GetConfig().last_configured_ssid(), shill_client,
ap_manager_client_.get(), cloud_.get()));
wifi_bootstrap_manager_->Init();
}
diff --git a/buffet/privet/privet_manager.h b/buffet/privet/privet_manager.h
index 72189c0..2af19d1 100644
--- a/buffet/privet/privet_manager.h
+++ b/buffet/privet/privet_manager.h
@@ -52,7 +52,6 @@
bool disable_privet{false};
bool disable_security{false};
bool enable_ping{false};
- std::set<std::string> device_whitelist;
base::FilePath config_path;
};
@@ -61,6 +60,7 @@
void Start(const Options& options,
const scoped_refptr<dbus::Bus>& bus,
+ ShillClient* shill_client,
buffet::DeviceRegistrationInfo* device,
buffet::CommandManager* command_manager,
buffet::StateManager* state_manager,
@@ -101,7 +101,6 @@
std::unique_ptr<CloudDelegate> cloud_;
std::unique_ptr<DeviceDelegate> device_;
std::unique_ptr<SecurityManager> security_;
- std::unique_ptr<ShillClient> shill_client_;
std::unique_ptr<ApManagerClient> ap_manager_client_;
std::unique_ptr<WifiBootstrapManager> wifi_bootstrap_manager_;
std::unique_ptr<PeerdClient> peerd_client_;
diff --git a/buffet/privet/shill_client.cc b/buffet/privet/shill_client.cc
index 0a1b2e2..48d0cef 100644
--- a/buffet/privet/shill_client.cc
+++ b/buffet/privet/shill_client.cc
@@ -464,19 +464,20 @@
new_connectivity_state = kv.second.service_state;
}
}
- VLOG(3) << "New connectivity state is "
+ VLOG(1) << "Connectivity changed: "
+ << ServiceStateToString(connectivity_state_) << " -> "
<< ServiceStateToString(new_connectivity_state);
- if (new_connectivity_state != connectivity_state_) {
- connectivity_state_ = new_connectivity_state;
- // We may call UpdateConnectivityState whenever we mutate a data structure
- // such that our connectivity status could change. However, we don't want
- // to allow people to call into ShillClient while some other operation is
- // underway. Therefore, call our callbacks later, when we're in a good
- // state.
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(&ShillClient::NotifyConnectivityListeners,
- weak_factory_.GetWeakPtr(), AmOnline()));
- }
+ // Notify listeners even if state changed to the same value. Listeners may
+ // want to handle this event.
+ connectivity_state_ = new_connectivity_state;
+ // We may call UpdateConnectivityState whenever we mutate a data structure
+ // such that our connectivity status could change. However, we don't want
+ // to allow people to call into ShillClient while some other operation is
+ // underway. Therefore, call our callbacks later, when we're in a good
+ // state.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ShillClient::NotifyConnectivityListeners,
+ weak_factory_.GetWeakPtr(), AmOnline()));
}
void ShillClient::NotifyConnectivityListeners(bool am_online) {