From 52d928e06956bad27f03c78d67cbaadd80cef74d Mon Sep 17 00:00:00 2001 From: Wei Chen Date: Fri, 13 Sep 2019 15:43:27 -0700 Subject: [PATCH] GPS HAL: send platform power state event to modem Send platform power state event, suspend/resume/shutdown to modem Change-Id: I19960f5fb4935de9e4f5513abd95aed6241a2fd9 CRs-fixed: 2527622 --- core/LocApiBase.cpp | 2 ++ core/LocApiBase.h | 1 + gnss/GnssAdapter.cpp | 35 +++++++++++++++++++++++++++++++++-- gnss/GnssAdapter.h | 6 ++++++ gnss/location_gnss.cpp | 10 +++++++++- location/location_interface.h | 1 + utils/gps_extended_c.h | 7 +++++++ 7 files changed, 59 insertions(+), 3 deletions(-) diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 8c79cf74..595fa49f 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -873,5 +873,7 @@ DEFAULT_IMPL() void LocApiBase::addToCallQueue(LocApiResponse* /*adapterResponse*/) DEFAULT_IMPL() +void LocApiBase::updateSystemPowerState(PowerStateType /*powerState*/) +DEFAULT_IMPL() } // namespace loc_core diff --git a/core/LocApiBase.h b/core/LocApiBase.h index 6dac585b..3c85b099 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -312,6 +312,7 @@ public: void updateEvtMask(); void updateNmeaMask(uint32_t mask); + virtual void updateSystemPowerState(PowerStateType systemPowerState); }; typedef LocApiBase* (getLocApi_t)(LOC_API_ADAPTER_EVENT_MASK_T exMask, diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 11f6777e..7d42106b 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -98,7 +98,8 @@ GnssAdapter::GnssAdapter() : mIsE911Session(NULL), mGnssMbSvIdUsedInPosition{}, mGnssMbSvIdUsedInPosAvail(false), - mSupportNfwControl(true) + mSupportNfwControl(true), + mSystemPowerState(POWER_STATE_UNKNOWN) { LOC_LOGD("%s]: Constructor %p", __func__, this); mLocPositionMode.mode = LOC_POSITION_MODE_INVALID; @@ -1997,6 +1998,35 @@ GnssAdapter::blockCPICommand(double latitude, double longitude, sendMsg(new MsgBlockCPI(mBlockCPIInfo, blockCPIInfo)); } +void +GnssAdapter::updateSystemPowerState(PowerStateType systemPowerState) { + if (POWER_STATE_UNKNOWN != systemPowerState) { + mSystemPowerState = systemPowerState; + mLocApi->updateSystemPowerState(mSystemPowerState); + } +} + +void +GnssAdapter::updateSystemPowerStateCommand(PowerStateType systemPowerState) { + LOC_LOGd("power event %d", systemPowerState); + + struct MsgUpdatePowerState : public LocMsg { + GnssAdapter& mAdapter; + PowerStateType mSystemPowerState; + + inline MsgUpdatePowerState(GnssAdapter& adapter, + PowerStateType systemPowerState) : + LocMsg(), + mAdapter(adapter), + mSystemPowerState(systemPowerState) {} + inline virtual void proc() const { + mAdapter.updateSystemPowerState(mSystemPowerState); + } + }; + + sendMsg(new MsgUpdatePowerState(*this, systemPowerState)); +} + void GnssAdapter::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks) { @@ -2133,9 +2163,10 @@ GnssAdapter::handleEngineUpEvent() mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); // must be called only after capabilities are known mAdapter.setConfig(); - mAdapter.restartSessions(); mAdapter.gnssSvIdConfigUpdate(); mAdapter.gnssSvTypeConfigUpdate(); + mAdapter.updateSystemPowerState(mAdapter.getSystemPowerState()); + mAdapter.restartSessions(); for (auto msg: mAdapter.mPendingMsgs) { mAdapter.sendMsg(msg); } diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 3ccdd96d..b3ffeaf8 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -187,6 +187,7 @@ class GnssAdapter : public LocAdapterBase { XtraSystemStatusObserver mXtraObserver; LocationSystemInfo mLocSystemInfo; std::vector mBlacklistedSvIds; + PowerStateType mSystemPowerState; /* === Misc ===================================================================== */ BlockCPIInfo mBlockCPIInfo; @@ -413,6 +414,8 @@ public: return false; } + void updateSystemPowerState(PowerStateType systemPowerState); + /*======== GNSSDEBUG ================================================================*/ bool getDebugReport(GnssDebugReport& report); /* get AGC information from system status and fill it */ @@ -459,11 +462,14 @@ public: void reportPowerStateIfChanged(); void savePowerStateCallback(powerStateCallback powerStateCb){ mPowerStateCb = powerStateCb; } bool getPowerState() { return mPowerOn; } + inline PowerStateType getSystemPowerState() { return mSystemPowerState; } + void setAllowFlpNetworkFixes(uint32_t allow) { mAllowFlpNetworkFixes = allow; } uint32_t getAllowFlpNetworkFixes() { return mAllowFlpNetworkFixes; } void setSuplHostServer(const char* server, int port, LocServerType type); void notifyClientOfCachedLocationSystemInfo(LocationAPI* client, const LocationCallbacks& callbacks); + void updateSystemPowerStateCommand(PowerStateType systemPowerState); }; #endif //GNSS_ADAPTER_H diff --git a/gnss/location_gnss.cpp b/gnss/location_gnss.cpp index 76839b62..5380f05a 100644 --- a/gnss/location_gnss.cpp +++ b/gnss/location_gnss.cpp @@ -79,6 +79,7 @@ static void odcpiInject(const Location& location); static void blockCPI(double latitude, double longitude, float accuracy, int blockDurationMsec, double latLonDiffThreshold); static void updateBatteryStatus(bool charging); +static void updateSystemPowerState(PowerStateType systemPowerState); static const GnssInterface gGnssInterface = { sizeof(GnssInterface), @@ -117,7 +118,8 @@ static const GnssInterface gGnssInterface = { nfwInit, getPowerStateChanges, injectLocationExt, - updateBatteryStatus + updateBatteryStatus, + updateSystemPowerState }; #ifndef DEBUG_X86 @@ -390,3 +392,9 @@ static void updateBatteryStatus(bool charging) { gGnssAdapter->getSystemStatus()->updatePowerConnectState(charging); } } + +static void updateSystemPowerState(PowerStateType systemPowerState) { + if (NULL != gGnssAdapter) { + gGnssAdapter->updateSystemPowerStateCommand(systemPowerState); + } +} diff --git a/location/location_interface.h b/location/location_interface.h index fb15bea6..d08dfb3c 100644 --- a/location/location_interface.h +++ b/location/location_interface.h @@ -88,6 +88,7 @@ struct GnssInterface { void (*getPowerStateChanges)(void* powerStateCb); void (*injectLocationExt)(const GnssLocationInfoNotification &locationInfo); void (*updateBatteryStatus)(bool charging); + void (*updateSystemPowerState)(PowerStateType systemPowerState); }; struct BatchingInterface { diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index 3ef49e3d..cd7c2358 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -2223,6 +2223,13 @@ typedef void (*LocAgpsOpenResultCb)(bool isSuccess, AGpsExtType agpsType, const typedef void (*LocAgpsCloseResultCb)(bool isSuccess, AGpsExtType agpsType, void* userDataPtr); +enum PowerStateType { + POWER_STATE_UNKNOWN = 0, + POWER_STATE_SUSPEND = 1, + POWER_STATE_RESUME = 2, + POWER_STATE_SHUTDOWN = 3 +}; + /* Shared resources of LocIpc */ #define LOC_IPC_HAL "/dev/socket/location/socket_hal" #define LOC_IPC_XTRA "/dev/socket/location/xtra/socket_xtra"