Last Comment Bug 730830 - Don't add the Mozilla networks if they already exist
: Don't add the Mozilla networks if they already exist
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: DOM: Device Interfaces (show other bugs)
: unspecified
: ARM Android
: -- normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on:
Blocks: b2g-wifi
  Show dependency treegraph
 
Reported: 2012-02-27 08:30 PST by Blake Kaplan (:mrbkap)
Modified: 2012-03-15 05:27 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
patch (2.18 KB, patch)
2012-02-27 08:30 PST, Blake Kaplan (:mrbkap)
21: review+
Details | Diff | Splinter Review

Description Blake Kaplan (:mrbkap) 2012-02-27 08:30:00 PST
Created attachment 600923 [details] [diff] [review]
patch

Right now, we'll add the hacked mozilla networks, even if there's already an entry for them, we should avoid doing so.

Of note here is a fix to getNetworkConfiguration where the change from var -> let means that each closure created inside the loop gets its own fieldName.
Comment 1 Vivien Nicolas (:vingtetun) (:21) - (NOT reading bugmails, needinfo? please) 2012-03-08 02:20:14 PST
Comment on attachment 600923 [details] [diff] [review]
patch

>diff --git a/dom/wifi/nsWifiWorker.js b/dom/wifi/nsWifiWorker.js
>@@ -861,6 +861,13 @@ var WifiManager = (function() {
>       var done = 0;
>       var errors = 0;
>       var lines = reply.split("\n");
>+      if (lines.length === 1) {
>+        // We need to make sure we call the callback even if there are no
>+        // configured networks.
>+        callback(networks);
>+        return;
>+      }

nit: maybe you can return before declaring the done and errors variables

>@@ -986,7 +993,33 @@ function nsWifiWorker() {
>         WifiManager.scan(false, function(){});
>       });
>     }
>-    addThem();
>+
>+    WifiManager.getConfiguredNetworks(function(networks) {
>+      if (!networks) {
>+        debug("Unable to get existing networks");
>+        return;
>+      }
>+
>+      // O(n*m) but this is all temporary, right?
>+      // We enable any of our networks that area already configured but
>+      // disabled and avoid re-adding them if they exist.
>+      for each (let net in networks) {
>+        if (!net.ssid)
>+          continue;
>+        for (let known = 0; known < configs.length; ++known) {
>+          if (configs[known].ssid !== net.ssid)
>+            continue;
>+
>+          configs.splice(known, 1);
>+          if (net.status === "DISABLED")
>+            WifiManager.enableNetwork(net.netId, false, function() {});
>+          break;
>+        }
>+      }
>+
>+      if (configs.length > 0)
>+        addThem();
>+    });

This is not really elegant but this has been removed into another bug, right?

r+ with the small nit and a bug number for this part of the code that will/has been removed elsewhere.
Comment 2 Blake Kaplan (:mrbkap) 2012-03-15 05:27:00 PDT
This landed yesterday with bug 732982.

Note You need to log in before you can comment on or make changes to this bug.