diff --git a/android/AGnss.cpp b/android/AGnss.cpp index c497ed49..b5f76bbe 100644 --- a/android/AGnss.cpp +++ b/android/AGnss.cpp @@ -51,7 +51,11 @@ Return AGnss::setCallback(const sp& callback) { // Save the interface sAGnssCbIface = callback; - mGnss->getGnssInterface()->agpsInit((void*)agnssStatusIpV4Cb); + AgpsCbInfo cbInfo = {}; + cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + cbInfo.cbPriority = AGPS_CB_PRIORITY_LOW; + + mGnss->getGnssInterface()->agpsInit(cbInfo); return Void(); } diff --git a/android/location_api/BatchingAPIClient.cpp b/android/location_api/BatchingAPIClient.cpp index 2f3e8bd2..4c2c5f05 100644 --- a/android/location_api/BatchingAPIClient.cpp +++ b/android/location_api/BatchingAPIClient.cpp @@ -54,6 +54,7 @@ BatchingAPIClient::BatchingAPIClient(const sp& callback) LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); locationCallbacks.size = sizeof(LocationCallbacks); locationCallbacks.trackingCb = nullptr; diff --git a/android/location_api/GeofenceAPIClient.cpp b/android/location_api/GeofenceAPIClient.cpp index 7bd3bd42..61671771 100644 --- a/android/location_api/GeofenceAPIClient.cpp +++ b/android/location_api/GeofenceAPIClient.cpp @@ -50,6 +50,7 @@ GeofenceAPIClient::GeofenceAPIClient(const sp& callback) LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); locationCallbacks.size = sizeof(LocationCallbacks); locationCallbacks.trackingCb = nullptr; diff --git a/android/location_api/GnssAPIClient.cpp b/android/location_api/GnssAPIClient.cpp index 7acfbd70..852edfb3 100644 --- a/android/location_api/GnssAPIClient.cpp +++ b/android/location_api/GnssAPIClient.cpp @@ -35,6 +35,7 @@ #include "LocationUtil.h" #include "GnssAPIClient.h" +#include namespace android { namespace hardware { @@ -79,6 +80,7 @@ void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, mGnssNiCbIface = niCb; LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); locationCallbacks.size = sizeof(LocationCallbacks); locationCallbacks.trackingCb = nullptr; @@ -94,7 +96,12 @@ void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, locationCallbacks.gnssLocationInfoCb = nullptr; locationCallbacks.gnssNiCb = nullptr; - if (mGnssNiCbIface != nullptr) { + loc_core::ContextBase* context = + loc_core::LocDualContext::getLocFgContext( + NULL, NULL, + loc_core::LocDualContext::mLocationHalName, false); + if (mGnssNiCbIface != nullptr && !context->hasAgpsExtendedCapabilities()) { + LOC_LOGD("Registering NI CB"); locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotification) { onGnssNiCb(id, gnssNiNotification); }; diff --git a/android/location_api/MeasurementAPIClient.cpp b/android/location_api/MeasurementAPIClient.cpp index 468c77a9..e3ae9ad3 100644 --- a/android/location_api/MeasurementAPIClient.cpp +++ b/android/location_api/MeasurementAPIClient.cpp @@ -80,6 +80,7 @@ MeasurementAPIClient::measurementSetCallback(const sp& mGnssMeasurementCbIface = callback; LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); locationCallbacks.size = sizeof(LocationCallbacks); locationCallbacks.trackingCb = nullptr; diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index ca34d8cc..1e15bd33 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -62,7 +62,8 @@ GnssAdapter::GnssAdapter() : mControlCallbacks(), mPowerVoteId(0), mNiData(), - mAgpsManager() + mAgpsManager(), + mAgpsCbInfo() { LOC_LOGD("%s]: Constructor %p", __func__, this); mUlpPositionMode.mode = LOC_POSITION_MODE_INVALID; @@ -2301,7 +2302,7 @@ GnssAdapter::reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial) } /* INIT LOC AGPS MANAGER */ -void GnssAdapter::initAgpsCommand(void* statusV4Cb){ +void GnssAdapter::initAgpsCommand(const AgpsCbInfo& cbInfo){ LOC_LOGI("GnssAdapter::initAgpsCommand"); @@ -2416,10 +2417,20 @@ void GnssAdapter::initAgpsCommand(void* statusV4Cb){ } }; + if (mAgpsCbInfo.cbPriority > cbInfo.cbPriority) { + LOC_LOGI("Higher priority AGPS CB already registered (%d > %d) !", + mAgpsCbInfo.cbPriority, cbInfo.cbPriority); + return; + } else { + mAgpsCbInfo = cbInfo; + LOC_LOGI("Registering AGPS CB 0x%x with priority %d", + mAgpsCbInfo.statusV4Cb, mAgpsCbInfo.cbPriority); + } + /* Send message to initialize AGPS Manager */ sendMsg(new AgpsMsgInit( &mAgpsManager, - (AgpsFrameworkInterface::AgnssStatusIpV4Cb)statusV4Cb, + (AgpsFrameworkInterface::AgnssStatusIpV4Cb)cbInfo.statusV4Cb, atlOpenStatusCb, atlCloseStatusCb, dsClientInitFn, dsClientOpenAndStartDataCallFn, dsClientStopDataCallFn, dsClientCloseDataCallFn, diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 3d27e424..3b300474 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -99,6 +99,7 @@ class GnssAdapter : public LocAdapterBase { /* ==== AGPS ========================================================*/ // This must be initialized via initAgps() AgpsManager mAgpsManager; + AgpsCbInfo mAgpsCbInfo; /*==== CONVERSION ===================================================================*/ static void convertOptions(LocPosMode& out, const LocationOptions& options); @@ -185,7 +186,7 @@ public: uint32_t* gnssUpdateConfigCommand(GnssConfig config); uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data); - void initAgpsCommand(void* statusV4Cb); + void initAgpsCommand(const AgpsCbInfo& cbInfo); void dataConnOpenCommand( AGpsExtType agpsType, const char* apnName, int apnLen, LocApnIpType ipType); diff --git a/gnss/location_gnss.cpp b/gnss/location_gnss.cpp index 0f905fd7..0cd8e8d2 100644 --- a/gnss/location_gnss.cpp +++ b/gnss/location_gnss.cpp @@ -54,7 +54,7 @@ static uint32_t* gnssUpdateConfig(GnssConfig config); static void injectLocation(double latitude, double longitude, float accuracy); static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty); -static void agpsInit(void* statusV4Cb); +static void agpsInit(const AgpsCbInfo& cbInfo); static void agpsDataConnOpen(AGpsExtType agpsType, const char* apnName, int apnLen, int ipType); static void agpsDataConnClosed(AGpsExtType agpsType); static void agpsDataConnFailed(AGpsExtType agpsType); @@ -215,10 +215,10 @@ static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty) } } -static void agpsInit(void* statusV4Cb) { +static void agpsInit(const AgpsCbInfo& cbInfo) { if (NULL != gGnssAdapter) { - gGnssAdapter->initAgpsCommand(statusV4Cb); + gGnssAdapter->initAgpsCommand(cbInfo); } } static void agpsDataConnOpen( diff --git a/location/location_interface.h b/location/location_interface.h index 86febd31..c93f135c 100644 --- a/location/location_interface.h +++ b/location/location_interface.h @@ -30,6 +30,7 @@ #define LOCATION_INTERFACE_H #include +#include struct GnssInterface { size_t size; @@ -49,7 +50,7 @@ struct GnssInterface { uint32_t (*gnssDeleteAidingData)(GnssAidingData& data); void (*injectLocation)(double latitude, double longitude, float accuracy); void (*injectTime)(int64_t time, int64_t timeReference, int32_t uncertainty); - void (*agpsInit)(void* statusV4Cb); + void (*agpsInit)(const AgpsCbInfo& cbInfo); void (*agpsDataConnOpen)(short agpsType, const char* apnName, int apnLen, int ipType); void (*agpsDataConnClosed)(short agpsType); void (*agpsDataConnFailed)(short agpsType); diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index 40e87fb4..b8acead2 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -160,6 +160,17 @@ typedef int16_t AGpsBearerType; #define AGPS_APN_BEARER_IPV6 1 #define AGPS_APN_BEARER_IPV4V6 2 +typedef enum { + AGPS_CB_PRIORITY_LOW = 1, + AGPS_CB_PRIORITY_MED = 2, + AGPS_CB_PRIORITY_HIGH = 3 +} AgpsCbPriority; + +typedef struct { + void* statusV4Cb; + AgpsCbPriority cbPriority; +} AgpsCbInfo; + /** GPS extended callback structure. */ typedef struct { /** set to sizeof(LocGpsCallbacks) */