Bug 920551 - 2.j/2: fix GonkGPSGeolocationProvider. r=kanru, a=koi+
☠☠ backed out by 9535f227ec80 ☠ ☠
authorVicamo Yang <vyang@mozilla.com>
Thu, 31 Oct 2013 21:08:30 +0800
changeset 166333 d70b80fb400d5f71a256e878f0d29d5aa999f934
parent 166332 a2c2a0b7626ed626c135ed2aed9f6b3e27bc6ce6
child 166334 f31ef270c830c8a7e001adeac5ba8099ebd0f4db
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskanru, koi
bugs920551
milestone27.0a2
Bug 920551 - 2.j/2: fix GonkGPSGeolocationProvider. r=kanru, a=koi+
dom/system/gonk/GonkGPSGeolocationProvider.cpp
dom/system/gonk/GonkGPSGeolocationProvider.h
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -13,46 +13,53 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 #include <pthread.h>
 #include <hardware/gps.h>
 
 #include "GonkGPSGeolocationProvider.h"
-#include "SystemWorkerManager.h"
 #include "mozilla/Preferences.h"
 #include "nsGeoPosition.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsINetworkManager.h"
-#include "nsIRadioInterfaceLayer.h"
-#include "nsIDOMIccInfo.h"
-#include "nsIDOMMobileConnection.h"
 #include "nsJSUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsContentUtils.h"
 
+#ifdef MOZ_B2G_RIL
+#include "nsIDOMIccInfo.h"
+#include "nsIDOMMobileConnection.h"
+#include "nsIRadioInterfaceLayer.h"
+#endif
+
 #ifdef AGPS_TYPE_INVALID
 #define AGPS_HAVE_DUAL_APN
 #endif
 
 #define DEBUG_GPS 0
 
 using namespace mozilla;
 
 static const int kDefaultPeriod = 1000; // ms
 
 // 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.
+#ifdef MOZ_B2G_RIL
 NS_IMPL_ISUPPORTS3(GonkGPSGeolocationProvider,
                    nsIGeolocationProvider,
                    nsIRILDataCallback,
                    nsISettingsServiceCallback)
+#else
+NS_IMPL_ISUPPORTS1(GonkGPSGeolocationProvider,
+                   nsIGeolocationProvider)
+#endif
 
 /* static */ GonkGPSGeolocationProvider* GonkGPSGeolocationProvider::sSingleton = nullptr;
 GpsCallbacks GonkGPSGeolocationProvider::mCallbacks = {
   sizeof(GpsCallbacks),
   LocationCallback,
   StatusCallback,
   SvStatusCallback,
   NmeaCallback,
@@ -60,28 +67,30 @@ GpsCallbacks GonkGPSGeolocationProvider:
   AcquireWakelockCallback,
   ReleaseWakelockCallback,
   CreateThreadCallback,
 #ifdef GPS_CAPABILITY_ON_DEMAND_TIME
   RequestUtcTimeCallback,
 #endif
 };
 
+#ifdef MOZ_B2G_RIL
 AGpsCallbacks
 GonkGPSGeolocationProvider::mAGPSCallbacks = {
   AGPSStatusCallback,
   CreateThreadCallback,
 };
 
 AGpsRilCallbacks
 GonkGPSGeolocationProvider::mAGPSRILCallbacks = {
   AGPSRILSetIDCallback,
   AGPSRILRefLocCallback,
   CreateThreadCallback,
 };
+#endif // MOZ_B2G_RIL
 
 void
 GonkGPSGeolocationProvider::LocationCallback(GpsLocation* location)
 {
   class UpdateLocationEvent : public nsRunnable {
   public:
     UpdateLocationEvent(nsGeoPosition* aPosition)
       : mPosition(aPosition)
@@ -141,18 +150,20 @@ GonkGPSGeolocationProvider::SetCapabilit
     UpdateCapabilitiesEvent(uint32_t aCapabilities)
       : mCapabilities(aCapabilities)
     {}
     NS_IMETHOD Run() {
       nsRefPtr<GonkGPSGeolocationProvider> provider =
         GonkGPSGeolocationProvider::GetSingleton();
 
       provider->mSupportsScheduling = mCapabilities & GPS_CAPABILITY_SCHEDULING;
+#ifdef MOZ_B2G_RIL
       provider->mSupportsMSB = mCapabilities & GPS_CAPABILITY_MSB;
       provider->mSupportsMSA = mCapabilities & GPS_CAPABILITY_MSA;
+#endif
       provider->mSupportsSingleShot = mCapabilities & GPS_CAPABILITY_SINGLE_SHOT;
 #ifdef GPS_CAPABILITY_ON_DEMAND_TIME
       provider->mSupportsTimeInjection = mCapabilities & GPS_CAPABILITY_ON_DEMAND_TIME;
 #endif
       return NS_OK;
     }
   private:
     uint32_t mCapabilities;
@@ -191,16 +202,17 @@ GonkGPSGeolocationProvider::CreateThread
   return thread;
 }
 
 void
 GonkGPSGeolocationProvider::RequestUtcTimeCallback()
 {
 }
 
+#ifdef MOZ_B2G_RIL
 void
 GonkGPSGeolocationProvider::AGPSStatusCallback(AGpsStatus* status)
 {
   MOZ_ASSERT(status);
 
   class AGPSStatusEvent : public nsRunnable {
   public:
     AGPSStatusEvent(AGpsStatusValue aStatus)
@@ -262,22 +274,25 @@ GonkGPSGeolocationProvider::AGPSRILRefLo
       return NS_OK;
     }
   };
 
   if (flags & AGPS_RIL_REQUEST_REFLOC_CELLID) {
     NS_DispatchToMainThread(new RequestRefLocEvent());
   }
 }
