123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- /* Copyright (c) 2011-2014, 2016-2018, 2020-2021 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted 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 The Linux Foundation, nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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_LocAdapterBase"
- #include <dlfcn.h>
- #include <LocAdapterBase.h>
- #include <loc_target.h>
- #include <log_util.h>
- #include <LocAdapterProxyBase.h>
- namespace loc_core {
- // This is the top level class, so the constructor will
- // always gets called. Here we prepare for the default.
- // But if getLocApi(targetEnumType target) is overriden,
- // the right locApi should get created.
- LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
- ContextBase* context, bool isMaster,
- LocAdapterProxyBase *adapterProxyBase,
- bool waitForDoneInit) :
- mIsMaster(isMaster), mEvtMask(mask), mContext(context),
- mLocApi(context->getLocApi()), mLocAdapterProxyBase(adapterProxyBase),
- mMsgTask(context->getMsgTask()),
- mIsEngineCapabilitiesKnown(ContextBase::sIsEngineCapabilitiesKnown)
- {
- LOC_LOGd("waitForDoneInit: %d", waitForDoneInit);
- if (!waitForDoneInit) {
- mLocApi->addAdapter(this);
- mAdapterAdded = true;
- } else {
- mAdapterAdded = false;
- }
- }
- uint32_t LocAdapterBase::mSessionIdCounter(1);
- uint32_t LocAdapterBase::generateSessionId()
- {
- if (++mSessionIdCounter == 0xFFFFFFFF)
- mSessionIdCounter = 1;
- return mSessionIdCounter;
- }
- void LocAdapterBase::handleEngineUpEvent()
- {
- if (mLocAdapterProxyBase) {
- mLocAdapterProxyBase->handleEngineUpEvent();
- }
- }
- void LocAdapterBase::handleEngineDownEvent()
- {
- if (mLocAdapterProxyBase) {
- mLocAdapterProxyBase->handleEngineDownEvent();
- }
- }
- void LocAdapterBase::
- reportPositionEvent(const UlpLocation& location,
- const GpsLocationExtended& locationExtended,
- enum loc_sess_status status,
- LocPosTechMask loc_technology_mask,
- GnssDataNotification* pDataNotify,
- int msInWeek)
- {
- if (mLocAdapterProxyBase != NULL) {
- mLocAdapterProxyBase->reportPositionEvent((UlpLocation&)location,
- (GpsLocationExtended&)locationExtended,
- status,
- loc_technology_mask);
- } else {
- DEFAULT_IMPL()
- }
- }
- void LocAdapterBase::
- reportSvEvent(const GnssSvNotification& /*svNotify*/)
- DEFAULT_IMPL()
- void LocAdapterBase::
- reportSvPolynomialEvent(GnssSvPolynomial &/*svPolynomial*/)
- DEFAULT_IMPL()
- void LocAdapterBase::
- reportSvEphemerisEvent(GnssSvEphemerisReport &/*svEphemeris*/)
- DEFAULT_IMPL()
- void LocAdapterBase::
- reportStatus(LocGpsStatusValue /*status*/)
- DEFAULT_IMPL()
- void LocAdapterBase::
- reportNmeaEvent(const char* /*nmea*/, size_t /*length*/)
- DEFAULT_IMPL()
- void LocAdapterBase::
- reportDataEvent(const GnssDataNotification& /*dataNotify*/,
- int /*msInWeek*/)
- DEFAULT_IMPL()
- bool LocAdapterBase::
- reportXtraServer(const char* /*url1*/, const char* /*url2*/,
- const char* /*url3*/, const int /*maxlength*/)
- DEFAULT_IMPL(false)
- void LocAdapterBase::
- reportLocationSystemInfoEvent(const LocationSystemInfo& /*locationSystemInfo*/)
- DEFAULT_IMPL()
- bool LocAdapterBase::
- requestXtraData()
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- requestTime()
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- requestLocation()
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- requestATL(int /*connHandle*/, LocAGpsType /*agps_type*/,
- LocApnTypeMask /*apn_type_mask*/, LocSubId /*sub_id*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- releaseATL(int /*connHandle*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- requestNiNotifyEvent(const GnssNiNotification &/*notify*/,
- const void* /*data*/,
- const LocInEmergency emergencyState)
- DEFAULT_IMPL(false)
- void LocAdapterBase::
- reportGnssMeasurementsEvent(const GnssMeasurements& /*gnssMeasurements*/,
- int /*msInWeek*/)
- DEFAULT_IMPL()
- bool LocAdapterBase::
- reportWwanZppFix(LocGpsLocation &/*zppLoc*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- reportZppBestAvailableFix(LocGpsLocation& /*zppLoc*/,
- GpsLocationExtended& /*location_extended*/, LocPosTechMask /*tech_mask*/)
- DEFAULT_IMPL(false)
- void LocAdapterBase::reportGnssSvIdConfigEvent(const GnssSvIdConfig& /*config*/)
- DEFAULT_IMPL()
- void LocAdapterBase::reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& /*config*/)
- DEFAULT_IMPL()
- void LocAdapterBase::reportGnssConfigEvent(uint32_t, /* session id*/
- const GnssConfig& /*gnssConfig*/)
- DEFAULT_IMPL()
- bool LocAdapterBase::
- requestOdcpiEvent(OdcpiRequestInfo& /*request*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- reportGnssEngEnergyConsumedEvent(uint64_t /*energyConsumedSinceFirstBoot*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- reportDeleteAidingDataEvent(GnssAidingData & /*aidingData*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- reportKlobucharIonoModelEvent(GnssKlobucharIonoModel& /*ionoModel*/)
- DEFAULT_IMPL(false)
- bool LocAdapterBase::
- reportGnssAdditionalSystemInfoEvent(GnssAdditionalSystemInfo& /*additionalSystemInfo*/)
- DEFAULT_IMPL(false)
- void LocAdapterBase::
- reportNfwNotificationEvent(GnssNfwNotification& /*notification*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::geofenceBreachEvent(size_t /*count*/, uint32_t* /*hwIds*/, Location& /*location*/,
- GeofenceBreachType /*breachType*/, uint64_t /*timestamp*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::geofenceStatusEvent(GeofenceStatusAvailable /*available*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::reportLocationsEvent(const Location* /*locations*/, size_t /*count*/,
- BatchingMode /*batchingMode*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::reportCompletedTripsEvent(uint32_t /*accumulated_distance*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::reportBatchStatusChangeEvent(BatchingStatus /*batchStatus*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::reportPositionEvent(UlpLocation& /*location*/,
- GpsLocationExtended& /*locationExtended*/,
- enum loc_sess_status /*status*/,
- LocPosTechMask /*loc_technology_mask*/)
- DEFAULT_IMPL()
- void
- LocAdapterBase::saveClient(LocationAPI* client, const LocationCallbacks& callbacks)
- {
- mClientData[client] = callbacks;
- updateClientsEventMask();
- }
- void
- LocAdapterBase::eraseClient(LocationAPI* client)
- {
- auto it = mClientData.find(client);
- if (it != mClientData.end()) {
- mClientData.erase(it);
- }
- updateClientsEventMask();
- }
- LocationCallbacks
- LocAdapterBase::getClientCallbacks(LocationAPI* client)
- {
- LocationCallbacks callbacks = {};
- auto it = mClientData.find(client);
- if (it != mClientData.end()) {
- callbacks = it->second;
- }
- return callbacks;
- }
- LocationCapabilitiesMask
- LocAdapterBase::getCapabilities()
- {
- LocationCapabilitiesMask mask = 0;
- if (isEngineCapabilitiesKnown()) {
- // time based tracking always supported
- mask |= LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT;
- if (ContextBase::isMessageSupported(
- LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)){
- mask |= LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT |
- LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT;
- }
- if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) {
- mask |= LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT;
- }
- if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING)) {
- mask |= LOCATION_CAPABILITIES_OUTDOOR_TRIP_BATCHING_BIT;
- }
- // geofence always supported
- mask |= LOCATION_CAPABILITIES_GEOFENCE_BIT;
- if (ContextBase::gnssConstellationConfig()) {
- mask |= LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT;
- }
- uint32_t carrierCapabilities = ContextBase::getCarrierCapabilities();
- if (carrierCapabilities & LOC_GPS_CAPABILITY_MSB) {
- mask |= LOCATION_CAPABILITIES_GNSS_MSB_BIT;
- }
- if (LOC_GPS_CAPABILITY_MSA & carrierCapabilities) {
- mask |= LOCATION_CAPABILITIES_GNSS_MSA_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
- mask |= LOCATION_CAPABILITIES_DEBUG_NMEA_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) {
- mask |= LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_AGPM_V02)) {
- mask |= LOCATION_CAPABILITIES_AGPM_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_LOCATION_PRIVACY)) {
- mask |= LOCATION_CAPABILITIES_PRIVACY_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION)) {
- mask |= LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_ROBUST_LOCATION)) {
- mask |= LOCATION_CAPABILITIES_CONFORMITY_INDEX_BIT;
- }
- if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_EDGNSS) ||
- (ContextBase::getQwesFeatureStatus() & LOCATION_CAPABILITIES_QWES_DGNSS)) {
- mask |= LOCATION_CAPABILITIES_EDGNSS_BIT;
- }
- if ((ContextBase::getQwesFeatureStatus() & LOCATION_CAPABILITIES_QWES_PPE)) {
- mask |= LOCATION_CAPABILITIES_QWES_PPE;
- }
- } else {
- LOC_LOGE("%s]: attempt to get capabilities before they are known.", __func__);
- }
- return mask;
- }
- void
- LocAdapterBase::broadcastCapabilities(LocationCapabilitiesMask mask)
- {
- for (auto clientData : mClientData) {
- if (nullptr != clientData.second.capabilitiesCb) {
- clientData.second.capabilitiesCb(mask);
- }
- }
- }
- void
- LocAdapterBase::updateClientsEventMask()
- DEFAULT_IMPL()
- void
- LocAdapterBase::stopClientSessions(LocationAPI* client, bool eraseSession)
- DEFAULT_IMPL()
- void
- LocAdapterBase::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks)
- {
- LOC_LOGD("%s]: client %p", __func__, client);
- struct MsgAddClient : public LocMsg {
- LocAdapterBase& mAdapter;
- LocationAPI* mClient;
- const LocationCallbacks mCallbacks;
- inline MsgAddClient(LocAdapterBase& adapter,
- LocationAPI* client,
- const LocationCallbacks& callbacks) :
- LocMsg(),
- mAdapter(adapter),
- mClient(client),
- mCallbacks(callbacks) {}
- inline virtual void proc() const {
- mAdapter.saveClient(mClient, mCallbacks);
- }
- };
- sendMsg(new MsgAddClient(*this, client, callbacks));
- }
- void
- LocAdapterBase::removeClientCommand(LocationAPI* client,
- removeClientCompleteCallback rmClientCb)
- {
- LOC_LOGD("%s]: client %p", __func__, client);
- struct MsgRemoveClient : public LocMsg {
- LocAdapterBase& mAdapter;
- LocationAPI* mClient;
- removeClientCompleteCallback mRmClientCb;
- inline MsgRemoveClient(LocAdapterBase& adapter,
- LocationAPI* client,
- removeClientCompleteCallback rmCb) :
- LocMsg(),
- mAdapter(adapter),
- mClient(client),
- mRmClientCb(rmCb){}
- inline virtual void proc() const {
- mAdapter.stopClientSessions(mClient);
- mAdapter.eraseClient(mClient);
- if (nullptr != mRmClientCb) {
- (mRmClientCb)(mClient);
- }
- }
- };
- sendMsg(new MsgRemoveClient(*this, client, rmClientCb));
- }
- void
- LocAdapterBase::requestCapabilitiesCommand(LocationAPI* client)
- {
- LOC_LOGD("%s]: ", __func__);
- struct MsgRequestCapabilities : public LocMsg {
- LocAdapterBase& mAdapter;
- LocationAPI* mClient;
- inline MsgRequestCapabilities(LocAdapterBase& adapter,
- LocationAPI* client) :
- LocMsg(),
- mAdapter(adapter),
- mClient(client) {}
- inline virtual void proc() const {
- if (!mAdapter.isEngineCapabilitiesKnown()) {
- mAdapter.mPendingMsgs.push_back(new MsgRequestCapabilities(*this));
- return;
- }
- LocationCallbacks callbacks = mAdapter.getClientCallbacks(mClient);
- if (callbacks.capabilitiesCb != nullptr) {
- callbacks.capabilitiesCb(mAdapter.getCapabilities());
- }
- }
- };
- sendMsg(new MsgRequestCapabilities(*this, client));
- }
- void
- LocAdapterBase::reportLatencyInfoEvent(const GnssLatencyInfo& /*gnssLatencyInfo*/)
- DEFAULT_IMPL()
- bool LocAdapterBase::
- reportQwesCapabilities(const std::unordered_map<LocationQwesFeatureType, bool> &featureMap)
- DEFAULT_IMPL(false)
- } // namespace loc_core
|