Bug 1222899 - Handle geolocation-device-events callback. r=kchen

During this GPS engine is turned ON by the modem,
we make the location tracking icon visible to user.
This commit is contained in:
ywu 2015-12-26 13:39:42 -05:00
parent 5eec4037bc
commit d7829546e7
2 changed files with 77 additions and 26 deletions

View File

@ -1091,22 +1091,50 @@ window.addEventListener('ContentStart', function update_onContentStart() {
updatePrompt.wrappedJSObject.handleContentStart(shell);
});
/* The "GPSChipOn" is to indicate that GPS engine is turned ON by the modem.
During this GPS engine is turned ON by the modem, we make the location tracking icon visible to user.
Once GPS engine is turned OFF, the location icon will disappear.
If GPS engine is not turned ON by the modem or GPS location service is triggered,
we let GPS service take over the control of showing the location tracking icon.
The regular sequence of the geolocation-device-events is: starting-> GPSStarting-> shutdown-> GPSShutdown
*/
(function geolocationStatusTracker() {
let gGeolocationActive = false;
let GPSChipOn = false;
Services.obs.addObserver(function(aSubject, aTopic, aData) {
let oldState = gGeolocationActive;
if (aData == "starting") {
gGeolocationActive = true;
} else if (aData == "shutdown") {
gGeolocationActive = false;
let promptWarning = false;
switch (aData) {
case "GPSStarting":
if (!gGeolocationActive) {
gGeolocationActive = true;
GPSChipOn = true;
promptWarning = true;
}
break;
case "GPSShutdown":
if (GPSChipOn) {
gGeolocationActive = false;
GPSChipOn = false;
}
break;
case "starting":
gGeolocationActive = true;
GPSChipOn = false;
break;
case "shutdown":
gGeolocationActive = false;
break;
}
if (gGeolocationActive != oldState) {
shell.sendChromeEvent({
type: 'geolocation-status',
active: gGeolocationActive
active: gGeolocationActive,
prompt: promptWarning
});
}
}, "geolocation-device-events", false);

View File

@ -153,30 +153,53 @@ GonkGPSGeolocationProvider::LocationCallback(GpsLocation* location)
#endif
}
class NotifyObserversGPSTask final : public nsRunnable
{
public:
explicit NotifyObserversGPSTask(const char16_t* aData)
: mData(aData)
{}
NS_IMETHOD Run() override {
RefPtr<nsIGeolocationProvider> provider =
GonkGPSGeolocationProvider::GetSingleton();
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
obsService->NotifyObservers(provider, "geolocation-device-events", mData);
return NS_OK;
}
private:
const char16_t* mData;
};
void
GonkGPSGeolocationProvider::StatusCallback(GpsStatus* status)
{
if (gDebug_isLoggingEnabled) {
switch (status->status) {
case GPS_STATUS_NONE:
nsContentUtils::LogMessageToConsole("geo: GPS_STATUS_NONE\n");
break;
case GPS_STATUS_SESSION_BEGIN:
nsContentUtils::LogMessageToConsole("geo: GPS_STATUS_SESSION_BEGIN\n");
break;
case GPS_STATUS_SESSION_END:
nsContentUtils::LogMessageToConsole("geo: GPS_STATUS_SESSION_END\n");
break;
case GPS_STATUS_ENGINE_ON:
nsContentUtils::LogMessageToConsole("geo: GPS_STATUS_ENGINE_ON\n");
break;
case GPS_STATUS_ENGINE_OFF:
nsContentUtils::LogMessageToConsole("geo: GPS_STATUS_ENGINE_OFF\n");
break;
default:
nsContentUtils::LogMessageToConsole("geo: Unknown GPS status\n");
break;
}
const char* msgStream=0;
switch (status->status) {
case GPS_STATUS_NONE:
msgStream = "geo: GPS_STATUS_NONE\n";
break;
case GPS_STATUS_SESSION_BEGIN:
msgStream = "geo: GPS_STATUS_SESSION_BEGIN\n";
break;
case GPS_STATUS_SESSION_END:
msgStream = "geo: GPS_STATUS_SESSION_END\n";
break;
case GPS_STATUS_ENGINE_ON:
msgStream = "geo: GPS_STATUS_ENGINE_ON\n";
NS_DispatchToMainThread(new NotifyObserversGPSTask( MOZ_UTF16("GPSStarting")));
break;
case GPS_STATUS_ENGINE_OFF:
msgStream = "geo: GPS_STATUS_ENGINE_OFF\n";
NS_DispatchToMainThread(new NotifyObserversGPSTask( MOZ_UTF16("GPSShutdown")));
break;
default:
msgStream = "geo: Unknown GPS status\n";
break;
}
if (gDebug_isLoggingEnabled){
nsContentUtils::LogMessageToConsole(msgStream);
}
}