Bug 1018379 - Use wifi scanner as the sole the heartbeat that drives location updates, shorten the wifi scanner wait to 5s to ensure this (also stop and restart the scanner on WifiGeoPositionProvider.startup() to ensure this). r=jdm

This commit is contained in:
Garvan Keeley 2014-06-08 22:52:53 -07:00
Родитель 2fa097201c
Коммит 20266b3d5d
8 изменённых файлов: 42 добавлений и 29 удалений

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

@ -14,14 +14,10 @@ const SETTING_CHANGED_TOPIC = "mozsettings-changed";
let gLoggingEnabled = false;
// if we don't see any wifi responses in 5 seconds, send the request.
let gTimeToWaitBeforeSending = 5000; //ms
let gLocationRequestTimeout = 5000;
let gWifiScanningEnabled = true;
let gWifiResults;
let gCellScanningEnabled = false;
let gCellResults;
function LOG(aMsg) {
if (gLoggingEnabled) {
@ -59,7 +55,7 @@ function WifiGeoPositionProvider() {
} catch (e) {}
try {
gTimeToWaitBeforeSending = Services.prefs.getIntPref("geo.wifi.timeToWaitBeforeSending");
gLocationRequestTimeout = Services.prefs.getIntPref("geo.wifi.timeToWaitBeforeSending");
} catch (e) {}
try {
@ -123,12 +119,16 @@ WifiGeoPositionProvider.prototype = {
}
if (gWifiScanningEnabled && Cc["@mozilla.org/wifi/monitor;1"]) {
this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
if (this.wifiService) {
this.wifiService.stopWatching(this);
}
this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Ci.nsIWifiMonitor);
this.wifiService.startWatching(this);
}
// wifi thread triggers WifiGeoPositionProvider to proceed, with no wifi, do manual timeout
this.timeoutTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this.timeoutTimer.initWithCallback(this,
gTimeToWaitBeforeSending,
gLocationRequestTimeout,
this.timeoutTimer.TYPE_REPEATING_SLACK);
LOG("startup called.");
},
@ -163,7 +163,6 @@ WifiGeoPositionProvider.prototype = {
},
onChange: function(accessPoints) {
function isPublic(ap) {
let mask = "_nomap"
let result = ap.ssid.indexOf(mask, ap.ssid.length - mask.length);
@ -181,18 +180,19 @@ WifiGeoPositionProvider.prototype = {
return { 'macAddress': ap.mac, 'signalStrength': ap.signal };
};
let wifiData = null;
if (accessPoints) {
gWifiResults = accessPoints.filter(isPublic).sort(sort).map(encode);
} else {
gWifiResults = null;
wifiData = accessPoints.filter(isPublic).sort(sort).map(encode);
}
this.sendLocationRequest(wifiData);
},
onError: function (code) {
LOG("wifi error: " + code);
this.sendLocationRequest(null);
},
updateMobileInfo: function() {
getMobileInfo: function() {
LOG("updateMobileInfo called");
try {
let radioService = Cc["@mozilla.org/ril;1"]
@ -216,11 +216,20 @@ WifiGeoPositionProvider.prototype = {
}
return result;
} catch (e) {
gCellResults = null;
return null;
}
},
notify: function (timeoutTimer) {
// If Wifi scanning is disabled, then we can not depend on that for the
// heartbeat that drives location updates. Instead, just use a timer which
// will drive the update.
if (gWifiScanningEnabled == false) {
this.sendLocationRequest(null);
}
},
sendLocationRequest: function (wifiData) {
let url = Services.urlFormatter.formatURLPref("geo.wifi.uri");
let listener = this.listener;
LOG("Sending request: " + url + "\n");
@ -258,19 +267,19 @@ WifiGeoPositionProvider.prototype = {
listener.update(newLocation);
};
if (gCellScanningEnabled) {
this.updateMobileInfo();
let data = {};
if (wifiData) {
data.wifiAccessPoints = wifiData;
}
let data = {};
if (gWifiResults) {
data.wifiAccessPoints = gWifiResults;
}
if (gCellResults) {
data.cellTowers = gCellResults;
if (gCellScanningEnabled) {
let cellData = this.getMobileInfo();
if (cellData) {
data.cellTowers = cellData;
}
}
data = JSON.stringify(data);
gWifiResults = gCellResults = null;
LOG("sending " + data);
xhr.send(data);
},

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

@ -21,6 +21,7 @@ nsWifiAccessPoint::nsWifiAccessPoint()
mMac[0] = '\0';
mSsid[0] = '\0';
mSsidLen = 0;
mSignal = -1000;
}
nsWifiAccessPoint::~nsWifiAccessPoint()
@ -70,7 +71,8 @@ bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccess
for (int32_t j = 0; j < b.Count(); j++) {
LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
!strcmp(a[i]->mMac, b[j]->mMac)) {
!strcmp(a[i]->mMac, b[j]->mMac) &&
a[i]->mSignal == b[j]->mSignal) {
found = true;
}
}

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

@ -28,6 +28,8 @@ extern PRLogModuleInfo *gWifiMonitorLog;
class nsWifiAccessPoint;
#define kDefaultWifiScanInterval 5 /* seconds */
class nsWifiListener
{
public:

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

@ -332,7 +332,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n"));
mozilla::ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(60));
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
return NS_OK;

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

@ -159,7 +159,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n"));
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(60));
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
while (mKeepGoing);

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

@ -47,7 +47,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n"));
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(60));
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
while (mKeepGoing);

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

@ -142,7 +142,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n"));
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(60));
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
return NS_OK;

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

@ -123,7 +123,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n"));
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mon.Wait(PR_SecondsToInterval(60));
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
}
while (mKeepGoing);