Don't add the Mozilla networks if they already exist

RESOLVED FIXED

Status

()

Core
DOM: Device Interfaces
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: mrbkap, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
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.
Attachment #600923 - Flags: review?(gal)
(Reporter)

Updated

6 years ago
Attachment #600923 - Flags: review?(gal) → review?(21)
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.
Attachment #600923 - Flags: review?(21) → review+
(Reporter)

Comment 2

6 years ago
This landed yesterday with bug 732982.
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.