wifi: do not send random MAC request until supplicant appears am: c65e95eb77
am: 197d69b1cd

Change-Id: If3ab1ec7b3fdd31495da1727216b4db8796fe95b
diff --git a/wifi/wifi.cc b/wifi/wifi.cc
index a8577f5..9bcda61 100644
--- a/wifi/wifi.cc
+++ b/wifi/wifi.cc
@@ -762,6 +762,11 @@
 }
 
 bool WiFi::SetRandomMACEnabled(const bool& enabled, Error* error) {
+  if (!supplicant_present_ || !supplicant_interface_proxy_.get()) {
+    SLOG(this, 2) << "Ignoring random MAC while supplicant is not present.";
+    return false;
+  }
+
   if (!random_mac_supported_) {
     Error::PopulateAndLog(FROM_HERE, error, Error::kNotSupported,
             "This WiFi device does not support MAC address randomization");
@@ -2329,6 +2334,13 @@
                << "May be running an older version of wpa_supplicant.";
   }
 
+  if (random_mac_enabled_ &&
+      !supplicant_interface_proxy_->EnableMACAddressRandomization(
+           kRandomMACMask)) {
+    LOG(ERROR) << "Failed to enable MAC address randomization. "
+               << "May be running an older version of wpa_supplicant.";
+  }
+
   Scan(kFullScan, nullptr, __func__);
   StartScanTimer();
 }