+#endif // MOZ_B2G_RIL
 
 GonkGPSGeolocationProvider::GonkGPSGeolocationProvider()
   : mStarted(false)
   , mSupportsScheduling(false)
+#ifdef MOZ_B2G_RIL
   , mSupportsMSB(false) 
   , mSupportsMSA(false) 
+#endif
   , mSupportsSingleShot(false)
   , mSupportsTimeInjection(false)
   , mGpsInterface(nullptr)
 {
 }
 
 GonkGPSGeolocationProvider::~GonkGPSGeolocationProvider()
 {
@@ -315,16 +330,17 @@ GonkGPSGeolocationProvider::GetGPSInterf
   const GpsInterface* result = gps_device->get_gps_interface(gps_device);
 
   if (result->size != sizeof(GpsInterface)) {
     return nullptr;
   }
   return result;
 }
 
+#ifdef MOZ_B2G_RIL
 int32_t
 GonkGPSGeolocationProvider::GetDataConnectionState()
 {
   if (!mRadioInterface) {
     return nsINetworkInterface::NETWORK_STATE_UNKNOWN;
   }
 
   int32_t state;
@@ -502,83 +518,91 @@ GonkGPSGeolocationProvider::SetReference
         }
       }
     }
     if (mAGpsRilInterface) {
       mAGpsRilInterface->set_ref_location(&location, sizeof(location));
     }
   }
 }
+#endif // MOZ_B2G_RIL
 
 void
 GonkGPSGeolocationProvider::Init()
 {
   // Must not be main thread. Some GPS driver's first init takes very long.
   MOZ_ASSERT(!NS_IsMainThread());
 
   mGpsInterface = GetGPSInterface();
   if (!mGpsInterface) {
     return;
   }
 
   if (mGpsInterface->init(&mCallbacks) != 0) {
     return;
   }
 
+#ifdef MOZ_B2G_RIL
   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);
   }
+#endif
 
   NS_DispatchToMainThread(NS_NewRunnableMethod(this, &GonkGPSGeolocationProvider::StartGPS));
 }
 
 void
 GonkGPSGeolocationProvider::StartGPS()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mGpsInterface);
 
   int32_t update = Preferences::GetInt("geo.default.update", kDefaultPeriod);
 
+#ifdef MOZ_B2G_RIL
   if (mSupportsMSA || mSupportsMSB) {
     SetupAGPS();
   }
+#endif
 
   int positionMode = GPS_POSITION_MODE_STANDALONE;
   bool singleShot = false;
 
+#ifdef MOZ_B2G_RIL
   // 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;
   }
+#endif
   if (!mSupportsScheduling) {
     update = kDefaultPeriod;
   }
 
   mGpsInterface->set_position_mode(positionMode,
                                    GPS_POSITION_RECURRENCE_PERIODIC,
                                    update, 0, 0);
 #if DEBUG_GPS
   // Delete cached data
   mGpsInterface->delete_aiding_data(GPS_DELETE_ALL);
 #endif
 
   mGpsInterface->start();
 }
 
+#ifdef MOZ_B2G_RIL
 void
 GonkGPSGeolocationProvider::SetupAGPS()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mAGpsInterface);
 
   const nsAdoptingCString& suplServer = Preferences::GetCString("geo.gps.supl_server");
   int32_t suplPort = Preferences::GetInt("geo.gps.supl_port", -1);
@@ -594,19 +618,18 @@ GonkGPSGeolocationProvider::SetupAGPS()
   if (ril) {
     // TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
     // MultiSIM configuration
     ril->GetRadioInterface(0 /* clientId */, getter_AddRefs(mRadioInterface));
     if (mRadioInterface) {
       mRadioInterface->RegisterDataCallCallback(this);
     }
   }
-
-  return;
 }
+#endif // MOZ_B2G_RIL
 
 NS_IMETHODIMP
 GonkGPSGeolocationProvider::Startup()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mStarted) {
     return NS_OK;
@@ -638,19 +661,21 @@ GonkGPSGeolocationProvider::Shutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!mStarted) {
     return NS_OK;
   }
   mStarted = false;
 
+#ifdef MOZ_B2G_RIL
   if (mRadioInterface) {
     mRadioInterface->UnregisterDataCallCallback(this);
   }
+#endif
 
   mInitThread->Dispatch(NS_NewRunnableMethod(this, &GonkGPSGeolocationProvider::ShutdownGPS),
                         NS_DISPATCH_NORMAL);
 
   return NS_OK;
 }
 
 void
