Bug 831716 - [Settings] [Internet sharing][wifi] Tapping Wi-fi hotspot/wifi ON disable Wi-fi connection forever. r=mrbkap, dflanagan

This commit is contained in:
Vincent Chang 2013-01-17 20:26:17 +08:00
parent 82a535ec6d
commit 168204983c

View File

@ -1025,6 +1025,7 @@ var WifiManager = (function() {
// Initial state // Initial state
manager.state = "UNINITIALIZED"; manager.state = "UNINITIALIZED";
manager.tetheringState = "UNINITIALIZED";
manager.enabled = false; manager.enabled = false;
manager.supplicantStarted = false; manager.supplicantStarted = false;
manager.connectionInfo = { ssid: null, bssid: null, id: -1 }; manager.connectionInfo = { ssid: null, bssid: null, id: -1 };
@ -1054,10 +1055,12 @@ var WifiManager = (function() {
} }
if (enable) { if (enable) {
manager.state = "INITIALIZING";
// Kill any existing connections if necessary. // Kill any existing connections if necessary.
getProperty("wifi.interface", "tiwlan0", function (ifname) { getProperty("wifi.interface", "tiwlan0", function (ifname) {
if (!ifname) { if (!ifname) {
callback(-1); callback(-1);
manager.state = "UNINITIALIZED";
return; return;
} }
manager.ifname = ifname; manager.ifname = ifname;
@ -1083,6 +1086,7 @@ var WifiManager = (function() {
loadDriver(function (status) { loadDriver(function (status) {
if (status < 0) { if (status < 0) {
callback(status); callback(status);
manager.state = "UNINITIALIZED";
return; return;
} }
@ -1093,6 +1097,7 @@ var WifiManager = (function() {
unloadDriver(function() { unloadDriver(function() {
callback(status); callback(status);
}); });
manager.state = "UNINITIALIZED";
return; return;
} }
@ -1132,25 +1137,32 @@ var WifiManager = (function() {
// Get wifi interface and load wifi driver when enable Ap mode. // Get wifi interface and load wifi driver when enable Ap mode.
manager.setWifiApEnabled = function(enabled, callback) { manager.setWifiApEnabled = function(enabled, callback) {
if (enabled) { if (enabled) {
manager.tetheringState = "INITIALIZING";
getProperty("wifi.interface", "tiwlan0", function (ifname) { getProperty("wifi.interface", "tiwlan0", function (ifname) {
if (!ifname) { if (!ifname) {
callback(enabled); callback();
manager.tetheringState = "UNINITIALIZED";
return; return;
} }
manager.ifname = ifname; manager.ifname = ifname;
loadDriver(function (status) { loadDriver(function (status) {
if (status < 0) { if (status < 0) {
callback(enabled); callback();
manager.tetheringState = "UNINITIALIZED";
return; return;
} }
function doStartWifiTethering() { function doStartWifiTethering() {
cancelWaitForDriverReadyTimer(); cancelWaitForDriverReadyTimer();
WifiNetworkInterface.name = manager.ifname; WifiNetworkInterface.name = manager.ifname;
manager.state = "WIFITETHERING";
gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) { gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) {
if (result) {
manager.tetheringState = "UNINITIALIZED";
} else {
manager.tetheringState = "COMPLETED";
}
// Pop out current request. // Pop out current request.
callback(enabled); callback();
// Should we fire a dom event if we fail to set wifi tethering ? // Should we fire a dom event if we fail to set wifi tethering ?
debug("Enable Wifi tethering result: " + (result ? result : "successfully")); debug("Enable Wifi tethering result: " + (result ? result : "successfully"));
}); });
@ -1163,7 +1175,6 @@ var WifiManager = (function() {
}); });
}); });
} else { } else {
manager.state = "UNINITIALIZED";
gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) { gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) {
// Should we fire a dom event if we fail to set wifi tethering ? // Should we fire a dom event if we fail to set wifi tethering ?
debug("Disable Wifi tethering result: " + (result ? result : "successfully")); debug("Disable Wifi tethering result: " + (result ? result : "successfully"));
@ -1172,7 +1183,8 @@ var WifiManager = (function() {
if (status < 0) { if (status < 0) {
debug("Fail to unload wifi driver"); debug("Fail to unload wifi driver");
} }
callback(enabled); manager.tetheringState = "UNINITIALIZED";
callback();
}); });
}); });
} }
@ -2559,6 +2571,7 @@ WifiWorker.prototype = {
// Don't remove more than one request if the previous one failed. // Don't remove more than one request if the previous one failed.
} while (success && } while (success &&
this._stateRequests.length && this._stateRequests.length &&
!("callback" in this._stateRequests[0]) &&
this._stateRequests[0].enabled === state); this._stateRequests[0].enabled === state);
} }
@ -2615,7 +2628,7 @@ WifiWorker.prototype = {
} }
}, },
setWifiEnabledInternal: function(enabled, callback) { queueRequest: function(enabled, callback) {
this.setWifiEnabled({enabled: enabled, callback: callback}); this.setWifiEnabled({enabled: enabled, callback: callback});
}, },
@ -2797,17 +2810,12 @@ WifiWorker.prototype = {
this.setWifiEnabled({enabled: false}); this.setWifiEnabled({enabled: false});
}, },
nextRequest: function nextRequest(state) { nextRequest: function nextRequest() {
if (this._stateRequests.length <= 0 || if (this._stateRequests.length <= 0 ||
!("callback" in this._stateRequests[0])) { !("callback" in this._stateRequests[0])) {
return; return;
} }
this._stateRequests.shift();
do {
this._stateRequests.shift();
} while (this._stateRequests.length &&
this._stateRequests[0].enabled === state);
// Serve the pending requests. // Serve the pending requests.
if (this._stateRequests.length > 0) { if (this._stateRequests.length > 0) {
if ("callback" in this._stateRequests[0]) { if ("callback" in this._stateRequests[0]) {
@ -2820,20 +2828,26 @@ WifiWorker.prototype = {
} }
}, },
notifyTetheringOff: function notifyTetheringOff() {
// It's really sad that we don't have an API to notify the wifi
// hotspot status. Toggle settings to let gaia know that wifi hotspot
// is disabled.
gSettingsService.createLock().set(
"tethering.wifi.enabled", false, null, "fromInternalSetting");
// Check for the next request.
this.nextRequest();
},
handleWifiEnabled: function(enabled) { handleWifiEnabled: function(enabled) {
if (WifiManager.enabled === enabled) { if (WifiManager.enabled === enabled) {
return; return;
} }
// Disable wifi tethering before enabling wifi. // Make sure Wifi hotspot is idle before switching to Wifi mode.
if (gNetworkManager.wifiTetheringEnabled) { if (enabled && (gNetworkManager.wifiTetheringEnabled ||
this.setWifiEnabledInternal(false, function(data) { WifiManager.tetheringState != "UNINITIALIZED")) {
this.setWifiApEnabled(data, this.nextRequest.bind(this)); this.queueRequest(false, function(data) {
this.setWifiApEnabled(false, this.notifyTetheringOff.bind(this));
}.bind(this)); }.bind(this));
// It's really sad that we don't have an API to notify the wifi
// hotspot status. Toggle settings to let gaia know that wifi hotspot
// is disalbed.
gSettingsService.createLock().set(
"tethering.wifi.enabled", false, null, "fromInternalSetting");
} }
this.setWifiEnabled({enabled: enabled}); this.setWifiEnabled({enabled: enabled});
}, },
@ -2843,22 +2857,15 @@ WifiWorker.prototype = {
return; return;
} }
// Wifi is disabled // Make sure Wifi is idle before switching to Wifi hotspot mode.
if (!WifiManager.enabled) { if (enabled && (WifiManager.enabled ||
this.setWifiEnabledInternal(enabled, function(data) { WifiManager.state != "UNINITIALIZED")) {
this.setWifiApEnabled(data, this.nextRequest.bind(this)); this.setWifiEnabled({enabled: false});
}.bind(this));
return;
} }
// Wifi is enabled, turn off it before switching to Ap mode. this.queueRequest(enabled, function(data) {
if (enabled) { this.setWifiApEnabled(data, this.nextRequest.bind(this));
// Turn off wifi first. }.bind(this));
this.setWifiEnabled({enabled: false});
this.setWifiEnabledInternal(enabled, (function (data) {
this.setWifiApEnabled(data, this.nextRequest.bind(this));
}).bind(this));
}
}, },
// nsIObserver implementation // nsIObserver implementation