зеркало из https://github.com/mozilla/gecko-dev.git
Bug 792952, B2G wifi scanning js. r=mrbkap
--HG-- extra : rebase_source : e05fffbf5344ad59cafe2293dd463ee963f90580
This commit is contained in:
Родитель
7e76c64120
Коммит
068ee6378f
|
@ -1369,6 +1369,7 @@ let WifiNetworkInterface = {
|
|||
|
||||
};
|
||||
|
||||
function WifiScanResult() {}
|
||||
|
||||
// TODO Make the difference between a DOM-based network object and our
|
||||
// networks objects much clearer.
|
||||
|
@ -2102,6 +2103,79 @@ WifiWorker.prototype = {
|
|||
}).bind(this));
|
||||
},
|
||||
|
||||
getWifiScanResults: function(callback) {
|
||||
var count = 0;
|
||||
var timer = null;
|
||||
var self = this;
|
||||
|
||||
self.waitForScan(waitForScanCallback);
|
||||
doScan();
|
||||
function doScan() {
|
||||
WifiManager.scan(true, function (ok) {
|
||||
if (!ok) {
|
||||
if (!timer) {
|
||||
count = 0;
|
||||
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
}
|
||||
|
||||
if (count++ >= 3) {
|
||||
timer = null;
|
||||
this.wantScanResults.splice(this.wantScanResults.indexOf(waitForScanCallback), 1);
|
||||
callback.onfailure();
|
||||
return;
|
||||
}
|
||||
|
||||
// Else it's still running, continue waiting.
|
||||
timer.initWithCallback(doScan, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function waitForScanCallback(networks) {
|
||||
if (networks === null) {
|
||||
callback.onfailure();
|
||||
return;
|
||||
}
|
||||
|
||||
var wifiScanResults = new Array();
|
||||
var net;
|
||||
for (let net in networks) {
|
||||
let value = networks[net];
|
||||
wifiScanResults.push(transformResult(value));
|
||||
}
|
||||
callback.onready(wifiScanResults.length, wifiScanResults);
|
||||
}
|
||||
|
||||
function transformResult(element) {
|
||||
var result = new WifiScanResult();
|
||||
result.connected = false;
|
||||
for (let id in element) {
|
||||
if (id === "__exposedProps__") {
|
||||
continue;
|
||||
}
|
||||
if (id === "capabilities") {
|
||||
result[id] = 0;
|
||||
var capabilities = element[id];
|
||||
for (let j = 0; j < capabilities.length; j++) {
|
||||
if (capabilities[j] === "WPA-PSK") {
|
||||
result[id] |= Ci.nsIWifiScanResult.WPA_PSK;
|
||||
} else if (capabilities[j] === "WPA-EAP") {
|
||||
result[id] |= Ci.nsIWifiScanResult.WPA_EAP;
|
||||
} else if (capabilities[j] === "WEP") {
|
||||
result[id] |= Ci.nsIWifiScanResult.WEP;
|
||||
} else {
|
||||
result[id] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result[id] = element[id];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
},
|
||||
|
||||
getKnownNetworks: function(msg) {
|
||||
const message = "WifiManager:getKnownNetworks:Return";
|
||||
if (!WifiManager.enabled) {
|
||||
|
|
|
@ -8,13 +8,55 @@
|
|||
|
||||
interface nsIVariant;
|
||||
|
||||
[scriptable, uuid(335ff8a0-fb18-11e1-a21f-0800200c9a66)]
|
||||
[scriptable, uuid(cf1ac02b-1f39-446e-815b-651ac78d2233)]
|
||||
interface nsIWifiScanResult : nsISupports {
|
||||
readonly attribute DOMString ssid;
|
||||
readonly attribute DOMString bssid;
|
||||
|
||||
const int32_t WPA_PSK = 0x01;
|
||||
const int32_t WPA_EAP = 0x02;
|
||||
const int32_t WEP = 0x04;
|
||||
readonly attribute uint32_t capabilities;
|
||||
|
||||
/**
|
||||
* Strength of the signal to network.
|
||||
*/
|
||||
readonly attribute uint32_t signalStrength;
|
||||
|
||||
readonly attribute uint32_t relSignalStrength;
|
||||
readonly attribute boolean connected;
|
||||
};
|
||||
|
||||
[scriptable, uuid(a6931ebf-8493-4014-90e2-99f406999982)]
|
||||
interface nsIWifiScanResultsReady : nsISupports {
|
||||
|
||||
/**
|
||||
* Callback with list of networks.
|
||||
*/
|
||||
void onready(in uint32_t count, [array, size_is(count)] in nsIWifiScanResult results);
|
||||
|
||||
/**
|
||||
* Callback if scanning for networks failed after 3 retry attempts.
|
||||
*/
|
||||
void onfailure();
|
||||
};
|
||||
|
||||
[scriptable, uuid(08dfefed-5c5d-4468-8c5d-2c65c24692d9)]
|
||||
interface nsIWifi : nsISupports
|
||||
{
|
||||
/**
|
||||
* Shutdown the wifi system.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Returns the list of currently available networks as well as the list of
|
||||
* currently configured networks.
|
||||
*
|
||||
* On success a callback is notified with the list of networks.
|
||||
* On failure after 3 scan retry attempts a callback is notified of failure.
|
||||
*/
|
||||
void getWifiScanResults(in nsIWifiScanResultsReady callback);
|
||||
};
|
||||
|
||||
[scriptable, uuid(caa76ee3-8ffe-4ea5-bc59-3b53a9df0d07)]
|
||||
|
|
Загрузка…
Ссылка в новой задаче