Bug 743941 - Some small fixes to state tracking. Also move some logic out of the manager. r=cjones

This commit is contained in:
Blake Kaplan 2012-04-09 12:13:28 +08:00
Родитель dfd38c0284
Коммит a24bc13e06
1 изменённых файлов: 36 добавлений и 23 удалений

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

@ -443,8 +443,7 @@ var WifiManager = (function() {
function stopDhcp(ifname, callback) { function stopDhcp(ifname, callback) {
controlMessage({ cmd: "dhcp_stop", ifname: ifname }, function(data) { controlMessage({ cmd: "dhcp_stop", ifname: ifname }, function(data) {
if (!data.status) dhcpInfo = null;
dhcpInfo = null;
notify("dhcplost"); notify("dhcplost");
callback(!data.status); callback(!data.status);
}); });
@ -452,8 +451,7 @@ var WifiManager = (function() {
function releaseDhcpLease(ifname, callback) { function releaseDhcpLease(ifname, callback) {
controlMessage({ cmd: "dhcp_release_lease", ifname: ifname }, function(data) { controlMessage({ cmd: "dhcp_release_lease", ifname: ifname }, function(data) {
if (!data.status) dhcpInfo = null;
dhcpInfo = null;
notify("dhcplost"); notify("dhcplost");
callback(!data.status); callback(!data.status);
}); });
@ -499,11 +497,6 @@ var WifiManager = (function() {
fields.prevState = manager.state; fields.prevState = manager.state;
manager.state = fields.state; manager.state = fields.state;
// If we got disconnected, kill the DHCP client in preparation for
// reconnection.
if (fields.state === "DISCONNECTED" && dhcpInfo)
stopDhcp(manager.ifname, function() {});
notify("statechange", fields); notify("statechange", fields);
} }
@ -580,6 +573,16 @@ var WifiManager = (function() {
notify("supplicantlost"); notify("supplicantlost");
} }
manager.connectionDropped = function(callback) {
// If we got disconnected, kill the DHCP client in preparation for
// reconnection.
resetConnections(manager.ifname, function() {
stopDhcp(manager.ifname, function() {
callback();
});
});
}
manager.start = function() { manager.start = function() {
debug("detected SDK version " + sdkVersion); debug("detected SDK version " + sdkVersion);
@ -722,9 +725,9 @@ var WifiManager = (function() {
return false; return false;
} }
if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) { if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) {
notifyStateChange({ state: "DISCONNECTED" });
manager.connectionInfo.bssid = null; manager.connectionInfo.bssid = null;
manager.connectionInfo.ssid = null; manager.connectionInfo.ssid = null;
manager.connectionInfo.id = -1;
return true; return true;
} }
if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) { if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) {
@ -869,11 +872,13 @@ var WifiManager = (function() {
// supplicant gracefully, then we need to continue telling it to die // supplicant gracefully, then we need to continue telling it to die
// until it does. // until it does.
terminateSupplicant(function (ok) { terminateSupplicant(function (ok) {
stopSupplicant(function (status) { manager.connectionDropped(function () {
manager.state = "UNINITIALIZED"; stopSupplicant(function (status) {
closeSupplicantConnection(function () { manager.state = "UNINITIALIZED";
disableInterface(manager.ifname, function (ok) { closeSupplicantConnection(function () {
unloadDriver(callback); disableInterface(manager.ifname, function (ok) {
unloadDriver(callback);
});
}); });
}); });
}); });
@ -1230,6 +1235,12 @@ function WifiWorker() {
self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) }); self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) });
break; break;
case "ASSOCIATED": case "ASSOCIATED":
if (!self.currentNetwork) {
self.currentNetwork =
{ bssid: WifiManager.connectionInfo.bssid,
ssid: quote(WifiManager.connectionInfo.ssid) };
}
self.currentNetwork.netId = this.id; self.currentNetwork.netId = this.id;
WifiManager.getNetworkConfiguration(self.currentNetwork, function (){}); WifiManager.getNetworkConfiguration(self.currentNetwork, function (){});
break; break;
@ -1251,7 +1262,7 @@ function WifiWorker() {
// because of that we need to gather information about the current // because of that we need to gather information about the current
// network here. // network here.
self.currentNetwork = { ssid: quote(WifiManager.connectionInfo.ssid), self.currentNetwork = { ssid: quote(WifiManager.connectionInfo.ssid),
known: true } netId: WifiManager.connectionInfo.id };
WifiManager.getNetworkConfiguration(self.currentNetwork, function(){}); WifiManager.getNetworkConfiguration(self.currentNetwork, function(){});
} }
@ -1264,12 +1275,14 @@ function WifiWorker() {
self._fireEvent("ondisconnect", {}); self._fireEvent("ondisconnect", {});
self.currentNetwork = null; self.currentNetwork = null;
// We've disconnected from a network because of a call to forgetNetwork. WifiManager.connectionDropped(function() {
// Reconnect to the next available network (if any). // We've disconnected from a network because of a call to forgetNetwork.
if (self._reconnectOnDisconnect) { // Reconnect to the next available network (if any).
self._reconnectOnDisconnect = false; if (self._reconnectOnDisconnect) {
WifiManager.reconnect(function(){}); self._reconnectOnDisconnect = false;
} WifiManager.reconnect(function(){});
}
});
break; break;
} }
@ -1683,7 +1696,7 @@ WifiWorker.prototype = {
let self = this; let self = this;
let configured = this.configuredNetworks[ssid]; let configured = this.configuredNetworks[ssid];
this._reconnectOnDisconnect = (this.currentNetwork && this._reconnectOnDisconnect = (this.currentNetwork &&
(this.currentNetwork.ssid === ssid)); (this.currentNetwork.ssid === ssid));
WifiManager.removeNetwork(configured.netId, function(ok) { WifiManager.removeNetwork(configured.netId, function(ok) {
if (!ok) { if (!ok) {
self._sendMessage(message, false, "Unable to remove the network", rid, mid); self._sendMessage(message, false, "Unable to remove the network", rid, mid);