Bug 784733 - Implementation of wifi power saving mode api interface. r=mrbkap

This commit is contained in:
Vincent Chang 2012-09-24 17:05:47 +08:00
Родитель 1b2e358fc6
Коммит ca01bac3e5
2 изменённых файлов: 45 добавлений и 1 удалений

Просмотреть файл

@ -78,6 +78,7 @@ DOMWifiManager.prototype = {
"WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
"WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
"WifiManager:wps:Return:OK", "WifiManager:wps:Return:NO",
"WifiManager:setPowerSavingMode:Return:OK", "WifiManager:setPowerSavingMode:Return:NO",
"WifiManager:wifiDown", "WifiManager:wifiUp",
"WifiManager:onconnecting", "WifiManager:onassociate",
"WifiManager:onconnect", "WifiManager:ondisconnect",
@ -164,6 +165,16 @@ DOMWifiManager.prototype = {
Services.DOMRequest.fireError(request, msg.data);
break;
case "WifiManager:setPowerSavingMode:Return:OK":
request = this.takeRequest(msg.rid);
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
break;
case "WifiManager:setPowerSavingMode:Return:NO":
request = this.takeRequest(msg.rid);
Services.DOMRequest.fireError(request, msg.data);
break;
case "WifiManager:wifiDown":
this._enabled = false;
this._currentNetwork = null;
@ -302,6 +313,14 @@ DOMWifiManager.prototype = {
return request;
},
setPowerSavingMode: function nsIDOMWifiManager_setPowerSavingMode(enabled) {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
var request = this.createRequest();
this._sendMessageForRequest("WifiManager:setPowerSavingMode", enabled, request);
return request;
},
get enabled() {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);

Просмотреть файл

@ -404,7 +404,7 @@ var WifiManager = (function() {
}
function setPowerModeCommand(mode, callback) {
doBooleanCommand("DRIVER POWERMODE " + mode, "OK", callback);
doBooleanCommand("DRIVER POWERMODE " + (mode === "AUTO" ? 0 : 1), "OK", callback);
}
function getPowerModeCommand(callback) {
@ -1174,6 +1174,8 @@ var WifiManager = (function() {
manager.wpsPbc = wpsPbcCommand;
manager.wpsPin = wpsPinCommand;
manager.wpsCancel = wpsCancelCommand;
manager.setPowerMode = setPowerModeCommand;
manager.setSuspendOptimizations = setSuspendOptimizationsCommand;
manager.getRssiApprox = getRssiApproxCommand;
manager.getLinkSpeed = getLinkSpeedCommand;
manager.getDhcpInfo = function() { return dhcpInfo; }
@ -1370,6 +1372,7 @@ function WifiWorker() {
const messages = ["WifiManager:getNetworks",
"WifiManager:associate", "WifiManager:forget",
"WifiManager:wps", "WifiManager:getState",
"WifiManager:setPowerSavingMode",
"WifiManager:managerFinished"];
messages.forEach((function(msgName) {
@ -1982,6 +1985,9 @@ WifiWorker.prototype = {
case "WifiManager:wps":
this.wps(msg);
break;
case "WifiManager:setPowerSavingMode":
this.setPowerSavingMode(msg);
break;
case "WifiManager:getState": {
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
let i;
@ -2267,6 +2273,25 @@ WifiWorker.prototype = {
}
},
setPowerSavingMode: function(msg) {
const message = "WifiManager:setPowerSavingMode:Return";
let self = this;
let enabled = msg.data;
let mode = enabled ? "AUTO" : "ACTIVE";
// Some wifi drivers may not implement this command. Set power mode
// even if suspend optimization command failed.
WifiManager.setSuspendOptimizations(enabled, function(ok) {
WifiManager.setPowerMode(mode, function(ok) {
if (ok) {
self._sendMessage(message, true, true, msg);
} else {
self._sendMessage(message, false, "Set power saving mode failed", msg);
}
});
});
},
// This is a bit ugly, but works. In particular, this depends on the fact
// that RadioManager never actually tries to get the worker from us.
get worker() { throw "Not implemented"; },