Bug 811833 - [System] When the device is woken from sleep, wifi does not automatically connect to the network. r=mrbkap
authorVincent Chang <vchang@mozilla.com>
Wed, 21 Nov 2012 16:19:08 +0800
changeset 114073 85c1a0de5374a3a60526275d09baaf2d6861f89a
parent 114072 5493ee135368050c2a80ff4a262a0b1f0aebaf65
child 114074 a765d833483a297e26e1f1f2a85042e15be4f91e
push id23901
push userryanvm@gmail.com
push dateFri, 23 Nov 2012 21:11:03 +0000
treeherdermozilla-central@0d373cf880fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs811833
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 811833 - [System] When the device is woken from sleep, wifi does not automatically connect to the network. r=mrbkap
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1723,17 +1723,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")
@@ -1763,21 +1769,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") {