Bug 989692 - Add GPS Debugging Logging. r=kchen

This commit is contained in:
Doug Turner 2014-03-24 21:58:18 -07:00
parent 37917f58c1
commit ab6130fd89
2 changed files with 57 additions and 19 deletions

View File

@ -9,6 +9,8 @@ const Ci = Components.interfaces;
const Cc = Components.classes;
const POSITION_UNAVAILABLE = Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE;
const SETTING_DEBUG_ENABLED = "geolocation.debugging.enabled";
const SETTING_CHANGED_TOPIC = "mozsettings-changed";
let gLoggingEnabled = false;
@ -77,14 +79,39 @@ WifiGeoPositionProvider.prototype = {
classID: Components.ID("{77DA64D3-7458-4920-9491-86CC9914F904}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationProvider,
Ci.nsIWifiListener,
Ci.nsITimerCallback]),
Ci.nsITimerCallback,
Ci.nsIObserver]),
listener: null,
observe: function(aSubject, aTopic, aData) {
if (aTopic != SETTING_CHANGED_TOPIC) {
return;
}
try {
let setting = JSON.parse(aData);
if (setting.key != SETTING_DEBUG_ENABLED) {
return;
}
gLoggingEnabled = setting.value;
} catch (e) {
}
},
startup: function() {
if (this.started)
return;
this.started = true;
try {
Services.obs.addObserver(this, SETTING_CHANGED_TOPIC, false);
let settings = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService);
settings.createLock().get(SETTING_DEBUG_ENABLED, this);
} catch(ex) {
// This platform doesn't have the settings interface, and that is just peachy
}
if (gWifiScanningEnabled) {
this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
this.wifiService.startWatching(this);
@ -115,6 +142,9 @@ WifiGeoPositionProvider.prototype = {
this.wifiService.stopWatching(this);
this.wifiService = null;
}
Services.obs.removeObserver(this, SETTING_CHANGED_TOPIC);
this.listener = null;
this.started = false;
},

View File

@ -36,15 +36,18 @@
#include "nsIRadioInterfaceLayer.h"
#endif
#define SETTING_DEBUG_ENABLED "geolocation.debugging.enabled"
#ifdef AGPS_TYPE_INVALID
#define AGPS_HAVE_DUAL_APN
#endif
#define DEBUG_GPS 0
#define FLUSH_AIDE_DATA 0
using namespace mozilla;
static const int kDefaultPeriod = 1000; // ms
static int gGPSDebugging = false;
static const char* kNetworkConnStateChangedTopic = "network-connection-state-changed";
@ -141,12 +144,11 @@ GonkGPSGeolocationProvider::SvStatusCallback(GpsSvStatus* sv_info)
void
GonkGPSGeolocationProvider::NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length)
{
#if DEBUG_GPS
printf_stderr("*** nmea info\n");
printf_stderr("timestamp:\t%lld\n", timestamp);
printf_stderr("nmea: \t%s\n", nmea);
printf_stderr("length: \t%d\n", length);
#endif
if (gGPSDebugging) {
nsContentUtils::LogMessageToConsole("NMEA: timestamp:\t%lld", timestamp);
nsContentUtils::LogMessageToConsole("NMEA: nmea: \t%s", nmea);
nsContentUtils::LogMessageToConsole("NMEA length: \%d", length);
}
}
void
@ -538,13 +540,13 @@ GonkGPSGeolocationProvider::InjectLocation(double latitude,
double longitude,
float accuracy)
{
#ifdef DEBUG_GPS
printf_stderr("*** injecting location\n");
printf_stderr("*** lat: %f\n", latitude);
printf_stderr("*** lon: %f\n", longitude);
printf_stderr("*** accuracy: %f\n", accuracy);
#endif
if (gGPSDebugging) {
nsContentUtils::LogMessageToConsole("*** injecting location");
nsContentUtils::LogMessageToConsole("*** lat: %f", latitude);
nsContentUtils::LogMessageToConsole("*** lon: %f", longitude);
nsContentUtils::LogMessageToConsole("*** accuracy: %f", accuracy);
}
MOZ_ASSERT(NS_IsMainThread());
if (!mGpsInterface) {
return;
@ -617,7 +619,7 @@ GonkGPSGeolocationProvider::StartGPS()
mGpsInterface->set_position_mode(positionMode,
GPS_POSITION_RECURRENCE_PERIODIC,
update, 0, 0);
#if DEBUG_GPS
#if FLUSH_AIDE_DATA
// Delete cached data
mGpsInterface->delete_aiding_data(GPS_DELETE_ALL);
#endif
@ -703,6 +705,7 @@ GonkGPSGeolocationProvider::Startup()
{
MOZ_ASSERT(NS_IsMainThread());
RequestSettingValue(SETTING_DEBUG_ENABLED);
if (mStarted) {
return NS_OK;
}
@ -808,10 +811,10 @@ NS_IMETHODIMP
GonkGPSGeolocationProvider::Handle(const nsAString& aName,
JS::Handle<JS::Value> aResult)
{
if (aName.EqualsLiteral("ril.supl.apn")) {
JSContext *cx = nsContentUtils::GetCurrentJSContext();
NS_ENSURE_TRUE(cx, NS_OK);
JSContext *cx = nsContentUtils::GetCurrentJSContext();
NS_ENSURE_TRUE(cx, NS_OK);
if (aName.EqualsLiteral("ril.supl.apn")) {
// When we get the APN, we attempt to call data_call_open of AGPS.
if (aResult.isString()) {
// NB: No need to enter a compartment to read the contents of a string.
@ -821,6 +824,11 @@ GonkGPSGeolocationProvider::Handle(const nsAString& aName,
SetAGpsDataConn(apn);
}
}
} else if (aName.EqualsLiteral(SETTING_DEBUG_ENABLED)) {
if (!aResult.isBoolean()) {
return NS_ERROR_FAILURE;
}
gGPSDebugging = aResult.toBoolean();
}
return NS_OK;
}