Bug 811833 - [System] When the device is woken from sleep, wifi does not automatically connect to the network. r=mrbkap, a=blocking-basecamp
authorVincent Chang <vchang@mozilla.com>
Wed, 21 Nov 2012 16:19:08 +0800
changeset 118398 06329b9181848f7bb549482e5067433764b39321
parent 118397 6d1876f4b34fb1b0ee3af93a77e4cb8c2c105a73
child 118399 4e0a8f234a6dc4981efa67ada3f038d3645de0e5
push id2766
push userryanvm@gmail.com
push dateFri, 23 Nov 2012 21:25:42 +0000
treeherdermozilla-aurora@4e0a8f234a6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, blocking-basecamp
bugs811833
milestone19.0a2
Bug 811833 - [System] When the device is woken from sleep, wifi does not automatically connect to the network. r=mrbkap, a=blocking-basecamp
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1718,17 +1718,23 @@ function WifiWorker() {
       self.macAddress = mac;
       debug("Got mac: " + mac);
     });
 
     self._reloadConfiguredNetworks(function(ok) {
       // Prime this.networks.
       if (!ok)
         return;
+
       self.waitForScan(function firstScan() {});
+      // The select network command we used in associate() disables others networks.
+      // Enable them here to make sure wpa_supplicant helps to connect to known
+      // network automatically.
+      self._enableAllNetworks();
+      WifiManager.saveConfig(function() {})
     });
 
     // Check if we need to dequeue requests first.
     self._notifyAfterStateChange(true, true);
 
     // Notify everybody, even if they didn't ask us to come up.
     self._fireEvent("wifiUp", {});
     if (WifiManager.state === "SCANNING")
@@ -1758,21 +1764,32 @@ function WifiWorker() {
     self._notifyAfterStateChange(false, false);
   };
 
   WifiManager.onpasswordmaybeincorrect = function() {
     WifiManager.authenticationFailuresCount++;
   };
 
   WifiManager.ondisconnected = function() {
+    // We may fail to establish the connection, re-enable the
+    // rest of our networks.
+    if (self._needToEnableNetworks) {
+      self._enableAllNetworks();
+      self._needToEnableNetworks = false;
+    }
+
     var currentNetwork = self.currentNetwork;
-    if (currentNetwork) {
+    if (currentNetwork && !isNaN(currentNetwork.netId)) {
+      // Disable the network when password is incorrect.
       WifiManager.disableNetwork(currentNetwork.netId, function() {});
-      self._fireEvent("onconnectingfailed", {network: currentNetwork});
+    } else {
+      // TODO: We can't get netId when connecting to wep network with
+      // incorrect password, see Bug 813880
     }
+    self._fireEvent("onconnectingfailed", {network: currentNetwork});
   };
 
   WifiManager.onstatechange = function() {
     debug("State change: " + this.prevState + " -> " + this.state);
 
     if (self._connectionInfoTimer &&
         this.state !== "CONNECTED" &&
         this.state !== "COMPLETED") {