Don't pass wifi pointer into libWeave if interface is not available

BUG: 24111116
Change-Id: I4f3f54348574c63656904d34928ff90bc93823ec
Reviewed-on: https://weave-review.googlesource.com/1116
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc
index b0b7f14..c6450b4 100644
--- a/libweave/examples/ubuntu/main.cc
+++ b/libweave/examples/ubuntu/main.cc
@@ -47,8 +47,11 @@
   opts.disable_privet = false;
   opts.disable_security = false;
   opts.enable_ping = true;
-  device->Start(opts, &config_store, &task_runner, &http_client, &network,
-                &mdns, &http_server, &network, &bluetooth);
+  device->Start(
+      opts, &config_store, &task_runner, &http_client, &network, &mdns,
+      &http_server,
+      weave::examples::NetworkImpl::HasWifiCapability() ? &network : nullptr,
+      &bluetooth);
 
   task_runner.Run();
 
diff --git a/libweave/examples/ubuntu/network_manager.cc b/libweave/examples/ubuntu/network_manager.cc
index 2414d7d..56e9544 100644
--- a/libweave/examples/ubuntu/network_manager.cc
+++ b/libweave/examples/ubuntu/network_manager.cc
@@ -200,6 +200,10 @@
   hostapd_started_ = false;
 }
 
+bool NetworkImpl::HasWifiCapability() {
+  return std::system("nmcli dev | grep ^wlan0") == 0;
+}
+
 void NetworkImpl::OpenSslSocket(
     const std::string& host,
     uint16_t port,
diff --git a/libweave/examples/ubuntu/network_manager.h b/libweave/examples/ubuntu/network_manager.h
index c7f2480..4e1b6bd 100644
--- a/libweave/examples/ubuntu/network_manager.h
+++ b/libweave/examples/ubuntu/network_manager.h
@@ -45,6 +45,8 @@
   void EnableAccessPoint(const std::string& ssid) override;
   void DisableAccessPoint() override;
 
+  static bool HasWifiCapability();
+
  private:
   void TryToConnect(const std::string& ssid,
                     const std::string& passphrase,