diff --git a/gps/android/1.1/Gnss.cpp b/gps/android/1.1/Gnss.cpp index e67d877..5417e69 100644 --- a/gps/android/1.1/Gnss.cpp +++ b/gps/android/1.1/Gnss.cpp @@ -390,7 +390,8 @@ Return Gnss::setCallback_1_1(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } return setCallback(callback); } diff --git a/gps/android/2.0/Gnss.cpp b/gps/android/2.0/Gnss.cpp index dfdbe1b..108f626 100644 --- a/gps/android/2.0/Gnss.cpp +++ b/gps/android/2.0/Gnss.cpp @@ -459,7 +459,8 @@ Return Gnss::setCallback_1_1(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } GnssAPIClient* api = getApi(); @@ -593,7 +594,8 @@ Return Gnss::setCallback_2_0(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } GnssAPIClient* api = getApi(); diff --git a/gps/android/2.1/Gnss.cpp b/gps/android/2.1/Gnss.cpp index 7ea2a42..ea3a48e 100644 --- a/gps/android/2.1/Gnss.cpp +++ b/gps/android/2.1/Gnss.cpp @@ -474,7 +474,8 @@ Return Gnss::setCallback_1_1(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } GnssAPIClient* api = getApi(); @@ -626,7 +627,8 @@ Return Gnss::setCallback_2_0(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } GnssAPIClient* api = getApi(); @@ -765,7 +767,8 @@ Return Gnss::setCallback_2_1(const sp& callback) { OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { odcpiRequestCb(odcpiRequest); }; - gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW, + (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI)); } GnssAPIClient* api = getApi(); diff --git a/gps/gnss/GnssAdapter.cpp b/gps/gnss/GnssAdapter.cpp index 0c7b164..6b2a1af 100644 --- a/gps/gnss/GnssAdapter.cpp +++ b/gps/gnss/GnssAdapter.cpp @@ -5119,7 +5119,7 @@ void GnssAdapter::requestOdcpi(const OdcpiRequestInfo& request) // extending the odcpi session past 30 seconds if needed if (ODCPI_REQUEST_TYPE_START == request.type) { if (!(mOdcpiStateMask & ODCPI_REQ_ACTIVE) && false == mOdcpiTimer.isActive()) { - mOdcpiRequestCb(request); + fireOdcpiRequest(request); mOdcpiStateMask |= ODCPI_REQ_ACTIVE; mOdcpiTimer.start(); sendEmergencyCallStatusEvent = true; @@ -5128,7 +5128,7 @@ void GnssAdapter::requestOdcpi(const OdcpiRequestInfo& request) // and restart the timer } else if (false == mOdcpiRequest.isEmergencyMode && true == request.isEmergencyMode) { - mOdcpiRequestCb(request); + fireOdcpiRequest(request); mOdcpiStateMask |= ODCPI_REQ_ACTIVE; if (true == mOdcpiTimer.isActive()) { mOdcpiTimer.restart(); @@ -5153,7 +5153,7 @@ void GnssAdapter::requestOdcpi(const OdcpiRequestInfo& request) // to avoid spamming more odcpi requests to the framework } else if (ODCPI_REQUEST_TYPE_STOP == request.type) { LOC_LOGd("request: type %d, isEmergency %d", request.type, request.isEmergencyMode); - mOdcpiRequestCb(request); + fireOdcpiRequest(request); mOdcpiStateMask = 0; sendEmergencyCallStatusEvent = true; } else { @@ -5222,36 +5222,84 @@ bool GnssAdapter::reportQwesCapabilities( } void GnssAdapter::initOdcpiCommand(const OdcpiRequestCallback& callback, - OdcpiPrioritytype priority) + OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask) { struct MsgInitOdcpi : public LocMsg { GnssAdapter& mAdapter; OdcpiRequestCallback mOdcpiCb; OdcpiPrioritytype mPriority; + OdcpiCallbackTypeMask mTypeMask; inline MsgInitOdcpi(GnssAdapter& adapter, const OdcpiRequestCallback& callback, - OdcpiPrioritytype priority) : + OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask) : LocMsg(), mAdapter(adapter), - mOdcpiCb(callback), mPriority(priority){} + mOdcpiCb(callback), mPriority(priority), + mTypeMask(typeMask) {} inline virtual void proc() const { - mAdapter.initOdcpi(mOdcpiCb, mPriority); + mAdapter.initOdcpi(mOdcpiCb, mPriority, mTypeMask); } }; - sendMsg(new MsgInitOdcpi(*this, callback, priority)); + sendMsg(new MsgInitOdcpi(*this, callback, priority, typeMask)); +} + +void GnssAdapter::deRegisterOdcpiCommand(OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask) { + struct MsgDeRegisterNonEsOdcpi : public LocMsg { + GnssAdapter& mAdapter; + OdcpiPrioritytype mPriority; + OdcpiCallbackTypeMask mTypeMask; + inline MsgDeRegisterNonEsOdcpi(GnssAdapter& adapter, + OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask) : + LocMsg(), + mAdapter(adapter), + mPriority(priority), + mTypeMask(typeMask) {} + inline virtual void proc() const { + mAdapter.deRegisterOdcpi(mPriority, mTypeMask); + } + }; + + sendMsg(new MsgDeRegisterNonEsOdcpi(*this, priority, typeMask)); +} + +void GnssAdapter::fireOdcpiRequest(const OdcpiRequestInfo& request) { + if (request.isEmergencyMode) { + mOdcpiRequestCb(request); + } else { + std::unordered_map::iterator iter; + for (int priority = ODCPI_HANDLER_PRIORITY_HIGH; + priority >= ODCPI_HANDLER_PRIORITY_LOW && iter == mNonEsOdcpiReqCbMap.end(); + priority--) { + iter = mNonEsOdcpiReqCbMap.find((OdcpiPrioritytype)priority); + } + if (iter != mNonEsOdcpiReqCbMap.end()) { + iter->second(request); + } + } } void GnssAdapter::initOdcpi(const OdcpiRequestCallback& callback, - OdcpiPrioritytype priority) -{ - LOC_LOGd("In priority: %d, Curr priority: %d", priority, mCallbackPriority); - if (priority >= mCallbackPriority) { - mOdcpiRequestCb = callback; - mCallbackPriority = priority; - /* Register for WIFI request */ - updateEvtMask(LOC_API_ADAPTER_BIT_REQUEST_WIFI, - LOC_REGISTRATION_MASK_ENABLED); + OdcpiPrioritytype priority, OdcpiCallbackTypeMask typeMask) { + if (typeMask & EMERGENCY_ODCPI) { + LOC_LOGd("In priority: %d, Curr priority: %d", priority, mCallbackPriority); + if (priority >= mCallbackPriority) { + mOdcpiRequestCb = callback; + mCallbackPriority = priority; + /* Register for WIFI request */ + updateEvtMask(LOC_API_ADAPTER_BIT_REQUEST_WIFI, + LOC_REGISTRATION_MASK_ENABLED); + } + } + if (typeMask & NON_EMERGENCY_ODCPI) { + //If this is for non emergency odcpi, + //Only set callback to mNonEsOdcpiReqCbMap according to its priority + //Will overwrite callback with same priority in this map + mNonEsOdcpiReqCbMap[priority] = callback; } } @@ -5373,7 +5421,7 @@ void GnssAdapter::odcpiTimerExpire() // if ODCPI request is still active after timer // expires, request again and restart timer if (mOdcpiStateMask & ODCPI_REQ_ACTIVE) { - mOdcpiRequestCb(mOdcpiRequest); + fireOdcpiRequest(mOdcpiRequest); mOdcpiTimer.restart(); } else { mOdcpiTimer.stop(); diff --git a/gps/gnss/GnssAdapter.h b/gps/gnss/GnssAdapter.h index cbfe58f..bd0bd98 100644 --- a/gps/gnss/GnssAdapter.h +++ b/gps/gnss/GnssAdapter.h @@ -79,6 +79,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #define MAX_URL_LEN 256 #define NMEA_SENTENCE_MAX_LENGTH 200 @@ -303,6 +304,7 @@ class GnssAdapter : public LocAdapterBase { OdcpiPrioritytype mCallbackPriority; OdcpiTimer mOdcpiTimer; OdcpiRequestInfo mOdcpiRequest; + std::unordered_map mNonEsOdcpiReqCbMap; void odcpiTimerExpire(); std::function mAddressRequestCb; @@ -344,8 +346,16 @@ class GnssAdapter : public LocAdapterBase { int totalSvCntInThisConstellation); /* ======== UTILITIES ================================================================== */ - inline void initOdcpi(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); + inline void initOdcpi(const OdcpiRequestCallback& callback, + OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask); + inline void deRegisterOdcpi(OdcpiPrioritytype priority, OdcpiCallbackTypeMask typeMask) { + if (typeMask & NON_EMERGENCY_ODCPI) { + mNonEsOdcpiReqCbMap.erase(priority); + } + } inline void injectOdcpi(const Location& location); + void fireOdcpiRequest(const OdcpiRequestInfo& request); inline void setAddressRequestCb(const std::function& addressRequestCb) { mAddressRequestCb = addressRequestCb;} inline void injectLocationAndAddr(const Location& location, const GnssCivicAddress& addr) @@ -523,7 +533,10 @@ public: /* ========= ODCPI ===================================================================== */ /* ======== COMMANDS ====(Called from Client Thread)==================================== */ - void initOdcpiCommand(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); + void initOdcpiCommand(const OdcpiRequestCallback& callback, + OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask); + void deRegisterOdcpiCommand(OdcpiPrioritytype priority, OdcpiCallbackTypeMask typeMask); void injectOdcpiCommand(const Location& location); void setAddressRequestCbCommand(const std::function& addressRequestCb); void injectLocationAndAddrCommand(const Location& location, const GnssCivicAddress& addr); diff --git a/gps/gnss/location_gnss.cpp b/gps/gnss/location_gnss.cpp index 2a40c6b..ad178a8 100644 --- a/gps/gnss/location_gnss.cpp +++ b/gps/gnss/location_gnss.cpp @@ -27,6 +27,42 @@ * */ +/* +Changes from Qualcomm Innovation Center are provided under the following license: + +Copyright (c) 2022, 2023 Qualcomm Innovation Center, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the +disclaimer below) provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE +GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT +HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + #include "GnssAdapter.h" #include "location_interface.h" @@ -75,7 +111,9 @@ static void enableNfwLocationAccess(std::vector& enabledNfws); static void nfwInit(const NfwCbInfo& cbInfo); static void getPowerStateChanges(std::function powerStateCb); -static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); +static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask); +static void deRegisterOdcpi(OdcpiPrioritytype priority, OdcpiCallbackTypeMask typeMask); static void odcpiInject(const Location& location); static void blockCPI(double latitude, double longitude, float accuracy, @@ -142,6 +180,7 @@ static const GnssInterface gGnssInterface = { getDebugReport, updateConnectionStatus, odcpiInit, + deRegisterOdcpi, odcpiInject, blockCPI, getGnssEnergyConsumed, @@ -404,10 +443,17 @@ static void updateConnectionStatus(bool connected, int8_t type, } } -static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority) +static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority, + OdcpiCallbackTypeMask typeMask) { if (NULL != gGnssAdapter) { - gGnssAdapter->initOdcpiCommand(callback, priority); + gGnssAdapter->initOdcpiCommand(callback, priority, typeMask); + } +} + +static void deRegisterOdcpi(OdcpiPrioritytype priority, OdcpiCallbackTypeMask typeMask) { + if (NULL != gGnssAdapter) { + gGnssAdapter->deRegisterOdcpiCommand(priority, typeMask); } } diff --git a/gps/location/LocationAPI.cpp b/gps/location/LocationAPI.cpp index 408e0b9..f5fcf57 100644 --- a/gps/location/LocationAPI.cpp +++ b/gps/location/LocationAPI.cpp @@ -25,6 +25,42 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* +Changes from Qualcomm Innovation Center are provided under the following license: + +Copyright (c) 2022, 2023 Qualcomm Innovation Center, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the +disclaimer below) provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE +GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT +HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + #define LOG_NDEBUG 0 #define LOG_TAG "LocSvc_LocationAPI" diff --git a/gps/location/LocationDataTypes.h b/gps/location/LocationDataTypes.h index b34dc9b..215b255 100644 --- a/gps/location/LocationDataTypes.h +++ b/gps/location/LocationDataTypes.h @@ -2097,6 +2097,20 @@ enum GnssNmeaTypesMask { NMEA_TYPE_ALL = 0xffffffff, }; +/* Specify the Geodetic datum for NMEA sentence types that + * are generated by GNSS stack on HLOS. + * + * Please note that this setting is only applicable if + * NMEA_PROVIDER in gps.conf is set to 0 to use HLOS + * generated NMEA. */ +enum GnssGeodeticDatumType { + // Geodetic datum defined in World Geodetic System 1984 (WGS84) format. + GEODETIC_TYPE_WGS_84 = 0, + // Geodetic datum defined for use in the GLONASS system. + GEODETIC_TYPE_PZ_90 = 1, +}; + + /* Provides the capabilities of the system capabilities callback is called once soon after createInstance is called */ typedef std::function OdcpiRequestCallbac /* ODCPI callback priorities*/ enum OdcpiPrioritytype { + //ODCPI callback registered by AFW via IGNSS AIDL has LOW priority ODCPI_HANDLER_PRIORITY_LOW, + ODCPI_HANDLER_PRIORITY_DEFAULT = ODCPI_HANDLER_PRIORITY_LOW, + //ODCPI callback registered by IzatProvider on LE/KaiOS has medium priority + ODCPI_HANDLER_PRIORITY_MEDIUM, + //Non emergency ODCPI callback registered by IzatManager for RTT position injection + //has high priority ODCPI_HANDLER_PRIORITY_HIGH }; + /* * Callback with AGNSS(IpV4) status information. *