From 4145243b7e08a7bb423662bea92c726f9f924578 Mon Sep 17 00:00:00 2001 From: Dante Russo Date: Thu, 5 Apr 2018 17:54:50 -0700 Subject: [PATCH 01/22] Assure event mask is set properly to get positions The event mask can be retrieved in the context of client thread as zero and then queued up to go to msg task thread. By the time the msg is actually handled in msg task thread, the actual event mask at LOC API layer may have already changed, but this mask would then be overridden by zero. This can cause no modem events to ever come, including position reports. The fix is to not retrieve the event mask in the client thread, but instead wait for msg to be handled in msg task thread before retrieving it. Change-Id: I48562d028bbfa187732686c060b5cdd62c6d5a89 CRs-fixed: 2219519 --- core/LocApiBase.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 1e326d94..956c6f10 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -107,19 +107,16 @@ struct LocSsrMsg : public LocMsg { struct LocOpenMsg : public LocMsg { LocApiBase* mLocApi; - LOC_API_ADAPTER_EVENT_MASK_T mMask; - inline LocOpenMsg(LocApiBase* locApi, - LOC_API_ADAPTER_EVENT_MASK_T mask) : - LocMsg(), mLocApi(locApi), mMask(mask) + inline LocOpenMsg(LocApiBase* locApi) : + LocMsg(), mLocApi(locApi) { locallog(); } inline virtual void proc() const { - mLocApi->open(mMask); + mLocApi->open(mLocApi->getEvtMask()); } inline void locallog() const { - LOC_LOGV("%s:%d]: LocOpen Mask: %" PRIu64 "\n", - __func__, __LINE__, mMask); + LOC_LOGv("LocOpen Mask: %" PRIx64 "\n", mLocApi->getEvtMask()); } inline virtual void log() const { locallog(); @@ -163,8 +160,7 @@ void LocApiBase::addAdapter(LocAdapterBase* adapter) for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { if (mLocAdapters[i] == NULL) { mLocAdapters[i] = adapter; - mMsgTask->sendMsg(new LocOpenMsg(this, - mMask | adapter->getEvtMask())); + mMsgTask->sendMsg(new LocOpenMsg(this)); break; } } @@ -200,7 +196,7 @@ void LocApiBase::removeAdapter(LocAdapterBase* adapter) close(); } else { // else we need to remove the bit - mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask())); + mMsgTask->sendMsg(new LocOpenMsg(this)); } } } From 49b42e8ce57f506745bf18f68a48a7304a02d09a Mon Sep 17 00:00:00 2001 From: Saurabh Srivastava Date: Sun, 8 Apr 2018 23:35:14 +0530 Subject: [PATCH 02/22] FR 48850 - Device based hybrid ODCPI Adding support for sending ODCPI request to framework via IGnss interface. Change-Id: I97ab4f00505705fedc266998602499fd344baf31 CRs-Fixed: 2217664 --- android/Gnss.cpp | 37 ++++++++- android/Gnss.h | 4 + android/location_api/LocationUtil.cpp | 31 +++++++ android/location_api/LocationUtil.h | 1 + core/LocAdapterBase.cpp | 4 + core/LocAdapterBase.h | 1 + core/LocApiBase.cpp | 10 +++ core/LocApiBase.h | 3 + gnss/GnssAdapter.cpp | 111 ++++++++++++++++++++++++++ gnss/GnssAdapter.h | 18 ++++- gnss/location_gnss.cpp | 20 +++++ location/location_interface.h | 2 + utils/gps_extended_c.h | 14 ++++ 13 files changed, 254 insertions(+), 2 deletions(-) diff --git a/android/Gnss.cpp b/android/Gnss.cpp index 878cd202..8f048e24 100644 --- a/android/Gnss.cpp +++ b/android/Gnss.cpp @@ -25,6 +25,8 @@ #include #include #include "Gnss.h" +#include + typedef void* (getLocationInterface)(); #define IMAGES_INFO_FILE "/sys/devices/soc0/images" @@ -368,6 +370,14 @@ Return> Gnss::getExtensionAGnssRil() { Return Gnss::setCallback_1_1(const sp& callback) { ENTRY_LOG_CALLFLOW(); callback->gnssNameCb(getVersionString()); + mGnssCbIface_1_1 = callback; + GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb); + } return setCallback(callback); } @@ -396,11 +406,36 @@ Return> Gnss::getExtensionGnssConfiguration_1_1() { return mGnssConfig; } -Return Gnss::injectBestLocation(const GnssLocation&) { +Return Gnss::injectBestLocation(const GnssLocation& gnssLocation) { ENTRY_LOG_CALLFLOW(); + GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } return true; } +void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) { + ENTRY_LOG_CALLFLOW(); + if (mGnssCbIface_1_1 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + if (request.isEmergencyMode) { + mGnssCbIface_1_1->gnssRequestLocationCb(false); + } else { + mGnssCbIface_1_1->gnssRequestLocationCb(true); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else { + LOC_LOGe("ODCPI request not supported."); + } +} + IGnss* HIDL_FETCH_IGnss(const char* hal) { ENTRY_LOG_CALLFLOW(); IGnss* iface = nullptr; diff --git a/android/Gnss.h b/android/Gnss.h index c562b1fb..4c0c8b05 100644 --- a/android/Gnss.h +++ b/android/Gnss.h @@ -111,6 +111,9 @@ struct Gnss : public IGnss { Return updateConfiguration(GnssConfig& gnssConfig); GnssInterface* getGnssInterface(); + // Callback for ODCPI request + void odcpiRequestCb(const OdcpiRequestInfo& request); + private: struct GnssDeathRecipient : hidl_death_recipient { GnssDeathRecipient(sp gnss) : mGnss(gnss) { @@ -134,6 +137,7 @@ struct Gnss : public IGnss { GnssAPIClient* mApi = nullptr; sp mGnssCbIface = nullptr; + sp mGnssCbIface_1_1 = nullptr; sp mGnssNiCbIface = nullptr; GnssConfig mPendingConfig; GnssInterface* mGnssInterface = nullptr; diff --git a/android/location_api/LocationUtil.cpp b/android/location_api/LocationUtil.cpp index 7f3a74bc..21c2e397 100644 --- a/android/location_api/LocationUtil.cpp +++ b/android/location_api/LocationUtil.cpp @@ -70,6 +70,37 @@ void convertGnssLocation(Location& in, GnssLocation& out) out.timestamp = static_cast(in.timestamp); } +void convertGnssLocation(const GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) + out.flags |= LOCATION_HAS_SPEED_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) + out.flags |= LOCATION_HAS_BEARING_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) + out.flags |= LOCATION_HAS_ACCURACY_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.latitude = in.latitudeDegrees; + out.longitude = in.longitudeDegrees; + out.altitude = in.altitudeMeters; + out.speed = in.speedMetersPerSec; + out.bearing = in.bearingDegrees; + out.accuracy = in.horizontalAccuracyMeters; + out.verticalAccuracy = in.verticalAccuracyMeters; + out.speedAccuracy = in.speedAccuracyMetersPerSecond; + out.bearingAccuracy = in.bearingAccuracyDegrees; + out.timestamp = static_cast(in.timestamp); +} + void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out) { switch(in) { diff --git a/android/location_api/LocationUtil.h b/android/location_api/LocationUtil.h index acc0eabc..63f4f6f0 100644 --- a/android/location_api/LocationUtil.h +++ b/android/location_api/LocationUtil.h @@ -41,6 +41,7 @@ namespace V1_1 { namespace implementation { void convertGnssLocation(Location& in, V1_0::GnssLocation& out); +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out); void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out); void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out); void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out); diff --git a/core/LocAdapterBase.cpp b/core/LocAdapterBase.cpp index f3c999c2..d0da3dac 100644 --- a/core/LocAdapterBase.cpp +++ b/core/LocAdapterBase.cpp @@ -161,4 +161,8 @@ bool LocAdapterBase:: reportWwanZppFix(LocGpsLocation &/*zppLoc*/) DEFAULT_IMPL(false) +bool LocAdapterBase:: + reportOdcpiRequestEvent(OdcpiRequestInfo& /*request*/) +DEFAULT_IMPL(false) + } // namespace loc_core diff --git a/core/LocAdapterBase.h b/core/LocAdapterBase.h index e7beca83..35fc48e5 100644 --- a/core/LocAdapterBase.h +++ b/core/LocAdapterBase.h @@ -153,6 +153,7 @@ public: virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements, int msInWeek); virtual bool reportWwanZppFix(LocGpsLocation &zppLoc); + virtual bool reportOdcpiRequestEvent(OdcpiRequestInfo& request); }; } // namespace loc_core diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 1e326d94..13d0773b 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -264,6 +264,12 @@ void LocApiBase::reportWwanZppFix(LocGpsLocation &zppLoc) TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportWwanZppFix(zppLoc)); } +void LocApiBase::reportOdcpiRequest(OdcpiRequestInfo& request) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportOdcpiRequestEvent(request)); +} + void LocApiBase::reportSv(GnssSvNotification& svNotify) { const char* constellationString[] = { "Unknown", "GPS", "SBAS", "GLONASS", @@ -440,6 +446,10 @@ enum loc_api_adapter_err LocApiBase:: injectPosition(double /*latitude*/, double /*longitude*/, float /*accuracy*/) DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) +enum loc_api_adapter_err LocApiBase:: + injectPosition(const Location& /*location*/) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + enum loc_api_adapter_err LocApiBase:: setTime(LocGpsUtcTime /*time*/, int64_t /*timeReference*/, int /*uncertainty*/) DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) diff --git a/core/LocApiBase.h b/core/LocApiBase.h index 25d95b2a..6563dead 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -134,6 +134,7 @@ public: void reportGnssMeasurementData(GnssMeasurementsNotification& measurements, int msInWeek); void saveSupportedFeatureList(uint8_t *featureList); void reportWwanZppFix(LocGpsLocation &zppLoc); + void reportOdcpiRequest(OdcpiRequestInfo& request); // downward calls // All below functions are to be defined by adapter specific modules: @@ -153,6 +154,8 @@ public: setAPN(char* apn, int len); virtual enum loc_api_adapter_err injectPosition(double latitude, double longitude, float accuracy); + virtual enum loc_api_adapter_err + injectPosition(const Location& location); virtual enum loc_api_adapter_err setTime(LocGpsUtcTime time, int64_t timeReference, int uncertainty); virtual enum loc_api_adapter_err diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index e2a7c37f..a482acc0 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -74,6 +74,9 @@ GnssAdapter::GnssAdapter() : mNiData(), mAgpsManager(), mAgpsCbInfo(), + mOdcpiRequestCb(nullptr), + mOdcpiRequestActive(false), + mOdcpiInjectedPositionCount(0), mSystemStatus(SystemStatus::getInstance(mMsgTask)), mServerUrl(":"), mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask) @@ -1179,6 +1182,11 @@ GnssAdapter::updateClientsEventMask() mask |= LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST; } + // Add ODCPI handling + if (nullptr != mOdcpiRequestCb) { + mask |= LOC_API_ADAPTER_BIT_REQUEST_WIFI; + } + updateEvtMask(mask, LOC_REGISTRATION_MASK_SET); } @@ -2512,6 +2520,109 @@ GnssAdapter::reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial) mUlpProxy->reportSvPolynomial(svPolynomial); } +bool +GnssAdapter::reportOdcpiRequestEvent(OdcpiRequestInfo& request) +{ + LOC_LOGd("ODCPI request: type %d, tbf %d, isEmergency %d", request.type, + request.tbfMillis, request.isEmergencyMode); + + struct MsgReportOdcpiRequest : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestInfo mOdcpiRequest; + inline MsgReportOdcpiRequest(GnssAdapter& adapter, OdcpiRequestInfo& request) : + LocMsg(), + mAdapter(adapter), + mOdcpiRequest(request) {} + inline virtual void proc() const { + mAdapter.reportOdcpiRequest(mOdcpiRequest); + } + }; + + sendMsg(new MsgReportOdcpiRequest(*this, request)); + return true; +} + +void GnssAdapter::reportOdcpiRequest(const OdcpiRequestInfo& request) +{ + if (nullptr != mOdcpiRequestCb) { + mOdcpiInjectedPositionCount = 0; + if (ODCPI_REQUEST_TYPE_START == request.type) { + mOdcpiRequestCb(request); + mOdcpiRequestActive = true; + } else { + mOdcpiRequestActive = false; + } + } else { + LOC_LOGe("ODCPI request not supported"); + } +} + +void GnssAdapter::initOdcpiCommand(const OdcpiRequestCallback& callback) +{ + struct MsgInitOdcpi : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestCallback mOdcpiCb; + inline MsgInitOdcpi(GnssAdapter& adapter, + const OdcpiRequestCallback& callback) : + LocMsg(), + mAdapter(adapter), + mOdcpiCb(callback) {} + inline virtual void proc() const { + mAdapter.initOdcpi(mOdcpiCb); + } + }; + + sendMsg(new MsgInitOdcpi(*this, callback)); +} + +void GnssAdapter::initOdcpi(const OdcpiRequestCallback& callback) +{ + mOdcpiRequestCb = callback; + + /* Register for WIFI request */ + updateEvtMask(LOC_API_ADAPTER_BIT_REQUEST_WIFI, + LOC_REGISTRATION_MASK_ENABLED); +} + +void GnssAdapter::injectOdcpiCommand(const Location& location) +{ + struct MsgInjectOdcpi : public LocMsg { + GnssAdapter& mAdapter; + Location mLocation; + inline MsgInjectOdcpi(GnssAdapter& adapter, const Location& location) : + LocMsg(), + mAdapter(adapter), + mLocation(location) {} + inline virtual void proc() const { + mAdapter.injectOdcpi(mLocation); + } + }; + + sendMsg(new MsgInjectOdcpi(*this, location)); +} + +void GnssAdapter::injectOdcpi(const Location& location) +{ + LOC_LOGd("ODCPI Injection: requestActive: %d, lat %.7f long %.7f", + mOdcpiRequestActive, location.latitude, location.longitude); + + if (mOdcpiRequestActive) { + loc_api_adapter_err err = mLocApi->injectPosition(location); + if (LOC_API_ADAPTER_ERR_SUCCESS == err) { + mOdcpiInjectedPositionCount++; + if (mOdcpiInjectedPositionCount >= + ODCPI_INJECTED_POSITION_COUNT_PER_REQUEST) { + mOdcpiRequestActive = false; + mOdcpiInjectedPositionCount = 0; + } + } else { + LOC_LOGe("Inject Position API error %d", err); + } + } else { + LOC_LOGv("ODCPI request inactive, injection dropped"); + } +} + void GnssAdapter::initDefaultAgps() { LOC_LOGD("%s]: ", __func__); diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 99ce5c9a..e98c76ea 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -43,6 +43,7 @@ #define MAX_SATELLITES_IN_USE 12 #define LOC_NI_NO_RESPONSE_TIME 20 #define LOC_GPS_NI_RESPONSE_IGNORE 4 +#define ODCPI_INJECTED_POSITION_COUNT_PER_REQUEST 30 class GnssAdapter; @@ -102,12 +103,17 @@ class GnssAdapter : public LocAdapterBase { /* ==== NI ============================================================================= */ NiData mNiData; - /* ==== AGPS ========================================================*/ + /* ==== AGPS =========================================================================== */ // This must be initialized via initAgps() AgpsManager mAgpsManager; AgpsCbInfo mAgpsCbInfo; void initAgps(const AgpsCbInfo& cbInfo); + /* ==== ODCPI ========================================================================== */ + OdcpiRequestCallback mOdcpiRequestCb; + bool mOdcpiRequestActive; + uint32_t mOdcpiInjectedPositionCount; + /* === SystemStatus ===================================================================== */ SystemStatus* mSystemStatus; std::string mServerUrl; @@ -209,6 +215,14 @@ public: void dataConnClosedCommand(AGpsExtType agpsType); void dataConnFailedCommand(AGpsExtType agpsType); + /* ========= ODCPI ===================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void initOdcpiCommand(const OdcpiRequestCallback& callback); + void injectOdcpiCommand(const Location& location); + /* ======== UTILITIES ================================================================== */ + void initOdcpi(const OdcpiRequestCallback& callback); + void injectOdcpi(const Location& location); + /* ======== RESPONSES ================================================================== */ void reportResponse(LocationError err, uint32_t sessionId); void reportResponse(size_t count, LocationError* errs, uint32_t* ids); @@ -242,6 +256,7 @@ public: virtual bool requestSuplES(int connHandle); virtual bool reportDataCallOpened(); virtual bool reportDataCallClosed(); + virtual bool reportOdcpiRequestEvent(OdcpiRequestInfo& request); /* ======== UTILITIES ================================================================= */ bool needReport(const UlpLocation& ulpLocation, @@ -254,6 +269,7 @@ public: void reportNmea(const char* nmea, size_t length); bool requestNiNotify(const GnssNiNotification& notify, const void* data); void reportGnssMeasurementData(const GnssMeasurementsNotification& measurements); + void reportOdcpiRequest(const OdcpiRequestInfo& request); /*======== GNSSDEBUG ================================================================*/ bool getDebugReport(GnssDebugReport& report); diff --git a/gnss/location_gnss.cpp b/gnss/location_gnss.cpp index 3e989c97..21763dd1 100644 --- a/gnss/location_gnss.cpp +++ b/gnss/location_gnss.cpp @@ -62,6 +62,9 @@ static void agpsDataConnFailed(AGpsExtType agpsType); static void getDebugReport(GnssDebugReport& report); static void updateConnectionStatus(bool connected, int8_t type); +static void odcpiInit(const OdcpiRequestCallback& callback); +static void odcpiInject(const Location& location); + static const GnssInterface gGnssInterface = { sizeof(GnssInterface), initialize, @@ -87,6 +90,8 @@ static const GnssInterface gGnssInterface = { agpsDataConnFailed, getDebugReport, updateConnectionStatus, + odcpiInit, + odcpiInject, }; #ifndef DEBUG_X86 @@ -265,3 +270,18 @@ static void updateConnectionStatus(bool connected, int8_t type) { gGnssAdapter->getSystemStatus()->eventConnectionStatus(connected, type); } } + +static void odcpiInit(const OdcpiRequestCallback& callback) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->initOdcpiCommand(callback); + } +} + +static void odcpiInject(const Location& location) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectOdcpiCommand(location); + } +} + diff --git a/location/location_interface.h b/location/location_interface.h index 27589f71..92290521 100644 --- a/location/location_interface.h +++ b/location/location_interface.h @@ -57,6 +57,8 @@ struct GnssInterface { void (*agpsDataConnFailed)(AGpsExtType agpsType); void (*getDebugReport)(GnssDebugReport& report); void (*updateConnectionStatus)(bool connected, int8_t type); + void (*odcpiInit)(const OdcpiRequestCallback& callback); + void (*odcpiInject)(const Location& location); }; struct FlpInterface { diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index afe47ccc..f029a354 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -1293,6 +1293,20 @@ struct AGnssExtStatusIpV6 { uint8_t ipV6Addr[16]; }; +/* ODCPI Request Info */ +enum OdcpiRequestType { + ODCPI_REQUEST_TYPE_START, + ODCPI_REQUEST_TYPE_STOP +}; +struct OdcpiRequestInfo { + size_t size; + OdcpiRequestType type; + uint32_t tbfMillis; + bool isEmergencyMode; +}; +/* Callback to send ODCPI request to framework */ +typedef std::function OdcpiRequestCallback; + /* * Callback with AGNSS(IpV4) status information. * From 746606807f7189caa0f4deed77e41741a9fa1140 Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Fri, 23 Mar 2018 23:00:16 -0700 Subject: [PATCH 03/22] renamed DataItemIndex and ClientIndex files and moved them into utils. Change-Id: I138471168bf58d2cf09c6a435088edea29a567d0 CRs-Fixed: 2218519 --- core/data-items/common/ClientIndex.h => utils/LocListMap.h | 0 .../common/DataItemIndex.h => utils/LocUnorderedSetMap.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/data-items/common/ClientIndex.h => utils/LocListMap.h (100%) rename core/data-items/common/DataItemIndex.h => utils/LocUnorderedSetMap.h (100%) diff --git a/core/data-items/common/ClientIndex.h b/utils/LocListMap.h similarity index 100% rename from core/data-items/common/ClientIndex.h rename to utils/LocListMap.h diff --git a/core/data-items/common/DataItemIndex.h b/utils/LocUnorderedSetMap.h similarity index 100% rename from core/data-items/common/DataItemIndex.h rename to utils/LocUnorderedSetMap.h From 395001f24d4100fbcd69d77badd25f476ee32b80 Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Fri, 23 Mar 2018 22:57:51 -0700 Subject: [PATCH 04/22] changed SystemStatusOsObserver to allow clients to subscribe before subscription obj arrives, and also simplified ClientIndex and DataItemIndex implementation significantly. Change-Id: I092f344e688fa698aa98795b8a8f0c1ba8fcd9e4 CRs-Fixed: 2218519 --- core/Android.mk | 3 - core/Makefile.am | 3 - core/SystemStatus.cpp | 4 +- core/SystemStatusOsObserver.cpp | 623 ++++++++++------------- core/SystemStatusOsObserver.h | 94 ++-- core/data-items/common/ClientIndex.cpp | 172 ------- core/data-items/common/DataItemIndex.cpp | 203 -------- core/data-items/common/IClientIndex.h | 83 --- core/data-items/common/IDataItemIndex.h | 94 ---- core/data-items/common/IndexFactory.cpp | 64 --- core/data-items/common/IndexFactory.h | 48 -- utils/LocListMap.h | 70 --- utils/LocUnorderedSetMap.h | 166 +++++- 13 files changed, 473 insertions(+), 1154 deletions(-) delete mode 100644 core/data-items/common/ClientIndex.cpp delete mode 100644 core/data-items/common/DataItemIndex.cpp delete mode 100644 core/data-items/common/IClientIndex.h delete mode 100644 core/data-items/common/IDataItemIndex.h delete mode 100644 core/data-items/common/IndexFactory.cpp delete mode 100644 core/data-items/common/IndexFactory.h delete mode 100644 utils/LocListMap.h diff --git a/core/Android.mk b/core/Android.mk index 1374b6c0..82660d5e 100644 --- a/core/Android.mk +++ b/core/Android.mk @@ -31,9 +31,6 @@ LOCAL_SRC_FILES += \ LocDualContext.cpp \ loc_core_log.cpp \ data-items/DataItemsFactoryProxy.cpp \ - data-items/common/ClientIndex.cpp \ - data-items/common/DataItemIndex.cpp \ - data-items/common/IndexFactory.cpp \ SystemStatusOsObserver.cpp \ SystemStatus.cpp diff --git a/core/Makefile.am b/core/Makefile.am index dc540e9c..77bc6108 100644 --- a/core/Makefile.am +++ b/core/Makefile.am @@ -37,9 +37,6 @@ libloc_core_la_c_sources = \ LocDualContext.cpp \ loc_core_log.cpp \ data-items/DataItemsFactoryProxy.cpp \ - data-items/common/ClientIndex.cpp \ - data-items/common/DataItemIndex.cpp \ - data-items/common/IndexFactory.cpp \ SystemStatusOsObserver.cpp \ SystemStatus.cpp diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index 6eb99683..e12d9f32 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -1694,9 +1694,7 @@ bool SystemStatus::eventConnectionStatus(bool connected, int8_t type) // send networkinof dataitem to systemstatus observer clients SystemStatusNetworkInfo s(type, "", "", false, connected, false); - list dl(0); - dl.push_back(&s); - mSysStatusObsvr.notify(dl); + mSysStatusObsvr.notify({&s}); } return true; } diff --git a/core/SystemStatusOsObserver.cpp b/core/SystemStatusOsObserver.cpp index 2fdd19f1..0f6d2289 100644 --- a/core/SystemStatusOsObserver.cpp +++ b/core/SystemStatusOsObserver.cpp @@ -32,28 +32,20 @@ #include #include #include -#include -#include -#include #include namespace loc_core { -SystemStatusOsObserver::SystemStatusOsObserver( - SystemStatus* systemstatus, const MsgTask* msgTask) : - mSystemStatus(systemstatus), - mAddress("SystemStatusOsObserver"), -#ifdef USE_GLIB - mBackHaulConnectReqCount(0), -#endif - mClientIndex(IndexFactory :: createClientIndex()), - mDataItemIndex(IndexFactory :: createDataItemIndex()) -{ - mContext.mMsgTask = msgTask; +template +COUT SystemStatusOsObserver::containerTransfer(CINT& inContainer) { + COUT outContainer(0); + for (auto item : inContainer) { + outContainer.insert(outContainer.begin(), item); + } + return outContainer; } -SystemStatusOsObserver::~SystemStatusOsObserver() -{ +SystemStatusOsObserver::~SystemStatusOsObserver() { // Close data-item library handle DataItemsFactoryProxy::closeDataItemLibraryHandle(); @@ -65,290 +57,238 @@ SystemStatusOsObserver::~SystemStatusOsObserver() } mDataItemCache.clear(); - delete mClientIndex; - delete mDataItemIndex; } void SystemStatusOsObserver::setSubscriptionObj(IDataItemSubscription* subscriptionObj) { - mContext.mSubscriptionObj = subscriptionObj; + struct SetSubsObj : public LocMsg { + ObserverContext& mContext; + IDataItemSubscription* mSubsObj; + inline SetSubsObj(ObserverContext& context, IDataItemSubscription* subscriptionObj) : + mContext(context), mSubsObj(subscriptionObj) {} + void proc() const { + mContext.mSubscriptionObj = mSubsObj; - LOC_LOGD("Request cache size - Subscribe:%zu RequestData:%zu", - mSubscribeReqCache.size(), mReqDataCache.size()); - - // we have received the subscription object. process cached requests - // process - subscribe request cache - for (auto each : mSubscribeReqCache) { - subscribe(each.second, each.first); - } - // process - requestData request cache - for (auto each : mReqDataCache) { - requestData(each.second, each.first); - } -} - -// Helper to cache requests subscribe and requestData till subscription obj is obtained -void SystemStatusOsObserver::cacheObserverRequest(ObserverReqCache& reqCache, - const list& l, IDataItemObserver* client) -{ - ObserverReqCache::iterator dicIter = reqCache.find(client); - if (dicIter != reqCache.end()) { - // found - list difference(0); - set_difference(l.begin(), l.end(), - dicIter->second.begin(), dicIter->second.end(), - inserter(difference, difference.begin())); - if (!difference.empty()) { - difference.sort(); - dicIter->second.merge(difference); - dicIter->second.unique(); + if (!mContext.mSSObserver->mDataItemToClients.empty()) { + list dis( + containerTransfer, list>( + mContext.mSSObserver->mDataItemToClients.getKeys())); + mContext.mSubscriptionObj->subscribe(dis, mContext.mSSObserver); + mContext.mSubscriptionObj->requestData(dis, mContext.mSSObserver); + } } - } - else { - // not found - reqCache[client] = l; + }; + + if (nullptr == subscriptionObj) { + LOC_LOGw("subscriptionObj is NULL"); + } else { + mContext.mMsgTask->sendMsg(new SetSubsObj(mContext, subscriptionObj)); } } /****************************************************************************** IDataItemSubscription Overrides ******************************************************************************/ -void SystemStatusOsObserver::subscribe( - const list& l, IDataItemObserver* client) +void SystemStatusOsObserver::subscribe(const list& l, IDataItemObserver* client, + bool toRequestData) { - if (nullptr == mContext.mSubscriptionObj) { - LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__); - cacheObserverRequest(mSubscribeReqCache, l, client); - return; - } - struct HandleSubscribeReq : public LocMsg { - HandleSubscribeReq(SystemStatusOsObserver* parent, - const list& l, IDataItemObserver* client) : - mParent(parent), mClient(client), mDataItemList(l) {} - virtual ~HandleSubscribeReq() {} + inline HandleSubscribeReq(SystemStatusOsObserver* parent, + list& l, IDataItemObserver* client, bool requestData) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)), + mToRequestData(requestData) {} + void proc() const { + unordered_set dataItemsToSubscribe(0); + mParent->mDataItemToClients.add(mDataItemSet, {mClient}, &dataItemsToSubscribe); + mParent->mClientToDataItems.add(mClient, mDataItemSet); - if (mDataItemList.empty()) { - LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting"); - return; - } + mParent->sendCachedDataItems(mDataItemSet, mClient); - // Handle First Response - list pendingFirstResponseList(0); - mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList); - - // Do not send first response for only pendingFirstResponseList, - // instead send for all the data items (present in the cache) that - // have been subscribed for each time. - mParent->sendFirstResponse(mDataItemList, mClient); - - list yetToSubscribeDataItemsList(0); - mParent->mDataItemIndex->add(mClient, mDataItemList, yetToSubscribeDataItemsList); - - // Send subscription list to framework - if (!yetToSubscribeDataItemsList.empty()) { - mParent->mContext.mSubscriptionObj->subscribe(yetToSubscribeDataItemsList, mParent); + // Send subscription set to framework + if (nullptr != mParent->mContext.mSubscriptionObj && !dataItemsToSubscribe.empty()) { LOC_LOGD("Subscribe Request sent to framework for the following"); - mParent->logMe(yetToSubscribeDataItemsList); + mParent->logMe(dataItemsToSubscribe); + + if (mToRequestData) { + mParent->mContext.mSubscriptionObj->requestData( + containerTransfer, list>( + std::move(dataItemsToSubscribe)), + mParent); + } else { + mParent->mContext.mSubscriptionObj->subscribe( + containerTransfer, list>( + std::move(dataItemsToSubscribe)), + mParent); + } } } - SystemStatusOsObserver* mParent; + mutable SystemStatusOsObserver* mParent; IDataItemObserver* mClient; - const list mDataItemList; + const unordered_set mDataItemSet; + bool mToRequestData; }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleSubscribeReq(this, l, client)); + + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg( + new HandleSubscribeReq(this, (list&)l, client, toRequestData)); + } } void SystemStatusOsObserver::updateSubscription( const list& l, IDataItemObserver* client) { - if (nullptr == mContext.mSubscriptionObj) { - LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__); - return; - } - struct HandleUpdateSubscriptionReq : public LocMsg { HandleUpdateSubscriptionReq(SystemStatusOsObserver* parent, - const list& l, IDataItemObserver* client) : - mParent(parent), mClient(client), mDataItemList(l) {} - virtual ~HandleUpdateSubscriptionReq() {} + list& l, IDataItemObserver* client) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)) {} + void proc() const { - if (mDataItemList.empty()) { - LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting"); - return; - } - - list currentlySubscribedList(0); - mParent->mClientIndex->getSubscribedList(mClient, currentlySubscribedList); - - list removeDataItemList(0); - set_difference(currentlySubscribedList.begin(), currentlySubscribedList.end(), - mDataItemList.begin(), mDataItemList.end(), - inserter(removeDataItemList,removeDataItemList.begin())); - - // Handle First Response - list pendingFirstResponseList(0); - mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList); + unordered_set dataItemsToSubscribe(0); + unordered_set dataItemsToUnsubscribe(0); + unordered_set clients({mClient}); + // below removes clients from all entries keyed with the return of the + // mClientToDataItems.update() call. If leaving an empty set of clients as the + // result, the entire entry will be removed. dataItemsToUnsubscribe will be + // populated to keep the keys of the removed entries. + mParent->mDataItemToClients.trimOrRemove( + // this call updates map; removes + // the DataItemId's that are not new to the clietn from mDataItemSet; + // and returns a set of mDataItemSet's that are no longer used by client. + // This unused set of mDataItemSet's is passed to trimOrRemove method of + // map to remove the client from the + // corresponding entries, and gets a set of the entries that are + // removed from the map as a result. + mParent->mClientToDataItems.update(mClient, + (unordered_set&)mDataItemSet), + clients, &dataItemsToUnsubscribe, nullptr); + // below adds mClient to map, and populates + // new keys added to that map, which are DataItemIds to be subscribed. + mParent->mDataItemToClients.add(mDataItemSet, clients, &dataItemsToSubscribe); // Send First Response - mParent->sendFirstResponse(pendingFirstResponseList, mClient); + mParent->sendCachedDataItems(mDataItemSet, mClient); - list yetToSubscribeDataItemsList(0); - mParent->mDataItemIndex->add( - mClient, mDataItemList, yetToSubscribeDataItemsList); + if (nullptr != mParent->mContext.mSubscriptionObj) { + // Send subscription set to framework + if (!dataItemsToSubscribe.empty()) { + LOC_LOGD("Subscribe Request sent to framework for the following"); + mParent->logMe(dataItemsToSubscribe); - // Send subscription list to framework - if (!yetToSubscribeDataItemsList.empty()) { - mParent->mContext.mSubscriptionObj->subscribe( - yetToSubscribeDataItemsList, mParent); - LOC_LOGD("Subscribe Request sent to framework for the following"); - mParent->logMe(yetToSubscribeDataItemsList); - } + mParent->mContext.mSubscriptionObj->subscribe( + containerTransfer, list>( + std::move(dataItemsToSubscribe)), + mParent); + } - list unsubscribeList(0); - list unused(0); - mParent->mClientIndex->remove(mClient, removeDataItemList, unused); - - if (!mParent->mClientIndex->isSubscribedClient(mClient)) { - mParent->mDataItemIndex->remove( - list (1,mClient), unsubscribeList); - } - if (!unsubscribeList.empty()) { // Send unsubscribe to framework - mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent); - LOC_LOGD("Unsubscribe Request sent to framework for the following"); - mParent->logMe(unsubscribeList); + if (!dataItemsToUnsubscribe.empty()) { + LOC_LOGD("Unsubscribe Request sent to framework for the following"); + mParent->logMe(dataItemsToUnsubscribe); + + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); + } } } SystemStatusOsObserver* mParent; IDataItemObserver* mClient; - const list mDataItemList; + unordered_set mDataItemSet; }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleUpdateSubscriptionReq(this, l, client)); -} -void SystemStatusOsObserver::requestData( - const list& l, IDataItemObserver* client) -{ - if (nullptr == mContext.mSubscriptionObj) { - LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__); - cacheObserverRequest(mReqDataCache, l, client); - return; + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg( + new HandleUpdateSubscriptionReq(this, (list&)l, client)); } - - struct HandleRequestData : public LocMsg { - HandleRequestData(SystemStatusOsObserver* parent, - const list& l, IDataItemObserver* client) : - mParent(parent), mClient(client), mDataItemList(l) {} - virtual ~HandleRequestData() {} - void proc() const { - if (mDataItemList.empty()) { - LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting"); - return; - } - - list yetToSubscribeDataItemsList(0); - mParent->mClientIndex->add( - mClient, mDataItemList, yetToSubscribeDataItemsList); - mParent->mDataItemIndex->add( - mClient, mDataItemList, yetToSubscribeDataItemsList); - - // Send subscription list to framework - if (!mDataItemList.empty()) { - mParent->mContext.mSubscriptionObj->requestData(mDataItemList, mParent); - LOC_LOGD("Subscribe Request sent to framework for the following"); - mParent->logMe(yetToSubscribeDataItemsList); - } - } - SystemStatusOsObserver* mParent; - IDataItemObserver* mClient; - const list mDataItemList; - }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleRequestData(this, l, client)); } void SystemStatusOsObserver::unsubscribe( const list& l, IDataItemObserver* client) { - if (nullptr == mContext.mSubscriptionObj) { - LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__); - return; - } struct HandleUnsubscribeReq : public LocMsg { HandleUnsubscribeReq(SystemStatusOsObserver* parent, - const list& l, IDataItemObserver* client) : - mParent(parent), mClient(client), mDataItemList(l) {} - virtual ~HandleUnsubscribeReq() {} + list& l, IDataItemObserver* client) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)) {} + void proc() const { - if (mDataItemList.empty()) { - LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting"); - return; - } + unordered_set dataItemsUnusedByClient(0); + unordered_set clientToRemove(0); + mParent->mClientToDataItems.trimOrRemove({mClient}, mDataItemSet, &clientToRemove, + &dataItemsUnusedByClient); + unordered_set dataItemsToUnsubscribe(0); + mParent->mDataItemToClients.trimOrRemove(dataItemsUnusedByClient, {mClient}, + &dataItemsToUnsubscribe, nullptr); - list unsubscribeList(0); - list unused(0); - mParent->mClientIndex->remove(mClient, mDataItemList, unused); - - for (auto each : mDataItemList) { - list clientListSubs(0); - list clientListOut(0); - mParent->mDataItemIndex->remove( - each, list (1,mClient), clientListOut); - // check if there are any other subscribed client for this data item id - mParent->mDataItemIndex->getListOfSubscribedClients(each, clientListSubs); - if (clientListSubs.empty()) - { - LOC_LOGD("Client list subscribed is empty for dataitem - %d", each); - unsubscribeList.push_back(each); - } - } - - if (!unsubscribeList.empty()) { - // Send unsubscribe to framework - mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent); + if (nullptr != mParent->mContext.mSubscriptionObj && !dataItemsToUnsubscribe.empty()) { LOC_LOGD("Unsubscribe Request sent to framework for the following data items"); - mParent->logMe(unsubscribeList); + mParent->logMe(dataItemsToUnsubscribe); + + // Send unsubscribe to framework + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); } } SystemStatusOsObserver* mParent; IDataItemObserver* mClient; - const list mDataItemList; + unordered_set mDataItemSet; }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeReq(this, l, client)); + + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg(new HandleUnsubscribeReq(this, (list&)l, client)); + } } void SystemStatusOsObserver::unsubscribeAll(IDataItemObserver* client) { - if (nullptr == mContext.mSubscriptionObj) { - LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__); - return; - } - struct HandleUnsubscribeAllReq : public LocMsg { HandleUnsubscribeAllReq(SystemStatusOsObserver* parent, IDataItemObserver* client) : mParent(parent), mClient(client) {} - virtual ~HandleUnsubscribeAllReq() {} - void proc() const { - list clients(1, mClient); - list unsubscribeList(0); - if(0 == mParent->mClientIndex->remove(mClient)) { - return; - } - mParent->mDataItemIndex->remove(clients, unsubscribeList); - if (!unsubscribeList.empty()) { - // Send unsubscribe to framework - mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent); - LOC_LOGD("Unsubscribe Request sent to framework for the following data items"); - mParent->logMe(unsubscribeList); + void proc() const { + unordered_set diByClient = mParent->mClientToDataItems.getValSet(mClient); + if (!diByClient.empty()) { + unordered_set dataItemsToUnsubscribe; + mParent->mClientToDataItems.remove(mClient); + mParent->mDataItemToClients.trimOrRemove(diByClient, {mClient}, + &dataItemsToUnsubscribe, nullptr); + + if (!dataItemsToUnsubscribe.empty() && + nullptr != mParent->mContext.mSubscriptionObj) { + + LOC_LOGD("Unsubscribe Request sent to framework for the following data items"); + mParent->logMe(dataItemsToUnsubscribe); + + // Send unsubscribe to framework + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); + } } } SystemStatusOsObserver* mParent; IDataItemObserver* mClient; }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeAllReq(this, client)); + + if (nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg(new HandleUnsubscribeAllReq(this, client)); + } } /****************************************************************************** @@ -356,84 +296,78 @@ void SystemStatusOsObserver::unsubscribeAll(IDataItemObserver* client) ******************************************************************************/ void SystemStatusOsObserver::notify(const list& dlist) { - list dataItemList(0); - - for (auto each : dlist) { - string dv; - each->stringify(dv); - LOC_LOGD("notify: DataItem In Value:%s", dv.c_str()); - - IDataItemCore* di = DataItemsFactoryProxy::createNewDataItem(each->getId()); - if (nullptr == di) { - LOC_LOGE("Unable to create dataitem:%d", each->getId()); - return; - } - - // Copy contents into the newly created data item - di->copy(each); - - // Request systemstatus to record this dataitem in its cache - if (mSystemStatus->eventDataItemNotify(di)) { - // add this dataitem if updated from last one - dataItemList.push_back(di); - } - } - struct HandleNotify : public LocMsg { - HandleNotify(SystemStatusOsObserver* parent, const list& l) : - mParent(parent), mDList(l) {} - virtual ~HandleNotify() { - for (auto each : mDList) { - delete each; + HandleNotify(SystemStatusOsObserver* parent, vector& v) : + mParent(parent), mDiVec(std::move(v)) {} + + inline virtual ~HandleNotify() { + for (auto item : mDiVec) { + delete item; } } + void proc() const { // Update Cache with received data items and prepare // list of data items to be sent. - list dataItemIdsToBeSent(0); - for (auto item : mDList) { - bool dataItemUpdated = false; - mParent->updateCache(item, dataItemUpdated); - if (dataItemUpdated) { - dataItemIdsToBeSent.push_back(item->getId()); + unordered_set dataItemIdsToBeSent(0); + for (auto item : mDiVec) { + if (mParent->updateCache(item)) { + dataItemIdsToBeSent.insert(item->getId()); } } // Send data item to all subscribed clients - list clientList(0); + unordered_set clientSet(0); for (auto each : dataItemIdsToBeSent) { - list clients(0); - mParent->mDataItemIndex->getListOfSubscribedClients(each, clients); - for (auto each_cient: clients) { - clientList.push_back(each_cient); + auto clients = mParent->mDataItemToClients.getValSetPtr(each); + if (nullptr != clients) { + clientSet.insert(clients->begin(), clients->end()); } } - clientList.unique(); - for (auto client : clientList) { - list dataItemIdsSubscribedByThisClient(0); - list dataItemIdsToBeSentForThisClient(0); - mParent->mClientIndex->getSubscribedList( - client, dataItemIdsSubscribedByThisClient); - dataItemIdsSubscribedByThisClient.sort(); - dataItemIdsToBeSent.sort(); + for (auto client : clientSet) { + unordered_set dataItemIdsForThisClient( + mParent->mClientToDataItems.getValSet(client)); + for (auto id : dataItemIdsForThisClient) { + if (dataItemIdsToBeSent.find(id) == dataItemIdsToBeSent.end()) { + dataItemIdsForThisClient.erase(id); + } + } - set_intersection(dataItemIdsToBeSent.begin(), - dataItemIdsToBeSent.end(), - dataItemIdsSubscribedByThisClient.begin(), - dataItemIdsSubscribedByThisClient.end(), - inserter(dataItemIdsToBeSentForThisClient, - dataItemIdsToBeSentForThisClient.begin())); - - mParent->sendCachedDataItems(dataItemIdsToBeSentForThisClient, client); - dataItemIdsSubscribedByThisClient.clear(); - dataItemIdsToBeSentForThisClient.clear(); + mParent->sendCachedDataItems(dataItemIdsForThisClient, client); } } SystemStatusOsObserver* mParent; - const list mDList; + const vector mDiVec; }; - mContext.mMsgTask->sendMsg(new (nothrow) HandleNotify(this, dataItemList)); + + if (!dlist.empty()) { + vector dataItemVec(dlist.size()); + + for (auto each : dlist) { + IF_LOC_LOGD { + string dv; + each->stringify(dv); + LOC_LOGD("notify: DataItem In Value:%s", dv.c_str()); + } + + IDataItemCore* di = DataItemsFactoryProxy::createNewDataItem(each->getId()); + if (nullptr == di) { + LOC_LOGw("Unable to create dataitem:%d", each->getId()); + continue; + } + + // Copy contents into the newly created data item + di->copy(each); + + // add this dataitem if updated from last one + dataItemVec.push_back(di); + } + + if (!dataItemVec.empty()) { + mContext.mMsgTask->sendMsg(new HandleNotify(this, dataItemVec)); + } + } } /****************************************************************************** @@ -447,7 +381,7 @@ void SystemStatusOsObserver::turnOn(DataItemId dit, int timeOut) } // Check if data item exists in mActiveRequestCount - map::iterator citer = mActiveRequestCount.find(dit); + DataItemIdToInt::iterator citer = mActiveRequestCount.find(dit); if (citer == mActiveRequestCount.end()) { // Data item not found in map // Add reference count as 1 and add dataitem to map @@ -485,7 +419,7 @@ void SystemStatusOsObserver::turnOff(DataItemId dit) } // Check if data item exists in mActiveRequestCount - map::iterator citer = mActiveRequestCount.find(dit); + DataItemIdToInt::iterator citer = mActiveRequestCount.find(dit); if (citer != mActiveRequestCount.end()) { // found citer->second--; @@ -573,84 +507,65 @@ bool SystemStatusOsObserver::disconnectBackhaul() /****************************************************************************** Helpers ******************************************************************************/ -void SystemStatusOsObserver::sendFirstResponse( - const list& l, IDataItemObserver* to) -{ - if (l.empty()) { - LOC_LOGV("list is empty. Nothing to do. Exiting"); - return; - } - - string clientName; - to->getName(clientName); - list dataItems(0); - - for (auto each : l) { - map::const_iterator citer = mDataItemCache.find(each); - if (citer != mDataItemCache.end()) { - string dv; - citer->second->stringify(dv); - LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str()); - dataItems.push_back(citer->second); - } - } - if (dataItems.empty()) { - LOC_LOGV("No items to notify. Nothing to do. Exiting"); - return; - } - to->notify(dataItems); -} - void SystemStatusOsObserver::sendCachedDataItems( - const list& l, IDataItemObserver* to) + const unordered_set& s, IDataItemObserver* to) { - string clientName; - to->getName(clientName); - list dataItems(0); + if (nullptr == to) { + LOC_LOGv("client pointer is NULL."); + } else { + string clientName; + to->getName(clientName); + list dataItems(0); - for (auto each : l) { - string dv; - IDataItemCore* di = mDataItemCache[each]; - di->stringify(dv); - LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str()); - dataItems.push_back(di); + for (auto each : s) { + auto citer = mDataItemCache.find(each); + if (citer != mDataItemCache.end()) { + string dv; + citer->second->stringify(dv); + LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str()); + dataItems.push_front(citer->second); + } + } + + if (dataItems.empty()) { + LOC_LOGv("No items to notify."); + } else { + to->notify(dataItems); + } } - to->notify(dataItems); } -void SystemStatusOsObserver::updateCache(IDataItemCore* d, bool& dataItemUpdated) +bool SystemStatusOsObserver::updateCache(IDataItemCore* d) { - if (nullptr == d) { - return; - } + bool dataItemUpdated = false; - // Check if data item exists in cache - map::iterator citer = - mDataItemCache.find(d->getId()); - if (citer == mDataItemCache.end()) { - // New data item; not found in cache - IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(d->getId()); - if (nullptr == dataitem) { - return; + // Request systemstatus to record this dataitem in its cache + // if the return is false, it means that SystemStatus is not + // handling it, so SystemStatusOsObserver also doesn't. + // So it has to be true to proceed. + if (nullptr != d && mSystemStatus->eventDataItemNotify(d)) { + auto citer = mDataItemCache.find(d->getId()); + if (citer == mDataItemCache.end()) { + // New data item; not found in cache + IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(d->getId()); + if (nullptr != dataitem) { + // Copy the contents of the data item + dataitem->copy(d); + // Insert in mDataItemCache + mDataItemCache.insert(std::make_pair(d->getId(), dataitem)); + dataItemUpdated = true; + } + } else { + // Found in cache; Update cache if necessary + citer->second->copy(d, &dataItemUpdated); } - // Copy the contents of the data item - dataitem->copy(d); - pair cpair(d->getId(), dataitem); - // Insert in mDataItemCache - mDataItemCache.insert(cpair); - dataItemUpdated = true; - } - else { - // Found in cache; Update cache if necessary - if(0 == citer->second->copy(d, &dataItemUpdated)) { - return; + if (dataItemUpdated) { + LOC_LOGV("DataItem:%d updated:%d", d->getId(), dataItemUpdated); } } - if (dataItemUpdated) { - LOC_LOGV("DataItem:%d updated:%d", d->getId(), dataItemUpdated); - } + return dataItemUpdated; } } // namespace loc_core diff --git a/core/SystemStatusOsObserver.h b/core/SystemStatusOsObserver.h index 930ddc12..fd606063 100644 --- a/core/SystemStatusOsObserver.h +++ b/core/SystemStatusOsObserver.h @@ -41,6 +41,7 @@ #include #include #include +#include namespace loc_core { @@ -48,39 +49,57 @@ namespace loc_core SystemStatusOsObserver ******************************************************************************/ using namespace std; +using namespace loc_util; // Forward Declarations class IDataItemCore; -template class IClientIndex; -template class IDataItemIndex; +class SystemStatus; +class SystemStatusOsObserver; +typedef map> ObserverReqCache; +typedef LocUnorderedSetMap ClientToDataItems; +typedef LocUnorderedSetMap DataItemToClients; +typedef unordered_map DataItemIdToCore; +typedef unordered_map DataItemIdToInt; -struct SystemContext { +struct ObserverContext { IDataItemSubscription* mSubscriptionObj; IFrameworkActionReq* mFrameworkActionReqObj; const MsgTask* mMsgTask; + SystemStatusOsObserver* mSSObserver; - inline SystemContext() : - mSubscriptionObj(NULL), - mFrameworkActionReqObj(NULL), - mMsgTask(NULL) {} + inline ObserverContext(const MsgTask* msgTask, SystemStatusOsObserver* observer) : + mSubscriptionObj(NULL), mFrameworkActionReqObj(NULL), + mMsgTask(msgTask), mSSObserver(observer) {} }; -typedef map> ObserverReqCache; - // Clients wanting to get data from OS/Framework would need to // subscribe with OSObserver using IDataItemSubscription interface. // Such clients would need to implement IDataItemObserver interface // to receive data when it becomes available. -class SystemStatus; class SystemStatusOsObserver : public IOsObserver { public: // ctor - SystemStatusOsObserver( - SystemStatus* systemstatus, const MsgTask* msgTask); + inline SystemStatusOsObserver(SystemStatus* systemstatus, const MsgTask* msgTask) : + mSystemStatus(systemstatus), mContext(msgTask, this), + mAddress("SystemStatusOsObserver"), + mClientToDataItems(MAX_DATA_ITEM_ID), mDataItemToClients(MAX_DATA_ITEM_ID) +#ifdef USE_GLIB + , mBackHaulConnectReqCount(0) +#endif + { + } + // dtor ~SystemStatusOsObserver(); + template + static COUT containerTransfer(CINT& s); + template + inline static COUT containerTransfer(CINT&& s) { + return containerTransfer(s); + } + // To set the subscription object virtual void setSubscriptionObj(IDataItemSubscription* subscriptionObj); @@ -96,38 +115,40 @@ public: } // IDataItemSubscription Overrides - virtual void subscribe(const list& l, IDataItemObserver* client); - virtual void updateSubscription(const list& l, IDataItemObserver* client); - virtual void requestData(const list& l, IDataItemObserver* client); - virtual void unsubscribe(const list& l, IDataItemObserver* client); - virtual void unsubscribeAll(IDataItemObserver* client); + inline virtual void subscribe(const list& l, IDataItemObserver* client) override { + subscribe(l, client, false); + } + virtual void updateSubscription(const list& l, IDataItemObserver* client) override; + inline virtual void requestData(const list& l, IDataItemObserver* client) override { + subscribe(l, client, true); + } + virtual void unsubscribe(const list& l, IDataItemObserver* client) override; + virtual void unsubscribeAll(IDataItemObserver* client) override; // IDataItemObserver Overrides - virtual void notify(const list& dlist); - inline virtual void getName(string& name) { + virtual void notify(const list& dlist) override; + inline virtual void getName(string& name) override { name = mAddress; } // IFrameworkActionReq Overrides - virtual void turnOn(DataItemId dit, int timeOut = 0); - virtual void turnOff(DataItemId dit); + virtual void turnOn(DataItemId dit, int timeOut = 0) override; + virtual void turnOff(DataItemId dit) override; #ifdef USE_GLIB - virtual bool connectBackhaul(); + virtual bool connectBackhaul() override; virtual bool disconnectBackhaul(); #endif private: SystemStatus* mSystemStatus; - SystemContext mContext; + ObserverContext mContext; const string mAddress; - IClientIndex* mClientIndex; - IDataItemIndex* mDataItemIndex; - map mDataItemCache; - map mActiveRequestCount; + ClientToDataItems mClientToDataItems; + DataItemToClients mDataItemToClients; + DataItemIdToCore mDataItemCache; + DataItemIdToInt mActiveRequestCount; // Cache the subscribe and requestData till subscription obj is obtained - ObserverReqCache mSubscribeReqCache; - ObserverReqCache mReqDataCache; void cacheObserverRequest(ObserverReqCache& reqCache, const list& l, IDataItemObserver* client); #ifdef USE_GLIB @@ -135,13 +156,16 @@ private: int mBackHaulConnectReqCount; #endif + void subscribe(const list& l, IDataItemObserver* client, bool toRequestData); + // Helpers - void sendFirstResponse(const list& l, IDataItemObserver* to); - void sendCachedDataItems(const list& l, IDataItemObserver* to); - void updateCache(IDataItemCore* d, bool& dataItemUpdated); - inline void logMe(const list& l) { - for (auto id : l) { - LOC_LOGD("DataItem %d", id); + void sendCachedDataItems(const unordered_set& s, IDataItemObserver* to); + bool updateCache(IDataItemCore* d); + inline void logMe(const unordered_set& l) { + IF_LOC_LOGD { + for (auto id : l) { + LOC_LOGD("DataItem %d", id); + } } } }; diff --git a/core/data-items/common/ClientIndex.cpp b/core/data-items/common/ClientIndex.cpp deleted file mode 100644 index d4bd11e5..00000000 --- a/core/data-items/common/ClientIndex.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace loc_core; - -template -inline ClientIndex :: ClientIndex () {} - -template -inline ClientIndex :: ~ClientIndex () {} - -template -bool ClientIndex :: isSubscribedClient (CT client) { - bool result = false; - ENTRY_LOG (); - typename map < CT, list > :: iterator it = - mDataItemsPerClientMap.find (client); - if (it != mDataItemsPerClientMap.end ()) { - result = true; - } - EXIT_LOG_WITH_ERROR ("%d",result); - return result; -} - -template -void ClientIndex :: getSubscribedList (CT client, list & out) { - ENTRY_LOG (); - typename map < CT, list > :: iterator it = - mDataItemsPerClientMap.find (client); - if (it != mDataItemsPerClientMap.end ()) { - out = it->second; - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -int ClientIndex :: remove (CT client) { - int result = 0; - ENTRY_LOG (); - mDataItemsPerClientMap.erase (client); - EXIT_LOG_WITH_ERROR ("%d",result); - return result; -} - -template -void ClientIndex :: remove (const list & r, list & out) { - ENTRY_LOG (); - typename map < CT, list > :: iterator dicIter = - mDataItemsPerClientMap.begin (); - while (dicIter != mDataItemsPerClientMap.end()) { - typename list :: const_iterator it = r.begin (); - for (; it != r.end (); ++it) { - typename list :: iterator iter = - find (dicIter->second.begin (), dicIter->second.end (), *it); - if (iter != dicIter->second.end ()) { - dicIter->second.erase (iter); - } - } - if (dicIter->second.empty ()) { - out.push_back (dicIter->first); - // Post-increment operator increases the iterator but returns the - // prevous one that will be invalidated by erase() - mDataItemsPerClientMap.erase (dicIter++); - } else { - ++dicIter; - } - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -void ClientIndex :: remove -( - CT client, - const list & r, - list & out -) -{ - ENTRY_LOG (); - typename map < CT, list > :: iterator dicIter = - mDataItemsPerClientMap.find (client); - if (dicIter != mDataItemsPerClientMap.end ()) { - set_intersection (dicIter->second.begin (), dicIter->second.end (), - r.begin (), r.end (), - inserter (out,out.begin ())); - if (!out.empty ()) { - typename list :: iterator it = out.begin (); - for (; it != out.end (); ++it) { - dicIter->second.erase (find (dicIter->second.begin (), - dicIter->second.end (), - *it)); - } - } - if (dicIter->second.empty ()) { - mDataItemsPerClientMap.erase (dicIter); - EXIT_LOG_WITH_ERROR ("%d",0); - } - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -void ClientIndex :: add -( - CT client, - const list & l, - list & out -) -{ - ENTRY_LOG (); - list difference; - typename map < CT, list > :: iterator dicIter = - mDataItemsPerClientMap.find (client); - if (dicIter != mDataItemsPerClientMap.end ()) { - set_difference (l.begin (), l.end (), - dicIter->second.begin (), dicIter->second.end (), - inserter (difference,difference.begin ())); - if (!difference.empty ()) { - difference.sort (); - out = difference; - dicIter->second.merge (difference); - dicIter->second.unique (); - } - } else { - out = l; - pair < CT, list > dicnpair (client, out); - mDataItemsPerClientMap.insert (dicnpair); - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -// Explicit instantiation must occur in same namespace where class is defined -namespace loc_core -{ - template class ClientIndex ; - template class ClientIndex ; -} diff --git a/core/data-items/common/DataItemIndex.cpp b/core/data-items/common/DataItemIndex.cpp deleted file mode 100644 index 462bf748..00000000 --- a/core/data-items/common/DataItemIndex.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace loc_core; - -template -inline DataItemIndex :: DataItemIndex () {} - -template -inline DataItemIndex :: ~DataItemIndex () {} - -template -void DataItemIndex :: getListOfSubscribedClients - ( - DIT id, - list & out -) -{ - typename map < DIT, list > :: iterator cdiIter = - mClientsPerDataItemMap.find (id); - if (cdiIter != mClientsPerDataItemMap.end ()) { - out = cdiIter->second; - } -} - - -template -int DataItemIndex :: remove (DIT id) { - int result = 0; - ENTRY_LOG (); - mClientsPerDataItemMap.erase (id); - EXIT_LOG_WITH_ERROR ("%d",result); - return result; -} - -template -void DataItemIndex :: remove (const list & r, list & out) { - ENTRY_LOG (); - typename map < DIT, list > :: iterator cdiIter = - mClientsPerDataItemMap.begin (); - while (cdiIter != mClientsPerDataItemMap.end()) { - typename list :: const_iterator it = r.begin (); - for (; it != r.end (); ++it) { - typename list :: iterator iter = - find - ( - cdiIter->second.begin (), - cdiIter->second.end (), - *it - ); - if (iter != cdiIter->second.end ()) { - cdiIter->second.erase (iter); - } - } - - if (cdiIter->second.empty ()) { - out.push_back (cdiIter->first); - // Post-increment operator increases the iterator but returns the - // prevous one that will be invalidated by erase() - mClientsPerDataItemMap.erase (cdiIter++); - } else { - ++cdiIter; - } - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -void DataItemIndex :: remove -( - DIT id, - const list & r, - list & out -) -{ - ENTRY_LOG (); - - typename map < DIT, list > :: iterator cdiIter = - mClientsPerDataItemMap.find (id); - if (cdiIter != mClientsPerDataItemMap.end ()) { - set_intersection (cdiIter->second.begin (), cdiIter->second.end (), - r.begin (), r.end (), - inserter (out, out.begin ())); - if (!out.empty ()) { - typename list :: iterator it = out.begin (); - for (; it != out.end (); ++it) { - cdiIter->second.erase (find (cdiIter->second.begin (), - cdiIter->second.end (), - *it)); - } - } - if (cdiIter->second.empty ()) { - mClientsPerDataItemMap.erase (cdiIter); - EXIT_LOG_WITH_ERROR ("%d",0); - } - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -void DataItemIndex :: add -( - DIT id, - const list & l, - list & out -) -{ - ENTRY_LOG (); - list difference; - typename map < DIT, list > :: iterator cdiIter = - mClientsPerDataItemMap.find (id); - if (cdiIter != mClientsPerDataItemMap.end ()) { - set_difference (l.begin (), l.end (), - cdiIter->second.begin (), cdiIter->second.end (), - inserter (difference, difference.begin ())); - if (!difference.empty ()) { - difference.sort (); - out = difference; - cdiIter->second.merge (difference); - } - } else { - out = l; - pair < DIT, list > cndipair (id, out); - mClientsPerDataItemMap.insert (cndipair); - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -template -void DataItemIndex :: add -( - CT client, - const list & l, - list & out -) -{ - ENTRY_LOG (); - typename map < DIT, list > :: iterator cdiIter; - typename list :: const_iterator it = l.begin (); - for (; it != l.end (); ++it) { - cdiIter = mClientsPerDataItemMap.find (*it); - if (cdiIter == mClientsPerDataItemMap.end ()) { - out.push_back (*it); - pair < DIT, list > cndiPair (*it, list (1, client)); - mClientsPerDataItemMap.insert (cndiPair); - } else { - typename list :: iterator clientIter = - find - ( - cdiIter->second.begin (), - cdiIter->second.end (), - client - ); - if (clientIter == cdiIter->second.end()) { - cdiIter->second.push_back (client); - } - } - } - EXIT_LOG_WITH_ERROR ("%d",0); -} - -// Explicit instantiation must occur in same namespace where class is defined -namespace loc_core -{ - template class DataItemIndex ; - template class DataItemIndex ; -} diff --git a/core/data-items/common/IClientIndex.h b/core/data-items/common/IClientIndex.h deleted file mode 100644 index 0272e7b9..00000000 --- a/core/data-items/common/IClientIndex.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ - -#ifndef __ICLIENTINDEX_H__ -#define __ICLIENTINDEX_H__ - -#include - -namespace loc_core -{ - -template - -class IClientIndex { -public: - - // Checks if client is subscribed - virtual bool isSubscribedClient (CT client) = 0; - - // gets subscription list - virtual void getSubscribedList (CT client, std :: list & out) = 0; - - // removes an entry - virtual int remove (CT client) = 0; - - // removes std :: list of data items and returns a list of clients - // removed if any. - virtual void remove - ( - const std :: list & r, - std :: list & out - ) = 0; - - // removes list of data items indexed by client and returns list - // of data items removed if any. - virtual void remove - ( - CT client, - const std :: list & r, - std :: list & out - ) = 0; - - // adds/modifies entry in map and returns new data items added. - virtual void add - ( - CT client, - const std :: list & l, - std :: list & out - ) = 0; - - // dtor - virtual ~IClientIndex () {} -}; - -} // namespace loc_core - -#endif // #ifndef __ICLIENTINDEX_H__ diff --git a/core/data-items/common/IDataItemIndex.h b/core/data-items/common/IDataItemIndex.h deleted file mode 100644 index 91855826..00000000 --- a/core/data-items/common/IDataItemIndex.h +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ - -#ifndef __IDATAITEMINDEX_H__ -#define __IDATAITEMINDEX_H__ - -#include - -namespace loc_core -{ - -template - -class IDataItemIndex { - -public: - - // gets std :: list of subscribed clients - virtual void getListOfSubscribedClients - ( - DIT id, - std :: list & out - ) = 0; - - // removes an entry from - virtual int remove (DIT id) = 0; - - // removes list of clients and returns a list of data items - // removed if any. - virtual void remove - ( - const std :: list & r, - std :: list & out - ) = 0; - - // removes list of clients indexed by data item and returns list of - // clients removed if any. - virtual void remove - ( - DIT id, - const std :: list & r, - std :: list & out - ) = 0; - - // adds/modifies entry and returns new clients added - virtual void add - ( - DIT id, - const std :: list & l, - std :: list & out - ) = 0; - - // adds/modifies entry and returns yet to subscribe list of data items - virtual void add - ( - CT client, - const std :: list & l, - std :: list & out - ) = 0; - - // dtor - virtual ~IDataItemIndex () {} -}; - -} // namespace loc_core - -#endif // #ifndef __IDATAITEMINDEX_H__ - diff --git a/core/data-items/common/IndexFactory.cpp b/core/data-items/common/IndexFactory.cpp deleted file mode 100644 index cf494752..00000000 --- a/core/data-items/common/IndexFactory.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using loc_core::IClientIndex; -using loc_core::IDataItemIndex; -using loc_core::IDataItemObserver; -using namespace loc_core; - -template -inline IClientIndex * IndexFactory :: createClientIndex -() -{ - return new (nothrow) ClientIndex (); -} - -template -inline IDataItemIndex * IndexFactory :: createDataItemIndex -() -{ - return new (nothrow) DataItemIndex (); -} - -// Explicit instantiation must occur in same namespace where class is defined -namespace loc_core -{ - template class IndexFactory ; - template class IndexFactory ; -} diff --git a/core/data-items/common/IndexFactory.h b/core/data-items/common/IndexFactory.h deleted file mode 100644 index 9a2070e9..00000000 --- a/core/data-items/common/IndexFactory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ - -#ifndef __INDEXFACTORY_H__ -#define __INDEXFACTORY_H__ - -#include -#include - -namespace loc_core -{ -template -class IndexFactory { - -public: - static IClientIndex * createClientIndex (); - static IDataItemIndex * createDataItemIndex (); -}; - -} // namespace loc_core - -#endif // #ifndef __INDEXFACTORY_H__ diff --git a/utils/LocListMap.h b/utils/LocListMap.h deleted file mode 100644 index feccb059..00000000 --- a/utils/LocListMap.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2015, 2017 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. - * - */ -#ifndef __CLIENTINDEX_H__ -#define __CLIENTINDEX_H__ - -#include -#include -#include - -using loc_core::IClientIndex; - -namespace loc_core -{ - -template - -class ClientIndex : public IClientIndex { - -public: - - ClientIndex (); - - ~ClientIndex (); - - bool isSubscribedClient (CT client); - - void getSubscribedList (CT client, std :: list & out); - - int remove (CT client); - - void remove (const std :: list & r, std :: list & out); - - void remove (CT client, const std :: list & r, std :: list & out); - - void add (CT client, const std :: list & l, std :: list & out); - -private: - //Data members - std :: map < CT , std :: list > mDataItemsPerClientMap; -}; - -} // namespace loc_core - -#endif // #ifndef __CLIENTINDEX_H__ diff --git a/utils/LocUnorderedSetMap.h b/utils/LocUnorderedSetMap.h index d72e89eb..87481348 100644 --- a/utils/LocUnorderedSetMap.h +++ b/utils/LocUnorderedSetMap.h @@ -26,45 +26,167 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +#ifndef __LOC_UNORDERDED_SETMAP_H__ +#define __LOC_UNORDERDED_SETMAP_H__ -#ifndef __DATAITEMINDEX_H__ -#define __DATAITEMINDEX_H__ +#include +#include +#include -#include -#include -#include +using std::unordered_set; +using std::unordered_map; -using loc_core::IDataItemIndex; +namespace loc_util { -namespace loc_core -{ +// Trim from *fromSet* any elements that also exist in *rVals*. +// The optional *goneVals*, if not null, will be populated with removed elements. +template +inline static void trimSet(unordered_set& fromSet, const unordered_set& rVals, + unordered_set* goneVals) { + for (auto val : rVals) { + if (fromSet.erase(val) > 0 && nullptr != goneVals) { + goneVals->insert(val); + } + } +} -template +// this method is destructive to the input unordered_sets. +// the return set is the interset extracted out from the two input sets, *s1* and *s2*. +// *s1* and *s2* will be left with the intersect removed from them. +template +static unordered_set removeAndReturnInterset(unordered_set& s1, unordered_set& s2) { + unordered_set common(0); + for (auto b = s2.begin(); b != s2.end(); b++) { + auto a = find(s1.begin(), s1.end(), *b); + if (a != s1.end()) { + // this is a common item of both l1 and l2, remove from both + // but after we add to common + common.insert(*a); + s1.erase(a); + s2.erase(b); + } + } + return common; +} -class DataItemIndex : public IDataItemIndex { +template +class LocUnorderedSetMap { + unordered_map> mMap; + + + // Trim the VALs pointed to by *iter*, with everything that also exist in *rVals*. + // If the set becomes empty, remove the map entry. *goneVals*, if not null, records + // the trimmed VALs. + bool trimOrRemove(typename unordered_map>::iterator iter, + const unordered_set& rVals, unordered_set* goneVals) { + trimSet(iter->second, rVals, goneVals); + bool removeEntry = (iter->second.empty()); + if (removeEntry) { + mMap.erase(iter); + } + return removeEntry; + } public: + inline LocUnorderedSetMap() {} + inline LocUnorderedSetMap(size_t size) : mMap(size) {} - DataItemIndex (); + inline bool empty() { return mMap.empty(); } - ~DataItemIndex (); + // This gets the raw pointer to the VALs pointed to by *key* + // If the entry is not in the map, nullptr will be returned. + inline unordered_set* getValSetPtr(const KEY& key) { + auto entry = mMap.find(key); + return (entry != mMap.end()) ? &(entry->second) : nullptr; + } - void getListOfSubscribedClients (DIT id, std :: list & out); + // This gets a copy of VALs pointed to by *key* + // If the entry is not in the map, an empty set will be returned. + inline unordered_set getValSet(const KEY& key) { + auto entry = mMap.find(key); + return (entry != mMap.end()) ? entry->second : unordered_set(0); + } - int remove (DIT id); + // This gets all the KEYs from the map + inline unordered_set getKeys() { + unordered_set keys(0); + for (auto entry : mMap) { + keys.insert(entry.first); + } + return keys; + } - void remove (const std :: list & r, std :: list & out); + inline bool remove(const KEY& key) { + return mMap.erase(key) > 0; + } - void remove (DIT id, const std :: list & r, std :: list & out); + // This looks into all the entries keyed by *keys*. Remove any VALs from the entries + // that also exist in *rVals*. If the entry is left with an empty set, the entry will + // be removed. The optional parameters *goneKeys* and *goneVals* will record the KEYs + // (or entries) and the collapsed VALs removed from the map, respectively. + inline void trimOrRemove(unordered_set&& keys, const unordered_set& rVals, + unordered_set* goneKeys, unordered_set* goneVals) { + trimOrRemove(keys, rVals, goneKeys, goneVals); + } + inline void trimOrRemove(unordered_set& keys, const unordered_set& rVals, + unordered_set* goneKeys, unordered_set* goneVals) { + for (auto key : keys) { + auto iter = mMap.find(key); + if (iter != mMap.end() && trimOrRemove(iter, rVals, goneVals) && nullptr != goneKeys) { + goneKeys->insert(iter->first); + } + } + } - void add (DIT id, const std :: list & l, std :: list & out); + // This adds all VALs from *newVals* to the map entry keyed by *key*. Or if it + // doesn't exist yet, add the set to the map. + bool add(const KEY& key, const unordered_set& newVals) { + bool newEntryAdded = false; + if (!newVals.empty()) { + auto iter = mMap.find(key); + if (iter != mMap.end()) { + iter->second.insert(newVals.begin(), newVals.end()); + } else { + mMap[key] = newVals; + newEntryAdded = true; + } + } + return newEntryAdded; + } - void add (CT client, const std :: list & l, std :: list & out); + // This adds to each of entries in the map keyed by *keys* with the VALs in the + // *enwVals*. If there new entries added (new key in *keys*), *newKeys*, if not + // null, would be populated with those keys. + inline void add(const unordered_set& keys, const unordered_set&& newVals, + unordered_set* newKeys) { + add(keys, newVals, newKeys); + } + inline void add(const unordered_set& keys, const unordered_set& newVals, + unordered_set* newKeys) { + for (auto key : keys) { + if (add(key, newVals) && nullptr != newKeys) { + newKeys->insert(key); + } + } + } -private: - std :: map < DIT, std :: list > mClientsPerDataItemMap; + // This puts *newVals* into the map keyed by *key*, and returns the VALs that are + // in effect removed from the keyed VAL set in the map entry. + // This call would also remove those same VALs from *newVals*. + inline unordered_set update(const KEY& key, unordered_set& newVals) { + unordered_set goneVals(0); + + if (newVals.empty()) { + mMap.erase(key); + } else { + auto curVals = mMap[key]; + mMap[key] = newVals; + goneVals = removeAndReturnInterset(curVals, newVals); + } + return goneVals; + } }; -} // namespace loc_core +} // namespace loc_util -#endif // #ifndef __DATAITEMINDEX_H__ +#endif // #ifndef __LOC_UNORDERDED_SETMAP_H__ From 1d7904e9a654bc2889128fb29e173caa8e289b5f Mon Sep 17 00:00:00 2001 From: Saurabh Srivastava Date: Fri, 19 Jan 2018 17:32:08 +0530 Subject: [PATCH 05/22] Moving location sockets from /data to /dev Keeping sockets in /data/vendor/location prevents unmounting of /data partition after build load. CRs-Fixed: 2174503 Change-Id: Ib1b9f07bb25368ac7d1a32536e58c52dd2b2ad4e --- utils/gps_extended_c.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index afe47ccc..e29b2a84 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -1314,8 +1314,8 @@ typedef void (*LocAgpsOpenResultCb)(bool isSuccess, AGpsExtType agpsType, const typedef void (*LocAgpsCloseResultCb)(bool isSuccess, AGpsExtType agpsType, void* userDataPtr); /* Shared resources of LocIpc */ -#define LOC_IPC_HAL "/data/vendor/location/socket_hal" -#define LOC_IPC_XTRA "/data/vendor/location/xtra/socket_xtra" +#define LOC_IPC_HAL "/dev/socket/location/socket_hal" +#define LOC_IPC_XTRA "/dev/socket/location/xtra/socket_xtra" #ifdef __cplusplus } From 56334a379159f127071dd4552c5a28654cd586a4 Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Fri, 2 Mar 2018 17:02:28 -0800 Subject: [PATCH 06/22] fix: Default values in GNSS Debug Data Change default values for accuracies and uncertainties in GNSS Debug Data to non- zero constant values. Bug: 72753638 Change-Id: I075b364ed81c8a466b062ab4d5381c3d4ece1ea6 CRs-Fixed: 2185247 --- android/GnssDebug.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/android/GnssDebug.cpp b/android/GnssDebug.cpp index 45cde6be..823c9b17 100644 --- a/android/GnssDebug.cpp +++ b/android/GnssDebug.cpp @@ -114,6 +114,23 @@ Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; } + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + // time block if (reports.mTime.mValid) { data.time.timeEstimate = reports.mTime.timeEstimate; From 98125ae628a59fae6f1a4da19200b799595fd47e Mon Sep 17 00:00:00 2001 From: Saurabh Srivastava Date: Mon, 9 Apr 2018 17:56:08 +0530 Subject: [PATCH 07/22] Adding Location Service Modem Emulator Adding Modem Emulator to test features not yet supported in Modem build. Change-Id: I86f4eeaa7577d83c5ef9605c78672068721c020e CRs-Fixed: 2193247 --- utils/loc_cfg.cpp | 17 +++++++++++++++-- utils/loc_cfg.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index 80379792..aa8d0e82 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -57,12 +57,14 @@ /* Parameter data */ static uint32_t DEBUG_LEVEL = 0xff; static uint32_t TIMESTAMP = 0; +static uint32_t LOC_MODEM_EMULATOR = 0; /* Parameter spec table */ static const loc_param_s_type loc_param_table[] = { - {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, - {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, + {"LOC_MODEM_EMULATOR", &LOC_MODEM_EMULATOR, NULL, 'n'}, }; static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); @@ -85,6 +87,17 @@ const char LOC_PATH_APDR_CONF[] = LOC_PATH_APDR_CONF_STR; const char LOC_PATH_XTWIFI_CONF[] = LOC_PATH_XTWIFI_CONF_STR; const char LOC_PATH_QUIPC_CONF[] = LOC_PATH_QUIPC_CONF_STR; +/*=========================================================================== +FUNCTION loc_modem_emulator_enabled + +DESCRIPTION + Provides access to Modem Emulator config item. +===========================================================================*/ +uint32_t loc_modem_emulator_enabled() +{ + return LOC_MODEM_EMULATOR; +} + /*=========================================================================== FUNCTION loc_set_config_entry diff --git a/utils/loc_cfg.h b/utils/loc_cfg.h index c89d3038..652d86eb 100644 --- a/utils/loc_cfg.h +++ b/utils/loc_cfg.h @@ -133,6 +133,8 @@ extern const char LOC_PATH_QUIPC_CONF[]; int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr, loc_process_info_s_type** process_info_table_ptr); +uint32_t loc_modem_emulator_enabled(); + #ifdef __cplusplus } #endif From 9bb67cc1d40bcdf3ec21fdf66373a134eeadd711 Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Thu, 3 May 2018 11:41:51 -0700 Subject: [PATCH 08/22] fix: Add intermediate fixes in gnss debug report Include intermediate location fix info in gnss debug report that is cached in SystemStatus in addition to final fixes, so that the gnss debug report should always hold the latest information. Change-Id: I60aef92cf6d143a1b4f4b510ca2113887d051dcc CRs-Fixed: 2230415 --- gnss/GnssAdapter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index a482acc0..d08bd447 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -2050,7 +2050,8 @@ GnssAdapter::reportPositionEvent(const UlpLocation& ulpLocation, inline virtual void proc() const { // extract bug report info - this returns true if consumed by systemstatus SystemStatus* s = mAdapter.getSystemStatus(); - if ((nullptr != s) && (LOC_SESS_SUCCESS == mStatus)){ + if ((nullptr != s) && + ((LOC_SESS_SUCCESS == mStatus) || (LOC_SESS_INTERMEDIATE == mStatus))){ s->eventPosition(mUlpLocation, mLocationExtended); } mAdapter.reportPosition(mUlpLocation, mLocationExtended, mStatus, mTechMask); From 1e824a912c76a87e5d35363036ba0916cfc4801e Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Tue, 13 Feb 2018 17:19:54 -0800 Subject: [PATCH 09/22] moving AGnssCbIface from static to class member mAGnssCbIface is a static C++ obj, which ctor may not get called at load time, but its memory block will only be 0'ed out. Change-Id: Ie275f916a01c5eb3bf0a7cfa71b19fe4e0d3e879 CRs-Fixed: 2190347 --- android/AGnss.cpp | 25 ++++++++++++++++++++----- android/AGnss.h | 6 ++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/android/AGnss.cpp b/android/AGnss.cpp index 2f7d38db..fe50c9a0 100644 --- a/android/AGnss.cpp +++ b/android/AGnss.cpp @@ -30,12 +30,23 @@ namespace gnss { namespace V1_1 { namespace implementation { -sp AGnss::sAGnssCbIface = nullptr; +static AGnss* spAGnss = nullptr; AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { + spAGnss = this; +} + +AGnss::~AGnss() { + spAGnss = nullptr; } void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){ + if (nullptr != spAGnss) { + spAGnss->statusIpV4Cb(status); + } +} + +void AGnss::statusIpV4Cb(AGnssExtStatusIpV4 status) { IAGnssCallback::AGnssStatusIpV4 st = {}; switch (status.type) { @@ -72,9 +83,13 @@ void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){ } st.ipV4Addr = status.ipV4Addr; - auto r = sAGnssCbIface->agnssStatusIpV4Cb(st); - if (!r.isOk()) { - LOC_LOGE("Error invoking AGNSS status cb %s", r.description().c_str()); + if (mAGnssCbIface != nullptr) { + auto r = mAGnssCbIface->agnssStatusIpV4Cb(st); + if (!r.isOk()) { + LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); } } @@ -86,7 +101,7 @@ Return AGnss::setCallback(const sp& callback) { } // Save the interface - sAGnssCbIface = callback; + mAGnssCbIface = callback; AgpsCbInfo cbInfo = {}; cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; diff --git a/android/AGnss.h b/android/AGnss.h index 464d87ee..4b599b94 100644 --- a/android/AGnss.h +++ b/android/AGnss.h @@ -43,7 +43,7 @@ struct Gnss; struct AGnss : public IAGnss { AGnss(Gnss* gnss); - ~AGnss() = default; + ~AGnss(); /* * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow. * These declarations were generated from IAGnss.hal. @@ -60,12 +60,14 @@ struct AGnss : public IAGnss { Return setServer(IAGnssCallback::AGnssType type, const hidl_string& hostname, int32_t port) override; + void statusIpV4Cb(AGnssExtStatusIpV4 status); + /* Data call setup callback passed down to GNSS HAL implementation */ static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); private: Gnss* mGnss = nullptr; - static sp sAGnssCbIface; + sp mAGnssCbIface = nullptr; }; } // namespace implementation From f708597ed37fc1d77398c5f1de4678fbab66080c Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Mon, 7 May 2018 09:45:20 -0700 Subject: [PATCH 10/22] fix: Incorrect time estimate in debug report GNSS Time estimate shown in Gnss debug report is incorrect. It always shows default value instead of value delivered by PQWM1 message. Change-Id: Iff471613ac6fa25d213c14b543871b6c3ae7af0a CRs-Fixed: 2235219 --- android/GnssDebug.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android/GnssDebug.cpp b/android/GnssDebug.cpp index 823c9b17..94238abc 100644 --- a/android/GnssDebug.cpp +++ b/android/GnssDebug.cpp @@ -139,8 +139,7 @@ Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) reports.mTime.frequencyUncertaintyNsPerSec; } - if (data.time.timeEstimate <= 0 || - data.time.timeEstimate > GNSS_DEBUG_UNKNOWN_UTC_TIME) { + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; } if (data.time.timeUncertaintyNs <= 0 || From fdab877f359f323d322f2c109cc98b443e4a9b98 Mon Sep 17 00:00:00 2001 From: Saurabh Srivastava Date: Wed, 21 Feb 2018 16:04:28 +0530 Subject: [PATCH 11/22] KW Warning Fix Check file pointer before closing. Change-Id: Id9526f6eacf57e282dc0af35d72f571f950b0b0e CRs-Fixed: 2193268 --- utils/loc_cfg.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index aa8d0e82..200293fc 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -1129,7 +1129,9 @@ int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_p } err: - fclose(conf_fp); + if (conf_fp) { + fclose(conf_fp); + } if (ret != 0) { LOC_LOGE("%s:%d]: ret: %d", __func__, __LINE__, ret); if (child_proc) { From 533f43e690fd5faef877ba572ef4702f74a18c7b Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Mon, 9 Apr 2018 14:32:28 -0700 Subject: [PATCH 12/22] Fixed a number of issues with NetworkInfoDataItemBase There are a couple of issues. NetworkInfoDataItemBase objects might be from OsAgent or GnssLocationProvider. The two sources actually have mTypes defined differently. In addtion, when there are different types of connections such as wifi / mobile, getting connected / disconnected independently, clients need to be all notified correctly. Right now, if mConnected hasn't changed, no updates are send. For exmple, if mobile is connected, later wifi gets connected too, clients won't know. SystemStatus is also updated to get updated / colated informtion. In the above example, SystemStatus's top record would record as both mobile and wifi are connected. Change-Id: I1825902247fe1d4e6363f5e24a75be7e984d0dc4 CRs-Fixed: 2221114 --- core/SystemStatus.cpp | 113 +++++++++----------- core/SystemStatus.h | 43 +++++--- core/data-items/DataItemConcreteTypesBase.h | 32 +++--- gnss/XtraSystemStatusObserver.cpp | 26 +---- gnss/XtraSystemStatusObserver.h | 10 +- 5 files changed, 107 insertions(+), 117 deletions(-) diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index e12d9f32..5d5c4b08 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -1250,8 +1250,7 @@ IOsObserver* SystemStatus::getOsObserver() } SystemStatus::SystemStatus(const MsgTask* msgTask) : - mSysStatusObsvr(this, msgTask), - mConnected(false) + mSysStatusObsvr(this, msgTask) { int result = 0; ENTRY_LOG (); @@ -1301,17 +1300,10 @@ SystemStatus::SystemStatus(const MsgTask* msgTask) : /****************************************************************************** SystemStatus - storing dataitems ******************************************************************************/ -template -bool SystemStatus::setItemBaseinReport(TYPE_REPORT& report, const TYPE_ITEMBASE& s) -{ - TYPE_SYSTEMSTATUS_ITEM sout(s); - return setIteminReport(report, sout); -} - template -bool SystemStatus::setIteminReport(TYPE_REPORT& report, const TYPE_ITEM& s) +bool SystemStatus::setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s) { - if (!report.empty() && report.back().equals(s)) { + if (!report.empty() && report.back().equals(static_cast(s.collate(report.back())))) { // there is no change - just update reported timestamp report.back().mUtcReported = s.mUtcReported; return false; @@ -1449,94 +1441,92 @@ bool SystemStatus::eventDataItemNotify(IDataItemCore* dataitem) switch(dataitem->getId()) { case AIRPLANEMODE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mAirplaneMode, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mAirplaneMode, + SystemStatusAirplaneMode(*(static_cast(dataitem)))); break; case ENH_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mENH, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mENH, + SystemStatusENH(*(static_cast(dataitem)))); break; case GPSSTATE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mGPSState, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mGPSState, + SystemStatusGpsState(*(static_cast(dataitem)))); break; case NLPSTATUS_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mNLPStatus, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mNLPStatus, + SystemStatusNLPStatus(*(static_cast(dataitem)))); break; case WIFIHARDWARESTATE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mWifiHardwareState, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mWifiHardwareState, + SystemStatusWifiHardwareState(*(static_cast(dataitem)))); break; case NETWORKINFO_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mNetworkInfo, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mNetworkInfo, + SystemStatusNetworkInfo(*(static_cast(dataitem)))); break; case RILSERVICEINFO_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mRilServiceInfo, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mRilServiceInfo, + SystemStatusServiceInfo(*(static_cast(dataitem)))); break; case RILCELLINFO_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mRilCellInfo, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mRilCellInfo, + SystemStatusRilCellInfo(*(static_cast(dataitem)))); break; case SERVICESTATUS_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mServiceStatus, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mServiceStatus, + SystemStatusServiceStatus(*(static_cast(dataitem)))); break; case MODEL_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mModel, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mModel, + SystemStatusModel(*(static_cast(dataitem)))); break; case MANUFACTURER_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mManufacturer, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mManufacturer, + SystemStatusManufacturer(*(static_cast(dataitem)))); break; case ASSISTED_GPS_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mAssistedGps, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mAssistedGps, + SystemStatusAssistedGps(*(static_cast(dataitem)))); break; case SCREEN_STATE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mScreenState, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mScreenState, + SystemStatusScreenState(*(static_cast(dataitem)))); break; case POWER_CONNECTED_STATE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mPowerConnectState, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mPowerConnectState, + SystemStatusPowerConnectState(*(static_cast(dataitem)))); break; case TIMEZONE_CHANGE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mTimeZoneChange, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mTimeZoneChange, + SystemStatusTimeZoneChange(*(static_cast(dataitem)))); break; case TIME_CHANGE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mTimeChange, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mTimeChange, + SystemStatusTimeChange(*(static_cast(dataitem)))); break; case WIFI_SUPPLICANT_STATUS_DATA_ITEM_ID: - ret = setItemBaseinReport( - mCache.mWifiSupplicantStatus, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mWifiSupplicantStatus, + SystemStatusWifiSupplicantStatus(*(static_cast(dataitem)))); break; case SHUTDOWN_STATE_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mShutdownState, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mShutdownState, + SystemStatusShutdownState(*(static_cast(dataitem)))); break; case TAC_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mTac, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mTac, + SystemStatusTac(*(static_cast(dataitem)))); break; case MCCMNC_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mMccMnc, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mMccMnc, + SystemStatusMccMnc(*(static_cast(dataitem)))); break; case BTLE_SCAN_DATA_ITEM_ID: - ret = setItemBaseinReport(mCache.mBtDeviceScanDetail, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mBtDeviceScanDetail, + SystemStatusBtDeviceScanDetail(*(static_cast(dataitem)))); break; case BT_SCAN_DATA_ITEM_ID: - ret = setItemBaseinReport( - mCache.mBtLeDeviceScanDetail, - *(static_cast(dataitem))); + ret = setIteminReport(mCache.mBtLeDeviceScanDetail, + SystemStatusBtleDeviceScanDetail(*(static_cast(dataitem)))); break; default: break; @@ -1689,13 +1679,10 @@ bool SystemStatus::setDefaultGnssEngineStates(void) ******************************************************************************/ bool SystemStatus::eventConnectionStatus(bool connected, int8_t type) { - if (connected != mConnected) { - mConnected = connected; + // send networkinof dataitem to systemstatus observer clients + SystemStatusNetworkInfo s(type, "", "", false, connected, false); + mSysStatusObsvr.notify({&s}); - // send networkinof dataitem to systemstatus observer clients - SystemStatusNetworkInfo s(type, "", "", false, connected, false); - mSysStatusObsvr.notify({&s}); - } return true; } diff --git a/core/SystemStatus.h b/core/SystemStatus.h index 9500264d..1c3adc84 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -77,8 +77,11 @@ public: mUtcTime.tv_nsec = tv.tv_nsec; mUtcReported = mUtcTime; }; - virtual ~SystemStatusItemBase() { }; - virtual void dump(void) { }; + virtual ~SystemStatusItemBase() {}; + inline virtual SystemStatusItemBase& collate(SystemStatusItemBase&) { + return *this; + } + virtual void dump(void) {}; }; class SystemStatusLocation : public SystemStatusItemBase @@ -93,7 +96,7 @@ public: const GpsLocationExtended& locationEx) : mValid(true), mLocation(location), - mLocationEx(locationEx) { } + mLocationEx(locationEx) {} bool equals(const SystemStatusLocation& peer); void dump(void); }; @@ -457,6 +460,7 @@ public: class SystemStatusNetworkInfo : public SystemStatusItemBase, public NetworkInfoDataItemBase { + NetworkInfoDataItemBase* mSrcObjPtr; public: inline SystemStatusNetworkInfo( int32_t type=0, @@ -466,18 +470,21 @@ public: bool connected=false, bool roaming=false) : NetworkInfoDataItemBase( + (NetworkType)type, type, typeName, subTypeName, available, connected, - roaming) {} + roaming), + mSrcObjPtr(nullptr) {} inline SystemStatusNetworkInfo(const NetworkInfoDataItemBase& itemBase) : - NetworkInfoDataItemBase(itemBase) { + NetworkInfoDataItemBase(itemBase), + mSrcObjPtr((NetworkInfoDataItemBase*)&itemBase) { mType = itemBase.getType(); } inline bool equals(const SystemStatusNetworkInfo& peer) { - if ((mType == peer.mType) && + if ((mAllTypes == peer.mAllTypes) && (mTypeName == peer.mTypeName) && (mSubTypeName == peer.mSubTypeName) && (mAvailable == peer.mAvailable) && @@ -487,8 +494,24 @@ public: } return false; } + inline virtual SystemStatusItemBase& collate(SystemStatusItemBase& curInfo) { + uint64_t allTypes = (static_cast(curInfo)).mAllTypes; + if (mConnected) { + mAllTypes |= allTypes; + } else if (0 != mAllTypes) { + mAllTypes = (allTypes & (~mAllTypes)); + } // else (mConnected == false && mAllTypes == 0) + // we keep mAllTypes as 0, which means no more connections. + + if (nullptr != mSrcObjPtr) { + // this is critical, changing mAllTypes of the original obj + mSrcObjPtr->mAllTypes = mAllTypes; + } + return *this; + } inline void dump(void) override { - LOC_LOGD("NetworkInfo: type=%u connected=%u", mType, mConnected); + LOC_LOGD("NetworkInfo: mAllTypes=%" PRIx64 " connected=%u mType=%x", + mAllTypes, mConnected, mType); } }; @@ -783,13 +806,9 @@ private: // Data members static pthread_mutex_t mMutexSystemStatus; SystemStatusReports mCache; - bool mConnected; - - template - bool setItemBaseinReport(TYPE_REPORT& report, const TYPE_ITEMBASE& s); template - bool setIteminReport(TYPE_REPORT& report, const TYPE_ITEM& s); + bool setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s); // set default dataitem derived item in report cache template diff --git a/core/data-items/DataItemConcreteTypesBase.h b/core/data-items/DataItemConcreteTypesBase.h index fd744088..065366d3 100644 --- a/core/data-items/DataItemConcreteTypesBase.h +++ b/core/data-items/DataItemConcreteTypesBase.h @@ -221,9 +221,23 @@ protected: class NetworkInfoDataItemBase : public IDataItemCore { public: + enum NetworkType { + TYPE_MOBILE, + TYPE_WIFI, + TYPE_ETHERNET, + TYPE_BLUETOOTH, + TYPE_MMS, + TYPE_SUPL, + TYPE_DUN, + TYPE_HIPRI, + TYPE_WIMAX, + TYPE_UNKNOWN, + }; NetworkInfoDataItemBase( - int32_t type, string typeName, string subTypeName, + NetworkType initialType, int32_t type, string typeName, string subTypeName, bool available, bool connected, bool roaming ): + mAllTypes((initialType >= TYPE_UNKNOWN || initialType < TYPE_MOBILE) ? + 0 : (1<& dlist) { NetworkInfoDataItemBase* networkInfo = static_cast(each); - mXtraSysStatObj->updateConnectionStatus(networkInfo->mConnected, - networkInfo->mType); + mXtraSysStatObj->updateConnections(networkInfo->getAllTypes()); } break; diff --git a/gnss/XtraSystemStatusObserver.h b/gnss/XtraSystemStatusObserver.h index 31d80834..af0789b6 100644 --- a/gnss/XtraSystemStatusObserver.h +++ b/gnss/XtraSystemStatusObserver.h @@ -33,22 +33,20 @@ #include #include #include -#include using namespace std; using loc_core::IOsObserver; using loc_core::IDataItemObserver; using loc_core::IDataItemCore; using loc_util::LocIpc; -using CONNECTIONS = set; class XtraSystemStatusObserver : public IDataItemObserver, public LocIpc{ public : // constructor & destructor inline XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask): mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask), - mGpsLock(-1), mXtraThrottle(true), mReqStatusReceived(false), - mIsConnectivityStatusKnown (false), mDelayLocTimer(*this) { + mGpsLock(-1), mConnections(0), mXtraThrottle(true), mReqStatusReceived(false), + mDelayLocTimer(*this), mIsConnectivityStatusKnown (false) { subscribe(true); startListeningNonBlocking(LOC_IPC_HAL); mDelayLocTimer.start(100 /*.1 sec*/, false); @@ -63,7 +61,7 @@ public : virtual void notify(const list& dlist); bool updateLockStatus(uint32_t lock); - bool updateConnectionStatus(bool connected, int32_t type); + bool updateConnections(uint64_t allConnections); bool updateTac(const string& tac); bool updateMccMnc(const string& mccmnc); bool updateXtraThrottle(const bool enabled); @@ -77,7 +75,7 @@ private: IOsObserver* mSystemStatusObsrvr; const MsgTask* mMsgTask; int32_t mGpsLock; - CONNECTIONS mConnections; + uint64_t mConnections; string mTac; string mMccmnc; bool mXtraThrottle; From 2683aef90a0f2a2dd88020417a94b406d461a204 Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Fri, 23 Mar 2018 10:32:51 -0700 Subject: [PATCH 13/22] fix: LocIpc client app unable to exit LocIpc client apps such as garden app is unable to delete LocIpc object since its socket listening thread cannot be closed while it is waiting for data and cannot be closed. Fixed to close it by sending an abort message. CRs-Fixed: 2213212 Change-Id: I95f26862e9faf7bd75a2f447421ba4ab7220576e --- utils/LocIpc.cpp | 37 ++++++++++++++++++++++++------------- utils/LocIpc.h | 3 +-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/utils/LocIpc.cpp b/utils/LocIpc.cpp index 26a20765..675664a5 100644 --- a/utils/LocIpc.cpp +++ b/utils/LocIpc.cpp @@ -28,19 +28,9 @@ */ #include -#include -#include #include -#include #include -#include -#include -#include -#include #include -#include -#include -#include "gps_extended_c.h" #include "LocIpc.h" namespace loc_util { @@ -52,8 +42,10 @@ namespace loc_util { #define LOC_MSG_BUF_LEN 8192 #define LOC_MSG_HEAD "$MSGLEN$" +#define LOC_MSG_ABORT "LocIpcMsg::ABORT" class LocIpcRunnable : public LocRunnable { +friend LocIpc; public: LocIpcRunnable(LocIpc& locIpc, const std::string& ipcName) : mLocIpc(locIpc), mIpcName(ipcName) {} @@ -70,10 +62,10 @@ private: }; bool LocIpc::startListeningNonBlocking(const std::string& name) { - mRunnable.reset(new LocIpcRunnable(*this, name)); + mRunnable = new LocIpcRunnable(*this, name); std::string threadName("LocIpc-"); threadName.append(name); - return mThread.start(threadName.c_str(), mRunnable.get()); + return mThread.start(threadName.c_str(), mRunnable); } bool LocIpc::startListeningBlocking(const std::string& name) { @@ -107,6 +99,7 @@ bool LocIpc::startListeningBlocking(const std::string& name) { ssize_t nBytes = 0; std::string msg = ""; + std::string abort = LOC_MSG_ABORT; while (1) { msg.resize(LOC_MSG_BUF_LEN); nBytes = ::recvfrom(mIpcFd, (void*)(msg.data()), msg.size(), 0, NULL, NULL); @@ -116,6 +109,11 @@ bool LocIpc::startListeningBlocking(const std::string& name) { continue; } + if (strncmp(msg.data(), abort.c_str(), abort.length()) == 0) { + LOC_LOGi("recvd abort msg.data %s", msg.data()); + break; + } + if (strncmp(msg.data(), LOC_MSG_HEAD, sizeof(LOC_MSG_HEAD) - 1)) { // short message msg.resize(nBytes); @@ -142,7 +140,6 @@ bool LocIpc::startListeningBlocking(const std::string& name) { if (mStopRequested) { mStopRequested = false; return true; - } else { LOC_LOGe("cannot read socket. reason:%s", strerror(errno)); (void)::close(mIpcFd); @@ -152,14 +149,28 @@ bool LocIpc::startListeningBlocking(const std::string& name) { } void LocIpc::stopListening() { + + const char *socketName = nullptr; mStopRequested = true; + if (mRunnable) { + std::string abort = LOC_MSG_ABORT; + socketName = (reinterpret_cast(mRunnable))->mIpcName.c_str(); + send(socketName, abort); + mRunnable = nullptr; + } + if (mIpcFd >= 0) { if (::close(mIpcFd)) { LOC_LOGe("cannot close socket:%s", strerror(errno)); } mIpcFd = -1; } + + //delete from the file system at the end + if (socketName) { + unlink(socketName); + } } bool LocIpc::send(const char name[], const std::string& data) { diff --git a/utils/LocIpc.h b/utils/LocIpc.h index 8598a327..364093bd 100644 --- a/utils/LocIpc.h +++ b/utils/LocIpc.h @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -96,7 +95,7 @@ private: int mIpcFd; bool mStopRequested; LocThread mThread; - std::unique_ptr mRunnable; + LocRunnable *mRunnable; }; class LocIpcSender { From 5c25b329da9cf8c6d15bc0f5c0219e9accbf5f46 Mon Sep 17 00:00:00 2001 From: Katz Yamada Date: Tue, 20 Mar 2018 15:50:53 -0700 Subject: [PATCH 14/22] fix: add LOC_LOGi macro in log utility Add LOC_LOGi macro in log utility Change-Id: Ib30ce891496d61c10075cac028a80df2a6013a2a CRs-Fixed: 2209625 --- utils/log_util.h | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/log_util.h b/utils/log_util.h index 460d6e7e..feb4d3cb 100644 --- a/utils/log_util.h +++ b/utils/log_util.h @@ -141,6 +141,7 @@ extern char* get_timestamp(char* str, unsigned long buf_size); #define LOC_LOG_HEAD(fmt) "%s:%d] " fmt #define LOC_LOGv(fmt,...) LOC_LOGV(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define LOC_LOGw(fmt,...) LOC_LOGW(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define LOC_LOGi(fmt,...) LOC_LOGI(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define LOC_LOGd(fmt,...) LOC_LOGD(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define LOC_LOGe(fmt,...) LOC_LOGE(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) From e9c3f04f8628883091ca0912dd50b80fb9560316 Mon Sep 17 00:00:00 2001 From: Baili Feng Date: Mon, 21 May 2018 19:55:18 +0800 Subject: [PATCH 15/22] Replace MONOTONIC clock with BOOTTIME clock MONOTONIC clock doesn't tick when device is in suspend mode. BOOTTIME clock handles suspend mode while. Change-Id: I14ce943ddfd409fcc5cb70acde0cd4f5c94d1058 CRs-Fixed: 2241735 --- core/SystemStatus.h | 6 +++--- gnss/GnssAdapter.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/SystemStatus.h b/core/SystemStatus.h index 1c3adc84..ff5e7548 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -71,10 +71,10 @@ public: static const uint32_t maxItem = 5; SystemStatusItemBase() { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); + timeval tv; + gettimeofday(&tv, NULL); mUtcTime.tv_sec = tv.tv_sec; - mUtcTime.tv_nsec = tv.tv_nsec; + mUtcTime.tv_nsec = tv.tv_usec *1000ULL; mUtcReported = mUtcTime; }; virtual ~SystemStatusItemBase() {}; diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index d08bd447..9ab1fd6a 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -86,7 +86,7 @@ GnssAdapter::GnssAdapter() : pthread_condattr_t condAttr; pthread_condattr_init(&condAttr); - pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC); + pthread_condattr_setclock(&condAttr, CLOCK_BOOTTIME); pthread_cond_init(&mNiData.session.tCond, &condAttr); pthread_cond_init(&mNiData.sessionEs.tCond, &condAttr); pthread_condattr_destroy(&condAttr); @@ -2343,7 +2343,7 @@ static void* niThreadProc(void *args) pthread_mutex_lock(&pSession->tLock); /* Calculate absolute expire time */ - clock_gettime(CLOCK_MONOTONIC, &present_time); + clock_gettime(CLOCK_BOOTTIME, &present_time); expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft; expire_time.tv_nsec = present_time.tv_nsec; LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec", From 5891ffe9bc6c522ce1907a60e303a0c5587a358a Mon Sep 17 00:00:00 2001 From: Mike Cailean Date: Mon, 21 May 2018 14:33:14 -0700 Subject: [PATCH 16/22] Add AGC value for QZSS measurement report Add AGC value for QZSS measurement report to Android framework - value is the same as GPS Change-Id: I1e3106d99d124945be7f1bda725a413be11a75e6 CRs-fixed: 2245786 --- gnss/GnssAdapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 9ab1fd6a..fd26ac1e 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -3182,6 +3182,7 @@ GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int m for (size_t i = 0; i < measurements.count; i++) { switch (measurements.measurements[i].svType) { case GNSS_SV_TYPE_GPS: + case GNSS_SV_TYPE_QZSS: measurements.measurements[i].agcLevelDb = reports.mRfAndParams.back().mAgcGps; measurements.measurements[i].flags |= @@ -3209,7 +3210,6 @@ GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int m GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; break; - case GNSS_SV_TYPE_QZSS: case GNSS_SV_TYPE_SBAS: case GNSS_SV_TYPE_UNKNOWN: default: From 4c4660c11be67a6b5ce60ab427ae3a07d0f3354c Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Fri, 11 May 2018 10:03:33 -0700 Subject: [PATCH 17/22] fixed data items for service and cell info which right now are not keeping any data into the SSOO's table, therefore it is not able to determine if the new data arrives is different than the current one. This results in not passing the following data updates to the clients. Change-Id: Ieb94e959228d9a9f8d43b090f3328208387d864f CRs-Fixed: 2239616 --- core/SystemStatus.h | 10 ++++--- core/data-items/DataItemConcreteTypesBase.h | 30 ++++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/core/SystemStatus.h b/core/SystemStatus.h index ff5e7548..46e004a8 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -523,8 +523,9 @@ public: RilServiceInfoDataItemBase() {} inline SystemStatusServiceInfo(const RilServiceInfoDataItemBase& itemBase) : RilServiceInfoDataItemBase(itemBase) {} - inline bool equals(const SystemStatusServiceInfo& /*peer*/) { - return true; + inline bool equals(const SystemStatusServiceInfo& peer) { + return static_cast(peer) == + static_cast(*this); } }; @@ -536,8 +537,9 @@ public: RilCellInfoDataItemBase() {} inline SystemStatusRilCellInfo(const RilCellInfoDataItemBase& itemBase) : RilCellInfoDataItemBase(itemBase) {} - inline bool equals(const SystemStatusRilCellInfo& /*peer*/) { - return true; + inline bool equals(const SystemStatusRilCellInfo& peer) { + return static_cast(peer) == + static_cast(*this); } }; diff --git a/core/data-items/DataItemConcreteTypesBase.h b/core/data-items/DataItemConcreteTypesBase.h index 065366d3..d35c5450 100644 --- a/core/data-items/DataItemConcreteTypesBase.h +++ b/core/data-items/DataItemConcreteTypesBase.h @@ -313,24 +313,42 @@ protected: class RilServiceInfoDataItemBase : public IDataItemCore { public: - RilServiceInfoDataItemBase() : - mId(RILSERVICEINFO_DATA_ITEM_ID) {} - virtual ~RilServiceInfoDataItemBase() {} + inline RilServiceInfoDataItemBase() : + mData(nullptr), mId(RILSERVICEINFO_DATA_ITEM_ID) {} + inline virtual ~RilServiceInfoDataItemBase() { if (nullptr != mData) free(mData); } inline virtual DataItemId getId() { return mId; } virtual void stringify(string& /*valueStr*/) {} virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} + inline RilServiceInfoDataItemBase(const RilServiceInfoDataItemBase& peer) : + RilServiceInfoDataItemBase() { + peer.setPeerData(*this); + } + inline virtual bool operator==(const RilServiceInfoDataItemBase& other) const { + return other.mData == mData; + } + inline virtual void setPeerData(RilServiceInfoDataItemBase& /*peer*/) const {} + void* mData; protected: DataItemId mId; }; class RilCellInfoDataItemBase : public IDataItemCore { public: - RilCellInfoDataItemBase() : - mId(RILCELLINFO_DATA_ITEM_ID) {} - virtual ~RilCellInfoDataItemBase() {} + inline RilCellInfoDataItemBase() : + mData(nullptr), mId(RILCELLINFO_DATA_ITEM_ID) {} + inline virtual ~RilCellInfoDataItemBase() { if (nullptr != mData) free(mData); } inline virtual DataItemId getId() { return mId; } virtual void stringify(string& /*valueStr*/) {} virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} + inline RilCellInfoDataItemBase(const RilCellInfoDataItemBase& peer) : + RilCellInfoDataItemBase() { + peer.setPeerData(*this); + } + inline virtual bool operator==(const RilCellInfoDataItemBase& other) const { + return other.mData == mData; + } + inline virtual void setPeerData(RilCellInfoDataItemBase& /*peer*/) const {} + void* mData; protected: DataItemId mId; }; From 2c817bdc5851629cb039ebcd26f46d9167adbb01 Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Thu, 7 Jun 2018 15:26:26 -0700 Subject: [PATCH 18/22] Revert "Replace MONOTONIC clock with BOOTTIME clock" This reverts commit e9c3f04f8628883091ca0912dd50b80fb9560316. Change-Id: Iabdead2a535b26bc3f7df1987265c4e2aea4f62e CRs-Fixed: 2241735 --- core/SystemStatus.h | 6 +++--- gnss/GnssAdapter.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/SystemStatus.h b/core/SystemStatus.h index 46e004a8..ac59cdc7 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -71,10 +71,10 @@ public: static const uint32_t maxItem = 5; SystemStatusItemBase() { - timeval tv; - gettimeofday(&tv, NULL); + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); mUtcTime.tv_sec = tv.tv_sec; - mUtcTime.tv_nsec = tv.tv_usec *1000ULL; + mUtcTime.tv_nsec = tv.tv_nsec; mUtcReported = mUtcTime; }; virtual ~SystemStatusItemBase() {}; diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index fd26ac1e..30bc4212 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -86,7 +86,7 @@ GnssAdapter::GnssAdapter() : pthread_condattr_t condAttr; pthread_condattr_init(&condAttr); - pthread_condattr_setclock(&condAttr, CLOCK_BOOTTIME); + pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC); pthread_cond_init(&mNiData.session.tCond, &condAttr); pthread_cond_init(&mNiData.sessionEs.tCond, &condAttr); pthread_condattr_destroy(&condAttr); @@ -2343,7 +2343,7 @@ static void* niThreadProc(void *args) pthread_mutex_lock(&pSession->tLock); /* Calculate absolute expire time */ - clock_gettime(CLOCK_BOOTTIME, &present_time); + clock_gettime(CLOCK_MONOTONIC, &present_time); expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft; expire_time.tv_nsec = present_time.tv_nsec; LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec", From ccdb671f87cad33335c0389576335907876fc388 Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Wed, 30 May 2018 17:44:25 -0700 Subject: [PATCH 19/22] DataItem changes to fix incorrect NetworkInfo connect handling NetworkInfoBaase added a type to allTypes protected method so that derived class can use it. Also, the SystemStatusNetworkInfo no longer compares names in its equal(), as it only is going to return false when comparing GnssLocationProvider NetworkInfo and OsAgent NetworkInfo. Change-Id: I363f27f4ed7be4aab2a4c4c033d5dff69d0a47d9 CRs-Fixed: 2251564 --- core/SystemStatus.cpp | 2 +- core/SystemStatus.h | 13 ++----------- core/data-items/DataItemConcreteTypesBase.h | 7 ++++--- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index 5d5c4b08..b3260bdd 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -1680,7 +1680,7 @@ bool SystemStatus::setDefaultGnssEngineStates(void) bool SystemStatus::eventConnectionStatus(bool connected, int8_t type) { // send networkinof dataitem to systemstatus observer clients - SystemStatusNetworkInfo s(type, "", "", false, connected, false); + SystemStatusNetworkInfo s(type, "", "", connected); mSysStatusObsvr.notify({&s}); return true; diff --git a/core/SystemStatus.h b/core/SystemStatus.h index ac59cdc7..b2f4fb6a 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -466,7 +466,6 @@ public: int32_t type=0, std::string typeName="", string subTypeName="", - bool available=false, bool connected=false, bool roaming=false) : NetworkInfoDataItemBase( @@ -474,7 +473,7 @@ public: type, typeName, subTypeName, - available, + connected && (!roaming), connected, roaming), mSrcObjPtr(nullptr) {} @@ -484,15 +483,7 @@ public: mType = itemBase.getType(); } inline bool equals(const SystemStatusNetworkInfo& peer) { - if ((mAllTypes == peer.mAllTypes) && - (mTypeName == peer.mTypeName) && - (mSubTypeName == peer.mSubTypeName) && - (mAvailable == peer.mAvailable) && - (mConnected == peer.mConnected) && - (mRoaming == peer.mRoaming)) { - return true; - } - return false; + return (mAllTypes == peer.mAllTypes); } inline virtual SystemStatusItemBase& collate(SystemStatusItemBase& curInfo) { uint64_t allTypes = (static_cast(curInfo)).mAllTypes; diff --git a/core/data-items/DataItemConcreteTypesBase.h b/core/data-items/DataItemConcreteTypesBase.h index d35c5450..bcb8d725 100644 --- a/core/data-items/DataItemConcreteTypesBase.h +++ b/core/data-items/DataItemConcreteTypesBase.h @@ -236,8 +236,7 @@ public: NetworkInfoDataItemBase( NetworkType initialType, int32_t type, string typeName, string subTypeName, bool available, bool connected, bool roaming ): - mAllTypes((initialType >= TYPE_UNKNOWN || initialType < TYPE_MOBILE) ? - 0 : (1<= TYPE_UNKNOWN || type < TYPE_MOBILE) ? 0 : (1< Date: Thu, 21 Jun 2018 15:16:33 +0800 Subject: [PATCH 20/22] Correct the nmea sv info in the first fix Use the sv used info from postion report to correct nmea GPGSA in the first fix and decouple from the sv report. Change-Id: Ibc94f5b51f4112951a2bb13d83b757fa4088eb5c CRs-fixed: 2261346 --- utils/loc_nmea.cpp | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/utils/loc_nmea.cpp b/utils/loc_nmea.cpp index dd6b1285..558dc65b 100644 --- a/utils/loc_nmea.cpp +++ b/utils/loc_nmea.cpp @@ -73,8 +73,6 @@ typedef struct loc_sv_cache_info_s float vdop; } loc_sv_cache_info; -static loc_sv_cache_info sv_cache_info; - /*=========================================================================== FUNCTION loc_nmea_sv_meta_init @@ -92,6 +90,7 @@ SIDE EFFECTS ===========================================================================*/ static loc_nmea_sv_meta* loc_nmea_sv_meta_init(loc_nmea_sv_meta& sv_meta, + loc_sv_cache_info& sv_cache_info, GnssSvType svType, bool needCombine) { @@ -498,7 +497,20 @@ void loc_nmea_generate_pos(const UlpLocation &location, int utcMinutes = pTm->tm_min; int utcSeconds = pTm->tm_sec; int utcMSeconds = (location.gpsLocation.timestamp)%1000; + loc_sv_cache_info sv_cache_info = {}; + if (GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA & locationExtended.flags) { + sv_cache_info.gps_used_mask = + (uint32_t)locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask; + sv_cache_info.glo_used_mask = + (uint32_t)locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask; + sv_cache_info.gal_used_mask = + (uint32_t)locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask; + sv_cache_info.qzss_used_mask = + (uint32_t)locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask; + sv_cache_info.bds_used_mask = + (uint32_t)locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask; + } if (generate_nmea) { char talker[3] = {'G', 'P', '\0'}; uint32_t svUsedCount = 0; @@ -509,7 +521,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, // ------------------- count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GPS, true), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, true), + nmeaArraystr); if (count > 0) { svUsedCount += count; @@ -522,7 +535,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, // ------------------- count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GLONASS, true), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GLONASS, true), + nmeaArraystr); if (count > 0) { svUsedCount += count; @@ -535,7 +549,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, // ------------------- count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GALILEO, true), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, true), + nmeaArraystr); if (count > 0) { svUsedCount += count; @@ -548,7 +563,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, // -------------------------- count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_QZSS, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, false), + nmeaArraystr); if (count > 0) { svUsedCount += count; @@ -559,7 +575,8 @@ void loc_nmea_generate_pos(const UlpLocation &location, // ---$PQGSA/$GNGSA (BEIDOU)--- // ---------------------------- count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_BEIDOU, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, false), + nmeaArraystr); if (count > 0) { svUsedCount += count; @@ -931,13 +948,6 @@ void loc_nmea_generate_pos(const UlpLocation &location, length = loc_nmea_put_checksum(sentence, sizeof(sentence)); nmeaArraystr.push_back(sentence); - - // clear the cache so they can't be used again - sv_cache_info.gps_used_mask = 0; - sv_cache_info.glo_used_mask = 0; - sv_cache_info.gal_used_mask = 0; - sv_cache_info.qzss_used_mask = 0; - sv_cache_info.bds_used_mask = 0; } //Send blank NMEA reports for non-final fixes else { @@ -995,20 +1005,9 @@ void loc_nmea_generate_sv(const GnssSvNotification &svNotify, char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0}; int svCount = svNotify.count; int svNumber = 1; + loc_sv_cache_info sv_cache_info = {}; //Count GPS SVs for saparating GPS from GLONASS and throw others - - sv_cache_info.gps_used_mask = 0; - sv_cache_info.glo_used_mask = 0; - sv_cache_info.gal_used_mask = 0; - sv_cache_info.qzss_used_mask = 0; - sv_cache_info.bds_used_mask = 0; - - sv_cache_info.gps_count = 0; - sv_cache_info.glo_count = 0; - sv_cache_info.gal_count = 0; - sv_cache_info.qzss_count = 0; - sv_cache_info.bds_count = 0; for(svNumber=1; svNumber <= svCount; svNumber++) { if (GNSS_SV_TYPE_GPS == svNotify.gnssSvs[svNumber - 1].type) { @@ -1078,35 +1077,38 @@ void loc_nmea_generate_sv(const GnssSvNotification &svNotify, // ------------------ loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GPS, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, false), nmeaArraystr); // ------------------ // ------$GLGSV------ // ------------------ loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GLONASS, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GLONASS, false), + nmeaArraystr); // ------------------ // ------$GAGSV------ // ------------------ loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_GALILEO, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, false), + nmeaArraystr); // ------------------------- // ------$PQGSV (QZSS)------ // ------------------------- loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_QZSS, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, false), nmeaArraystr); // --------------------------- // ------$PQGSV (BEIDOU)------ // --------------------------- loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), - loc_nmea_sv_meta_init(sv_meta, GNSS_SV_TYPE_BEIDOU, false), nmeaArraystr); + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, false), + nmeaArraystr); EXIT_LOG(%d, 0); } From 2ef3437f1994ff0105206e59f3993a79d18e0fd2 Mon Sep 17 00:00:00 2001 From: Saurabh Srivastava Date: Tue, 26 Jun 2018 14:38:32 +0530 Subject: [PATCH 21/22] Checking return for ODCPI CB Adding return value check for ODCPI HIDL callback API. CRs-Fixed: 2263480 Change-Id: I652a4717ab08f8a0c64b3bc0f78bae4e8f553513 --- android/Gnss.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/android/Gnss.cpp b/android/Gnss.cpp index 8f048e24..de1430cd 100644 --- a/android/Gnss.cpp +++ b/android/Gnss.cpp @@ -423,10 +423,9 @@ void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) { // For emergency mode, request DBH (Device based hybrid) location // Mark Independent from GNSS flag to false. if (ODCPI_REQUEST_TYPE_START == request.type) { - if (request.isEmergencyMode) { - mGnssCbIface_1_1->gnssRequestLocationCb(false); - } else { - mGnssCbIface_1_1->gnssRequestLocationCb(true); + auto r = mGnssCbIface_1_1->gnssRequestLocationCb(!request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb %s", r.description().c_str()); } } else { LOC_LOGv("Unsupported ODCPI request type: %d", request.type); From 864d80533243578917ecc9e56bf00037a2ca92db Mon Sep 17 00:00:00 2001 From: Mike Cailean Date: Mon, 25 Jun 2018 14:36:06 -0700 Subject: [PATCH 22/22] Get AGC from PQWM1 regardless of time validity Eliminated time valid dependency when processing PQWM1 message to get AGC Bug: 110460486 Change-Id: I962272a749599db7a9dc84e00da9e1152686c366 CRs-fixed: 2267159 --- gnss/GnssAdapter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 30bc4212..f8ba0eb4 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -2470,7 +2470,7 @@ void GnssAdapter::reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements, int msInWeek) { - LOC_LOGD("%s]: ", __func__); + LOC_LOGD("%s]: msInWeek=%d", __func__, msInWeek); struct MsgReportGnssMeasurementData : public LocMsg { GnssAdapter& mAdapter; @@ -3176,7 +3176,6 @@ GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int m systemstatus->getReport(reports, true); if ((!reports.mRfAndParams.empty()) && (!reports.mTimeAndClock.empty()) && - reports.mTimeAndClock.back().mTimeValid && (abs(msInWeek - (int)reports.mTimeAndClock.back().mGpsTowMs) < 2000)) { for (size_t i = 0; i < measurements.count; i++) {