Bug 729943 - Add a codepath to simply reconnect to an existing wpa_supplicant for non-broken Androids. r=cjones

This commit is contained in:
Blake Kaplan 2012-02-23 15:24:08 +01:00
parent b4e3f041bf
commit 711bc6ec6e

View File

@ -640,6 +640,7 @@ var WifiManager = (function() {
return true;
}
const SUPP_PROP = "init.svc.wpa_supplicant";
function killSupplicant(callback) {
// It is interesting to note that this function does exactly what
// wifi_stop_supplicant does. Unforunately, on the Galaxy S2, Samsung
@ -649,15 +650,15 @@ var WifiManager = (function() {
var count = 0;
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
function tick() {
getProperty("init.svc.wpa_supplicant", "stopped", function (result) {
getProperty(SUPP_PROP, "stopped", function (result) {
if (result === null) {
callback(false);
callback();
return;
}
if (result === "stopped" || ++count >= 5) {
// Either we succeeded or ran out of time.
timer = null;
callback(count < 5);
callback();
return;
}
@ -670,9 +671,31 @@ var WifiManager = (function() {
}
function prepareForStartup(callback) {
stopDhcp(manager.ifname, function() {
// Ignore any errors.
killSupplicant(callback);
// First, check to see if there's a wpa_supplicant running that we can
// connect to.
getProperty(SUPP_PROP, "stopped", function (value) {
debug(SUPP_PROP + " was " + value);
if (value !== "running") {
stopDhcp(manager.ifname, function() { callback(false) });
return;
}
debug(SUPP_PROP + " was running, trying to connect");
// It's running, try to reconnect to it.
connectToSupplicant(function (retval) {
if (retval === 0) {
// Successfully reconnected! Don't do anything else.
debug("Successfully connected!");
callback(true);
return;
}
debug("Didn't connect, trying other method.");
stopDhcp(manager.ifname, function() {
// Ignore any errors.
killSupplicant(function() { callback(false); });
});
});
});
}
@ -695,8 +718,12 @@ var WifiManager = (function() {
}
manager.ifname = ifname;
prepareForStartup(function() {
// Ignore errors...
prepareForStartup(function(already_connected) {
if (already_connected) {
callback(0);
return;
}
loadDriver(function (status) {
if (status < 0) {
callback(status);