mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
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:
parent
2130eab9d9
commit
c65dff9229
@ -1025,6 +1025,7 @@ var WifiManager = (function() {
|
||||
|
||||
// Initial state
|
||||
manager.state = "UNINITIALIZED";
|
||||
manager.tetheringState = "UNINITIALIZED";
|
||||
manager.enabled = false;
|
||||
manager.supplicantStarted = false;
|
||||
manager.connectionInfo = { ssid: null, bssid: null, id: -1 };
|
||||
@ -1054,10 +1055,12 @@ var WifiManager = (function() {
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
manager.state = "INITIALIZING";
|
||||
// Kill any existing connections if necessary.
|
||||
getProperty("wifi.interface", "tiwlan0", function (ifname) {
|
||||
if (!ifname) {
|
||||
callback(-1);
|
||||
manager.state = "UNINITIALIZED";
|
||||
return;
|
||||
}
|
||||
manager.ifname = ifname;
|
||||
@ -1083,6 +1086,7 @@ var WifiManager = (function() {
|
||||
loadDriver(function (status) {
|
||||
if (status < 0) {
|
||||
callback(status);
|
||||
manager.state = "UNINITIALIZED";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1093,6 +1097,7 @@ var WifiManager = (function() {
|
||||
unloadDriver(function() {
|
||||
callback(status);
|
||||
});
|
||||
manager.state = "UNINITIALIZED";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1132,25 +1137,32 @@ var WifiManager = (function() {
|
||||
// Get wifi interface and load wifi driver when enable Ap mode.
|
||||
manager.setWifiApEnabled = function(enabled, callback) {
|
||||
if (enabled) {
|
||||
manager.tetheringState = "INITIALIZING";
|
||||
getProperty("wifi.interface", "tiwlan0", function (ifname) {
|
||||
if (!ifname) {
|
||||
callback(enabled);
|
||||
callback();
|
||||
manager.tetheringState = "UNINITIALIZED";
|
||||
return;
|
||||
}
|
||||
manager.ifname = ifname;
|
||||
loadDriver(function (status) {
|
||||
if (status < 0) {
|
||||
callback(enabled);
|
||||
callback();
|
||||
manager.tetheringState = "UNINITIALIZED";
|
||||
return;
|
||||
}
|
||||
|
||||
function doStartWifiTethering() {
|
||||
cancelWaitForDriverReadyTimer();
|
||||
WifiNetworkInterface.name = manager.ifname;
|
||||
manager.state = "WIFITETHERING";
|
||||
gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) {
|
||||
if (result) {
|
||||
manager.tetheringState = "UNINITIALIZED";
|
||||
} else {
|
||||
manager.tetheringState = "COMPLETED";
|
||||
}
|
||||
// Pop out current request.
|
||||
callback(enabled);
|
||||
callback();
|
||||
// Should we fire a dom event if we fail to set wifi tethering ?
|
||||
debug("Enable Wifi tethering result: " + (result ? result : "successfully"));
|
||||
});
|
||||
@ -1163,7 +1175,6 @@ var WifiManager = (function() {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
manager.state = "UNINITIALIZED";
|
||||
gNetworkManager.setWifiTethering(enabled, WifiNetworkInterface, function(result) {
|
||||
// Should we fire a dom event if we fail to set wifi tethering ?
|
||||
debug("Disable Wifi tethering result: " + (result ? result : "successfully"));
|
||||
@ -1172,7 +1183,8 @@ var WifiManager = (function() {
|
||||
if (status < 0) {
|
||||
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.
|
||||
} while (success &&
|
||||
this._stateRequests.length &&
|
||||
!("callback" in this._stateRequests[0]) &&
|
||||
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});
|
||||
},
|
||||
|
||||
@ -2797,17 +2810,12 @@ WifiWorker.prototype = {
|
||||
this.setWifiEnabled({enabled: false});
|
||||
},
|
||||
|
||||
nextRequest: function nextRequest(state) {
|
||||
nextRequest: function nextRequest() {
|
||||
if (this._stateRequests.length <= 0 ||
|
||||
!("callback" in this._stateRequests[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
this._stateRequests.shift();
|
||||
} while (this._stateRequests.length &&
|
||||
this._stateRequests[0].enabled === state);
|
||||
|
||||
this._stateRequests.shift();
|
||||
// Serve the pending requests.
|
||||
if (this._stateRequests.length > 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) {
|
||||
if (WifiManager.enabled === enabled) {
|
||||
return;
|
||||
}
|
||||
// Disable wifi tethering before enabling wifi.
|
||||
if (gNetworkManager.wifiTetheringEnabled) {
|
||||
this.setWifiEnabledInternal(false, function(data) {
|
||||
this.setWifiApEnabled(data, this.nextRequest.bind(this));
|
||||
// Make sure Wifi hotspot is idle before switching to Wifi mode.
|
||||
if (enabled && (gNetworkManager.wifiTetheringEnabled ||
|
||||
WifiManager.tetheringState != "UNINITIALIZED")) {
|
||||
this.queueRequest(false, function(data) {
|
||||
this.setWifiApEnabled(false, this.notifyTetheringOff.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});
|
||||
},
|
||||
@ -2843,22 +2857,15 @@ WifiWorker.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wifi is disabled
|
||||
if (!WifiManager.enabled) {
|
||||
this.setWifiEnabledInternal(enabled, function(data) {
|
||||
this.setWifiApEnabled(data, this.nextRequest.bind(this));
|
||||
}.bind(this));
|
||||
return;
|
||||
// Make sure Wifi is idle before switching to Wifi hotspot mode.
|
||||
if (enabled && (WifiManager.enabled ||
|
||||
WifiManager.state != "UNINITIALIZED")) {
|
||||
this.setWifiEnabled({enabled: false});
|
||||
}
|
||||
|
||||
// Wifi is enabled, turn off it before switching to Ap mode.
|
||||
if (enabled) {
|
||||
// Turn off wifi first.
|
||||
this.setWifiEnabled({enabled: false});
|
||||
this.setWifiEnabledInternal(enabled, (function (data) {
|
||||
this.setWifiApEnabled(data, this.nextRequest.bind(this));
|
||||
}).bind(this));
|
||||
}
|
||||
this.queueRequest(enabled, function(data) {
|
||||
this.setWifiApEnabled(data, this.nextRequest.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
// nsIObserver implementation
|
||||
|
Loading…
Reference in New Issue
Block a user