@@ -665,16 +690,17 @@ GonkGPSGeolocationProvider::ShutdownGPS(
 }
 
 NS_IMETHODIMP
 GonkGPSGeolocationProvider::SetHighAccuracy(bool)
 {
   return NS_OK;
 }
 
+#ifdef MOZ_B2G_RIL
 /** nsIRILDataCallback interface **/
 
 NS_IMETHODIMP
 GonkGPSGeolocationProvider::DataCallStateChanged(nsIRILDataCallInfo* aDataCall)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aDataCall);
 
@@ -716,8 +742,9 @@ GonkGPSGeolocationProvider::Handle(const
   return NS_OK;
 }
 
 NS_IMETHODIMP
 GonkGPSGeolocationProvider::HandleError(const nsAString& aErrorMessage)
 {
   return NS_OK;
 }
+#endif // MOZ_B2G_RIL
--- a/dom/system/gonk/GonkGPSGeolocationProvider.h
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.h
@@ -15,37 +15,42 @@
  */
 
 #ifndef GonkGPSGeolocationProvider_h
 #define GonkGPSGeolocationProvider_h
 
 #include <hardware/gps.h> // for GpsInterface
 #include "nsCOMPtr.h"
 #include "nsIGeolocationProvider.h"
+#ifdef MOZ_B2G_RIL
 #include "nsIRadioInterfaceLayer.h"
-#include "nsString.h"
 #include "nsISettingsService.h"
+#endif
 
 class nsIThread;
 
 #define GONK_GPS_GEOLOCATION_PROVIDER_CID \
 { 0x48525ec5, 0x5a7f, 0x490a, { 0x92, 0x77, 0xba, 0x66, 0xe0, 0xd2, 0x2c, 0x8b } }
 
 #define GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID \
 "@mozilla.org/gonk-gps-geolocation-provider;1"
 
 class GonkGPSGeolocationProvider : public nsIGeolocationProvider
+#ifdef MOZ_B2G_RIL
                                  , public nsIRILDataCallback
                                  , public nsISettingsServiceCallback
+#endif
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIGEOLOCATIONPROVIDER
+#ifdef MOZ_B2G_RIL
   NS_DECL_NSIRILDATACALLBACK
   NS_DECL_NSISETTINGSSERVICECALLBACK
+#endif
 
   static already_AddRefed<GonkGPSGeolocationProvider> GetSingleton();
 
 private:
 
   /* Client should use GetSingleton() to get the provider instance. */
   GonkGPSGeolocationProvider();
   GonkGPSGeolocationProvider(const GonkGPSGeolocationProvider &);
@@ -56,49 +61,59 @@ private:
   static void StatusCallback(GpsStatus* status);
   static void SvStatusCallback(GpsSvStatus* sv_info);
   static void NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length);
   static void SetCapabilitiesCallback(uint32_t capabilities);
   static void AcquireWakelockCallback();
   static void ReleaseWakelockCallback();
   static pthread_t CreateThreadCallback(const char* name, void (*start)(void*), void* arg);
   static void RequestUtcTimeCallback();
+#ifdef MOZ_B2G_RIL
   static void AGPSStatusCallback(AGpsStatus* status);
   static void AGPSRILSetIDCallback(uint32_t flags);
   static void AGPSRILRefLocCallback(uint32_t flags);
+#endif
 
   static GpsCallbacks mCallbacks;
+#ifdef MOZ_B2G_RIL
   static AGpsCallbacks mAGPSCallbacks;
   static AGpsRilCallbacks mAGPSRILCallbacks;
+#endif
 
+  void Init();
+  void StartGPS();
+  void ShutdownGPS();
+#ifdef MOZ_B2G_RIL
+  void SetupAGPS();
   int32_t GetDataConnectionState();
   void SetAGpsDataConn(nsAString& aApn);
-  void RequestSettingValue(char* aKey);
-  void Init();
-  void SetupAGPS();
-  void StartGPS();
-  void ShutdownGPS();
   void RequestDataConnection();
   void ReleaseDataConnection();
+  void RequestSettingValue(char* aKey);
   void RequestSetID(uint32_t flags);
   void SetReferenceLocation();
+#endif
 
   const GpsInterface* GetGPSInterface();
 
   static GonkGPSGeolocationProvider* sSingleton;
 
   bool mStarted;
 
   bool mSupportsScheduling;
+#ifdef MOZ_B2G_RIL
   bool mSupportsMSB;
   bool mSupportsMSA;
+#endif
   bool mSupportsSingleShot;
   bool mSupportsTimeInjection;
 
   const GpsInterface* mGpsInterface;
+#ifdef MOZ_B2G_RIL
   const AGpsInterface* mAGpsInterface;
   const AGpsRilInterface* mAGpsRilInterface;
+  nsCOMPtr<nsIRadioInterface> mRadioInterface;
+#endif
   nsCOMPtr<nsIGeolocationUpdate> mLocationCallback;
   nsCOMPtr<nsIThread> mInitThread;
-  nsCOMPtr<nsIRadioInterface> mRadioInterface;
 };
 
 #endif /* GonkGPSGeolocationProvider_h */