2012-01-19 06:53:51 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-07-20 02:10:44 -07:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <hardware/gps.h>
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
#include "GonkGPSGeolocationProvider.h"
|
2012-01-19 06:53:51 -08:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-03-29 00:18:11 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-01-19 06:53:51 -08:00
|
|
|
#include "nsGeoPosition.h"
|
2012-07-16 17:38:46 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsINetworkManager.h"
|
2014-03-29 00:18:11 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-10-23 00:18:11 -07:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-07-16 17:38:46 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-11-14 13:46:38 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-22 00:42:55 -07:00
|
|
|
#include "prtime.h"
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
#include "nsIDOMIccInfo.h"
|
|
|
|
#include "nsIDOMMobileConnection.h"
|
|
|
|
#include "nsIRadioInterfaceLayer.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-24 21:58:18 -07:00
|
|
|
#define SETTING_DEBUG_ENABLED "geolocation.debugging.enabled"
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
#ifdef AGPS_TYPE_INVALID
|
|
|
|
#define AGPS_HAVE_DUAL_APN
|
|
|
|
#endif
|
|
|
|
|
2014-03-24 21:58:18 -07:00
|
|
|
#define FLUSH_AIDE_DATA 0
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
static const int kDefaultPeriod = 1000; // ms
|
2014-03-24 21:58:18 -07:00
|
|
|
static int gGPSDebugging = false;
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2014-03-29 00:18:11 -07:00
|
|
|
static const char* kNetworkConnStateChangedTopic = "network-connection-state-changed";
|
|
|
|
|
2012-10-03 19:00:59 -07:00
|
|
|
// While most methods of GonkGPSGeolocationProvider should only be
|
|
|
|
// called from main thread, we deliberately put the Init and ShutdownGPS
|
|
|
|
// methods off main thread to avoid blocking.
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_IMPL_ISUPPORTS3(GonkGPSGeolocationProvider,
|
|
|
|
nsIGeolocationProvider,
|
2014-03-29 00:18:11 -07:00
|
|
|
nsIObserver,
|
2013-07-18 19:21:20 -07:00
|
|
|
nsISettingsServiceCallback)
|
2013-10-29 01:12:47 -07:00
|
|
|
#else
|
2014-03-29 00:18:11 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(GonkGPSGeolocationProvider,
|
|
|
|
nsIGeolocationProvider,
|
|
|
|
nsIObserver)
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2013-05-29 17:43:17 -07:00
|
|
|
/* static */ GonkGPSGeolocationProvider* GonkGPSGeolocationProvider::sSingleton = nullptr;
|
2012-07-16 17:38:46 -07:00
|
|
|
GpsCallbacks GonkGPSGeolocationProvider::mCallbacks = {
|
|
|
|
sizeof(GpsCallbacks),
|
|
|
|
LocationCallback,
|
|
|
|
StatusCallback,
|
|
|
|
SvStatusCallback,
|
|
|
|
NmeaCallback,
|
|
|
|
SetCapabilitiesCallback,
|
|
|
|
AcquireWakelockCallback,
|
|
|
|
ReleaseWakelockCallback,
|
|
|
|
CreateThreadCallback,
|
|
|
|
#ifdef GPS_CAPABILITY_ON_DEMAND_TIME
|
|
|
|
RequestUtcTimeCallback,
|
|
|
|
#endif
|
|
|
|
};
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
AGpsCallbacks
|
|
|
|
GonkGPSGeolocationProvider::mAGPSCallbacks = {
|
|
|
|
AGPSStatusCallback,
|
|
|
|
CreateThreadCallback,
|
|
|
|
};
|
|
|
|
|
|
|
|
AGpsRilCallbacks
|
|
|
|
GonkGPSGeolocationProvider::mAGPSRILCallbacks = {
|
|
|
|
AGPSRILSetIDCallback,
|
|
|
|
AGPSRILRefLocCallback,
|
|
|
|
CreateThreadCallback,
|
|
|
|
};
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::LocationCallback(GpsLocation* location)
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
2012-07-16 17:38:46 -07:00
|
|
|
class UpdateLocationEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
UpdateLocationEvent(nsGeoPosition* aPosition)
|
|
|
|
: mPosition(aPosition)
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
2014-03-22 00:42:55 -07:00
|
|
|
provider->mLastGPSDerivedLocationTime = PR_Now();
|
2012-07-16 17:38:46 -07:00
|
|
|
nsCOMPtr<nsIGeolocationUpdate> callback = provider->mLocationCallback;
|
|
|
|
if (callback) {
|
|
|
|
callback->Update(mPosition);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<nsGeoPosition> mPosition;
|
|
|
|
};
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-07-26 15:50:27 -07:00
|
|
|
MOZ_ASSERT(location);
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
nsRefPtr<nsGeoPosition> somewhere = new nsGeoPosition(location->latitude,
|
|
|
|
location->longitude,
|
|
|
|
location->altitude,
|
|
|
|
location->accuracy,
|
|
|
|
location->accuracy,
|
|
|
|
location->bearing,
|
|
|
|
location->speed,
|
|
|
|
location->timestamp);
|
2012-07-16 17:38:46 -07:00
|
|
|
NS_DispatchToMainThread(new UpdateLocationEvent(somewhere));
|
2012-01-19 06:53:51 -08:00
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::StatusCallback(GpsStatus* status)
|
|
|
|
{
|
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::SvStatusCallback(GpsSvStatus* sv_info)
|
|
|
|
{
|
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length)
|
|
|
|
{
|
2014-03-24 21:58:18 -07:00
|
|
|
if (gGPSDebugging) {
|
|
|
|
nsContentUtils::LogMessageToConsole("NMEA: timestamp:\t%lld", timestamp);
|
|
|
|
nsContentUtils::LogMessageToConsole("NMEA: nmea: \t%s", nmea);
|
|
|
|
nsContentUtils::LogMessageToConsole("NMEA length: \%d", length);
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::SetCapabilitiesCallback(uint32_t capabilities)
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
class UpdateCapabilitiesEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
UpdateCapabilitiesEvent(uint32_t aCapabilities)
|
|
|
|
: mCapabilities(aCapabilities)
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-10-03 19:00:59 -07:00
|
|
|
provider->mSupportsScheduling = mCapabilities & GPS_CAPABILITY_SCHEDULING;
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-10-03 19:00:59 -07:00
|
|
|
provider->mSupportsMSB = mCapabilities & GPS_CAPABILITY_MSB;
|
|
|
|
provider->mSupportsMSA = mCapabilities & GPS_CAPABILITY_MSA;
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-10-03 19:00:59 -07:00
|
|
|
provider->mSupportsSingleShot = mCapabilities & GPS_CAPABILITY_SINGLE_SHOT;
|
2012-07-16 17:38:46 -07:00
|
|
|
#ifdef GPS_CAPABILITY_ON_DEMAND_TIME
|
2012-10-03 19:00:59 -07:00
|
|
|
provider->mSupportsTimeInjection = mCapabilities & GPS_CAPABILITY_ON_DEMAND_TIME;
|
2012-07-16 17:38:46 -07:00
|
|
|
#endif
|
2012-10-03 19:00:59 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
uint32_t mCapabilities;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(new UpdateCapabilitiesEvent(capabilities));
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::AcquireWakelockCallback()
|
|
|
|
{
|
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::ReleaseWakelockCallback()
|
|
|
|
{
|
|
|
|
}
|
2012-06-03 20:17:43 -07:00
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
typedef void *(*pthread_func)(void *);
|
|
|
|
|
|
|
|
/** Callback for creating a thread that can call into the JS codes.
|
|
|
|
*/
|
2012-07-16 17:38:46 -07:00
|
|
|
pthread_t
|
|
|
|
GonkGPSGeolocationProvider::CreateThreadCallback(const char* name, void (*start)(void *), void* arg)
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
|
|
|
|
/* Unfortunately pthread_create and the callback disagreed on what
|
|
|
|
* start function should return.
|
|
|
|
*/
|
|
|
|
pthread_create(&thread, &attr, reinterpret_cast<pthread_func>(start), arg);
|
|
|
|
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::RequestUtcTimeCallback()
|
|
|
|
{
|
|
|
|
}
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::AGPSStatusCallback(AGpsStatus* status)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(status);
|
|
|
|
|
2012-10-03 19:00:59 -07:00
|
|
|
class AGPSStatusEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
AGPSStatusEvent(AGpsStatusValue aStatus)
|
|
|
|
: mStatus(aStatus)
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-10-03 19:00:59 -07:00
|
|
|
switch (mStatus) {
|
|
|
|
case GPS_REQUEST_AGPS_DATA_CONN:
|
|
|
|
provider->RequestDataConnection();
|
|
|
|
break;
|
|
|
|
case GPS_RELEASE_AGPS_DATA_CONN:
|
|
|
|
provider->ReleaseDataConnection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
AGpsStatusValue mStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(new AGPSStatusEvent(status->status));
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::AGPSRILSetIDCallback(uint32_t flags)
|
|
|
|
{
|
|
|
|
class RequestSetIDEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
RequestSetIDEvent(uint32_t flags)
|
|
|
|
: mFlags(flags)
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
|
|
|
provider->RequestSetID(mFlags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
uint32_t mFlags;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(new RequestSetIDEvent(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::AGPSRILRefLocCallback(uint32_t flags)
|
|
|
|
{
|
2013-04-25 19:54:45 -07:00
|
|
|
class RequestRefLocEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
RequestRefLocEvent()
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
|
|
|
provider->SetReferenceLocation();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
if (flags & AGPS_RIL_REQUEST_REFLOC_CELLID) {
|
2013-04-25 19:54:45 -07:00
|
|
|
NS_DispatchToMainThread(new RequestRefLocEvent());
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
GonkGPSGeolocationProvider::GonkGPSGeolocationProvider()
|
|
|
|
: mStarted(false)
|
2012-07-16 17:38:46 -07:00
|
|
|
, mSupportsScheduling(false)
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2014-03-22 00:42:55 -07:00
|
|
|
, mSupportsMSB(false)
|
|
|
|
, mSupportsMSA(false)
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
, mSupportsSingleShot(false)
|
|
|
|
, mSupportsTimeInjection(false)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mGpsInterface(nullptr)
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GonkGPSGeolocationProvider::~GonkGPSGeolocationProvider()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mStarted, "Must call Shutdown before destruction");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
sSingleton = nullptr;
|
2012-01-19 06:53:51 -08:00
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
already_AddRefed<GonkGPSGeolocationProvider>
|
2012-01-19 06:53:51 -08:00
|
|
|
GonkGPSGeolocationProvider::GetSingleton()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
if (!sSingleton)
|
|
|
|
sSingleton = new GonkGPSGeolocationProvider();
|
|
|
|
|
2013-05-29 17:43:17 -07:00
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider = sSingleton;
|
|
|
|
return provider.forget();
|
2012-01-19 06:53:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const GpsInterface*
|
|
|
|
GonkGPSGeolocationProvider::GetGPSInterface()
|
|
|
|
{
|
|
|
|
hw_module_t* module;
|
|
|
|
|
|
|
|
if (hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
hw_device_t* device;
|
|
|
|
if (module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
gps_device_t* gps_device = (gps_device_t *)device;
|
2012-03-21 22:25:59 -07:00
|
|
|
const GpsInterface* result = gps_device->get_gps_interface(gps_device);
|
|
|
|
|
|
|
|
if (result->size != sizeof(GpsInterface)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-21 22:25:59 -07:00
|
|
|
}
|
|
|
|
return result;
|
2012-01-19 06:53:51 -08:00
|
|
|
}
|
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-10-23 00:18:11 -07:00
|
|
|
int32_t
|
|
|
|
GonkGPSGeolocationProvider::GetDataConnectionState()
|
|
|
|
{
|
2013-07-02 02:36:44 -07:00
|
|
|
if (!mRadioInterface) {
|
2012-10-23 00:18:11 -07:00
|
|
|
return nsINetworkInterface::NETWORK_STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t state;
|
2013-07-02 02:36:44 -07:00
|
|
|
mRadioInterface->GetDataCallStateByType(NS_LITERAL_STRING("supl"), &state);
|
2012-10-23 00:18:11 -07:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::SetAGpsDataConn(nsAString& aApn)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mAGpsInterface);
|
|
|
|
|
|
|
|
int32_t connectionState = GetDataConnectionState();
|
|
|
|
if (connectionState == nsINetworkInterface::NETWORK_STATE_CONNECTED) {
|
|
|
|
NS_ConvertUTF16toUTF8 apn(aApn);
|
|
|
|
#ifdef AGPS_HAVE_DUAL_APN
|
|
|
|
mAGpsInterface->data_conn_open(AGPS_TYPE_SUPL,
|
|
|
|
apn.get(),
|
|
|
|
AGPS_APN_BEARER_IPV4);
|
|
|
|
#else
|
|
|
|
mAGpsInterface->data_conn_open(apn.get());
|
|
|
|
#endif
|
|
|
|
} else if (connectionState == nsINetworkInterface::NETWORK_STATE_DISCONNECTED) {
|
|
|
|
#ifdef AGPS_HAVE_DUAL_APN
|
|
|
|
mAGpsInterface->data_conn_closed(AGPS_TYPE_SUPL);
|
|
|
|
#else
|
|
|
|
mAGpsInterface->data_conn_closed();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::RequestSettingValue(char* aKey)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aKey);
|
|
|
|
nsCOMPtr<nsISettingsService> ss = do_GetService("@mozilla.org/settingsService;1");
|
|
|
|
if (!ss) {
|
|
|
|
MOZ_ASSERT(ss);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsISettingsServiceLock> lock;
|
2014-02-07 03:19:58 -08:00
|
|
|
ss->CreateLock(nullptr, getter_AddRefs(lock));
|
2012-10-23 00:18:11 -07:00
|
|
|
lock->Get(aKey, this);
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::RequestDataConnection()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
if (!mRadioInterface) {
|
2012-07-26 15:50:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 00:18:11 -07:00
|
|
|
if (GetDataConnectionState() == nsINetworkInterface::NETWORK_STATE_CONNECTED) {
|
|
|
|
// Connection is already established, we don't need to setup again.
|
|
|
|
// We just get supl APN and make AGPS data connection state updated.
|
|
|
|
RequestSettingValue("ril.supl.apn");
|
|
|
|
} else {
|
2013-07-02 02:36:44 -07:00
|
|
|
mRadioInterface->SetupDataCallByType(NS_LITERAL_STRING("supl"));
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::ReleaseDataConnection()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
if (!mRadioInterface) {
|
2012-07-26 15:50:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
mRadioInterface->DeactivateDataCallByType(NS_LITERAL_STRING("supl"));
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::RequestSetID(uint32_t flags)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
if (!mRadioInterface) {
|
2012-07-26 15:50:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
AGpsSetIDType type = AGPS_SETID_TYPE_NONE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRilContext> rilCtx;
|
2013-07-02 02:36:44 -07:00
|
|
|
mRadioInterface->GetRilContext(getter_AddRefs(rilCtx));
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
if (rilCtx) {
|
2013-01-10 05:57:49 -08:00
|
|
|
nsAutoString id;
|
|
|
|
if (flags & AGPS_RIL_REQUEST_SETID_IMSI) {
|
|
|
|
type = AGPS_SETID_TYPE_IMSI;
|
|
|
|
rilCtx->GetImsi(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & AGPS_RIL_REQUEST_SETID_MSISDN) {
|
2013-05-30 03:52:56 -07:00
|
|
|
nsCOMPtr<nsIDOMMozIccInfo> iccInfo;
|
2013-01-10 05:57:49 -08:00
|
|
|
rilCtx->GetIccInfo(getter_AddRefs(iccInfo));
|
|
|
|
if (iccInfo) {
|
2013-08-20 19:45:57 -07:00
|
|
|
nsCOMPtr<nsIDOMMozGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
|
|
|
|
if (gsmIccInfo) {
|
|
|
|
type = AGPS_SETID_TYPE_MSISDN;
|
|
|
|
gsmIccInfo->GetMsisdn(id);
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
}
|
2013-01-10 05:57:49 -08:00
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 idBytes(id);
|
|
|
|
mAGpsRilInterface->set_set_id(type, idBytes.get());
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::SetReferenceLocation()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
if (!mRadioInterface) {
|
2012-07-26 15:50:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
nsCOMPtr<nsIRilContext> rilCtx;
|
2013-07-02 02:36:44 -07:00
|
|
|
mRadioInterface->GetRilContext(getter_AddRefs(rilCtx));
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
AGpsRefLocation location;
|
|
|
|
|
|
|
|
// TODO: Bug 772750 - get mobile connection technology from rilcontext
|
|
|
|
location.type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
|
|
|
|
|
|
|
|
if (rilCtx) {
|
2013-05-30 03:52:56 -07:00
|
|
|
nsCOMPtr<nsIDOMMozIccInfo> iccInfo;
|
2013-01-10 05:57:49 -08:00
|
|
|
rilCtx->GetIccInfo(getter_AddRefs(iccInfo));
|
|
|
|
if (iccInfo) {
|
2013-02-24 19:59:30 -08:00
|
|
|
nsresult result;
|
|
|
|
nsAutoString mcc, mnc;
|
|
|
|
|
|
|
|
iccInfo->GetMcc(mcc);
|
|
|
|
iccInfo->GetMnc(mnc);
|
|
|
|
|
2013-04-24 05:36:09 -07:00
|
|
|
location.u.cellID.mcc = mcc.ToInteger(&result);
|
2013-02-24 19:59:30 -08:00
|
|
|
if (result != NS_OK) {
|
|
|
|
NS_WARNING("Cannot parse mcc to integer");
|
|
|
|
location.u.cellID.mcc = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-24 05:36:09 -07:00
|
|
|
location.u.cellID.mnc = mnc.ToInteger(&result);
|
2013-02-24 19:59:30 -08:00
|
|
|
if (result != NS_OK) {
|
|
|
|
NS_WARNING("Cannot parse mnc to integer");
|
|
|
|
location.u.cellID.mnc = 0;
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2012-08-15 18:36:56 -07:00
|
|
|
nsCOMPtr<nsIDOMMozMobileConnectionInfo> voice;
|
|
|
|
rilCtx->GetVoice(getter_AddRefs(voice));
|
|
|
|
if (voice) {
|
|
|
|
nsCOMPtr<nsIDOMMozMobileCellInfo> cell;
|
|
|
|
voice->GetCell(getter_AddRefs(cell));
|
|
|
|
if (cell) {
|
2013-07-18 02:30:54 -07:00
|
|
|
int32_t lac;
|
|
|
|
int64_t cid;
|
|
|
|
|
|
|
|
cell->GetGsmLocationAreaCode(&lac);
|
|
|
|
// The valid range of LAC is 0x0 to 0xffff which is defined in
|
|
|
|
// hardware/ril/include/telephony/ril.h
|
|
|
|
if (lac >= 0x0 && lac <= 0xffff) {
|
|
|
|
location.u.cellID.lac = lac;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell->GetGsmCellId(&cid);
|
|
|
|
// The valid range of cell id is 0x0 to 0xffffffff which is defined in
|
|
|
|
// hardware/ril/include/telephony/ril.h
|
|
|
|
if (cid >= 0x0 && cid <= 0xffffffff) {
|
|
|
|
location.u.cellID.cid = cid;
|
|
|
|
}
|
2012-08-15 18:36:56 -07:00
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2012-07-26 15:50:27 -07:00
|
|
|
if (mAGpsRilInterface) {
|
|
|
|
mAGpsRilInterface->set_ref_location(&location, sizeof(location));
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
}
|
2014-03-22 00:42:55 -07:00
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2014-03-22 00:42:55 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::InjectLocation(double latitude,
|
|
|
|
double longitude,
|
|
|
|
float accuracy)
|
|
|
|
{
|
2014-03-24 21:58:18 -07:00
|
|
|
if (gGPSDebugging) {
|
|
|
|
nsContentUtils::LogMessageToConsole("*** injecting location");
|
|
|
|
nsContentUtils::LogMessageToConsole("*** lat: %f", latitude);
|
|
|
|
nsContentUtils::LogMessageToConsole("*** lon: %f", longitude);
|
|
|
|
nsContentUtils::LogMessageToConsole("*** accuracy: %f", accuracy);
|
|
|
|
}
|
|
|
|
|
2014-03-22 00:42:55 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!mGpsInterface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGpsInterface->inject_location(latitude, longitude, accuracy);
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::Init()
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
2012-07-16 17:38:46 -07:00
|
|
|
// Must not be main thread. Some GPS driver's first init takes very long.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-03-21 22:25:59 -07:00
|
|
|
mGpsInterface = GetGPSInterface();
|
2012-07-16 17:38:46 -07:00
|
|
|
if (!mGpsInterface) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-21 22:25:59 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
if (mGpsInterface->init(&mCallbacks) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
mAGpsInterface =
|
|
|
|
static_cast<const AGpsInterface*>(mGpsInterface->get_extension(AGPS_INTERFACE));
|
|
|
|
if (mAGpsInterface) {
|
|
|
|
mAGpsInterface->init(&mAGPSCallbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
mAGpsRilInterface =
|
|
|
|
static_cast<const AGpsRilInterface*>(mGpsInterface->get_extension(AGPS_RIL_INTERFACE));
|
|
|
|
if (mAGpsRilInterface) {
|
|
|
|
mAGpsRilInterface->init(&mAGPSRILCallbacks);
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableMethod(this, &GonkGPSGeolocationProvider::StartGPS));
|
|
|
|
}
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::StartGPS()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-07-26 15:50:27 -07:00
|
|
|
MOZ_ASSERT(mGpsInterface);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t update = Preferences::GetInt("geo.default.update", kDefaultPeriod);
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
if (mSupportsMSA || mSupportsMSB) {
|
|
|
|
SetupAGPS();
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
int positionMode = GPS_POSITION_MODE_STANDALONE;
|
2012-07-16 17:38:46 -07:00
|
|
|
bool singleShot = false;
|
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
// XXX: If we know this is a single shot request, use MSA can be faster.
|
|
|
|
if (singleShot && mSupportsMSA) {
|
|
|
|
positionMode = GPS_POSITION_MODE_MS_ASSISTED;
|
|
|
|
} else if (mSupportsMSB) {
|
|
|
|
positionMode = GPS_POSITION_MODE_MS_BASED;
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
if (!mSupportsScheduling) {
|
|
|
|
update = kDefaultPeriod;
|
|
|
|
}
|
2012-03-21 22:25:59 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
mGpsInterface->set_position_mode(positionMode,
|
2012-01-19 06:53:51 -08:00
|
|
|
GPS_POSITION_RECURRENCE_PERIODIC,
|
|
|
|
update, 0, 0);
|
2014-03-24 21:58:18 -07:00
|
|
|
#if FLUSH_AIDE_DATA
|
2012-07-16 17:38:46 -07:00
|
|
|
// Delete cached data
|
|
|
|
mGpsInterface->delete_aiding_data(GPS_DELETE_ALL);
|
|
|
|
#endif
|
2012-03-21 22:25:59 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
mGpsInterface->start();
|
|
|
|
}
|
|
|
|
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
void
|
|
|
|
GonkGPSGeolocationProvider::SetupAGPS()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(mAGpsInterface);
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
const nsAdoptingCString& suplServer = Preferences::GetCString("geo.gps.supl_server");
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t suplPort = Preferences::GetInt("geo.gps.supl_port", -1);
|
2012-07-16 17:38:46 -07:00
|
|
|
if (!suplServer.IsEmpty() && suplPort > 0) {
|
|
|
|
mAGpsInterface->set_server(AGPS_TYPE_SUPL, suplServer.get(), suplPort);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Cannot get SUPL server settings");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-29 00:18:11 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->AddObserver(this, kNetworkConnStateChangedTopic, false);
|
|
|
|
}
|
|
|
|
|
2013-07-02 02:36:44 -07:00
|
|
|
nsCOMPtr<nsIRadioInterfaceLayer> ril = do_GetService("@mozilla.org/ril;1");
|
|
|
|
if (ril) {
|
|
|
|
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
|
|
|
|
// MultiSIM configuration
|
|
|
|
ril->GetRadioInterface(0 /* clientId */, getter_AddRefs(mRadioInterface));
|
2012-07-26 15:50:27 -07:00
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2014-03-22 00:42:55 -07:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(GonkGPSGeolocationProvider::NetworkLocationUpdate,
|
|
|
|
nsIGeolocationUpdate)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::NetworkLocationUpdate::Update(nsIDOMGeoPosition *position)
|
|
|
|
{
|
|
|
|
nsRefPtr<GonkGPSGeolocationProvider> provider =
|
|
|
|
GonkGPSGeolocationProvider::GetSingleton();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
|
|
|
position->GetCoords(getter_AddRefs(coords));
|
|
|
|
if (!coords) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we haven't seen anything from the GPS device for 1s,
|
|
|
|
// use this network derived location.
|
|
|
|
int64_t diff = PR_Now() - provider->mLastGPSDerivedLocationTime;
|
|
|
|
if (provider->mLocationCallback && diff > kDefaultPeriod) {
|
|
|
|
provider->mLocationCallback->Update(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
double lat, lon, acc;
|
|
|
|
coords->GetLatitude(&lat);
|
|
|
|
coords->GetLongitude(&lon);
|
|
|
|
coords->GetAccuracy(&acc);
|
|
|
|
provider->InjectLocation(lat, lon, acc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::NetworkLocationUpdate::LocationUpdatePending()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::NetworkLocationUpdate::NotifyError(uint16_t error)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::Startup()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-03-24 21:58:18 -07:00
|
|
|
RequestSettingValue(SETTING_DEBUG_ENABLED);
|
2012-07-16 17:38:46 -07:00
|
|
|
if (mStarted) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInitThread) {
|
|
|
|
nsresult rv = NS_NewThread(getter_AddRefs(mInitThread));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitThread->Dispatch(NS_NewRunnableMethod(this, &GonkGPSGeolocationProvider::Init),
|
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
|
2014-03-22 00:42:55 -07:00
|
|
|
mNetworkLocationProvider = do_CreateInstance("@mozilla.org/geolocation/mls-provider;1");
|
|
|
|
if (mNetworkLocationProvider) {
|
|
|
|
nsresult rv = mNetworkLocationProvider->Startup();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsRefPtr<NetworkLocationUpdate> update = new NetworkLocationUpdate();
|
|
|
|
mNetworkLocationProvider->Watch(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastGPSDerivedLocationTime = 0;
|
2012-03-21 22:25:59 -07:00
|
|
|
mStarted = true;
|
2012-01-19 06:53:51 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-12 19:20:07 -07:00
|
|
|
GonkGPSGeolocationProvider::Watch(nsIGeolocationUpdate* aCallback)
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
mLocationCallback = aCallback;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::Shutdown()
|
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-07-26 15:50:27 -07:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
if (!mStarted) {
|
2012-01-19 06:53:51 -08:00
|
|
|
return NS_OK;
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2012-10-03 19:00:59 -07:00
|
|
|
mStarted = false;
|
2014-03-24 12:40:42 -07:00
|
|
|
if (mNetworkLocationProvider) {
|
|
|
|
mNetworkLocationProvider->Shutdown();
|
|
|
|
mNetworkLocationProvider = nullptr;
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2014-03-29 00:18:11 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, kNetworkConnStateChangedTopic);
|
2012-10-03 19:00:59 -07:00
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-10-03 19:00:59 -07:00
|
|
|
|
|
|
|
mInitThread->Dispatch(NS_NewRunnableMethod(this, &GonkGPSGeolocationProvider::ShutdownGPS),
|
2012-07-16 17:38:46 -07:00
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-03 19:00:59 -07:00
|
|
|
GonkGPSGeolocationProvider::ShutdownGPS()
|
2012-07-16 17:38:46 -07:00
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(!mStarted, "Should only be called after Shutdown");
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-07-26 15:50:27 -07:00
|
|
|
if (mGpsInterface) {
|
|
|
|
mGpsInterface->stop();
|
|
|
|
mGpsInterface->cleanup();
|
|
|
|
}
|
2012-01-19 06:53:51 -08:00
|
|
|
}
|
2012-03-21 10:52:35 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::SetHighAccuracy(bool)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-29 00:18:11 -07:00
|
|
|
GonkGPSGeolocationProvider::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData)
|
2012-07-16 17:38:46 -07:00
|
|
|
{
|
2012-10-03 19:00:59 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2014-03-29 00:18:11 -07:00
|
|
|
if (strcmp(aTopic, kNetworkConnStateChangedTopic)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRilNetworkInterface> iface = do_QueryInterface(aSubject);
|
|
|
|
if (!iface) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 00:18:11 -07:00
|
|
|
RequestSettingValue("ril.supl.apn");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2014-03-29 00:18:11 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-10-23 00:18:11 -07:00
|
|
|
/** nsISettingsServiceCallback **/
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-10-23 00:18:11 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GonkGPSGeolocationProvider::Handle(const nsAString& aName,
|
2014-01-09 09:39:36 -08:00
|
|
|
JS::Handle<JS::Value> aResult)
|
2012-10-23 00:18:11 -07:00
|
|
|
{
|
2014-03-24 21:58:18 -07:00
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
NS_ENSURE_TRUE(cx, NS_OK);
|
2013-04-03 15:45:35 -07:00
|
|
|
|
2014-03-24 21:58:18 -07:00
|
|
|
if (aName.EqualsLiteral("ril.supl.apn")) {
|
2012-10-23 00:18:11 -07:00
|
|
|
// When we get the APN, we attempt to call data_call_open of AGPS.
|
|
|
|
if (aResult.isString()) {
|
2013-04-03 15:45:35 -07:00
|
|
|
// NB: No need to enter a compartment to read the contents of a string.
|
2012-10-23 00:18:11 -07:00
|
|
|
nsDependentJSString apn;
|
|
|
|
apn.init(cx, aResult.toString());
|
|
|
|
if (!apn.IsEmpty()) {
|
|
|
|
SetAGpsDataConn(apn);
|
|
|
|
}
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
2014-03-24 21:58:18 -07:00
|
|
|
} else if (aName.EqualsLiteral(SETTING_DEBUG_ENABLED)) {
|
|
|
|
if (!aResult.isBoolean()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
gGPSDebugging = aResult.toBoolean();
|
2012-07-16 17:38:46 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-14 13:46:38 -08:00
|
|
|
GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage)
|
2012-07-16 17:38:46 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|