diff --git a/android/1.0/Gnss.cpp b/android/1.0/Gnss.cpp index 873cf373..d85e0a40 100644 --- a/android/1.0/Gnss.cpp +++ b/android/1.0/Gnss.cpp @@ -37,6 +37,7 @@ namespace gnss { namespace V1_0 { namespace implementation { +static sp sGnss; void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { LOC_LOGE("%s] service died. cookie: %llu, who: %p", __FUNCTION__, static_cast(cookie), &who); @@ -47,10 +48,14 @@ void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who } void location_on_battery_status_changed(bool charging) { - LOC_LOGd("%s: battery status changed to %s charging", __func__, charging ? "" : "not "); + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not "); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } } Gnss::Gnss() { ENTRY_LOG_CALLFLOW(); + sGnss = this; // register health client to listen on battery change loc_extn_battery_properties_listener_init(location_on_battery_status_changed); // clear pending GnssConfig @@ -65,6 +70,7 @@ Gnss::~Gnss() { delete mApi; mApi = nullptr; } + sGnss = nullptr; } GnssAPIClient* Gnss::getApi() { diff --git a/android/1.1/Gnss.cpp b/android/1.1/Gnss.cpp index f0d74da0..bea556fe 100644 --- a/android/1.1/Gnss.cpp +++ b/android/1.1/Gnss.cpp @@ -41,6 +41,7 @@ namespace gnss { namespace V1_1 { namespace implementation { +static sp sGnss; static std::string getVersionString() { static std::string version; if (!version.empty()) @@ -88,10 +89,14 @@ void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who } void location_on_battery_status_changed(bool charging) { - LOC_LOGd("%s: battery status changed to %s charging", __func__, charging ? "" : "not "); + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not"); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } } Gnss::Gnss() { ENTRY_LOG_CALLFLOW(); + sGnss = this; // register health client to listen on battery change loc_extn_battery_properties_listener_init(location_on_battery_status_changed); // clear pending GnssConfig @@ -106,6 +111,7 @@ Gnss::~Gnss() { delete mApi; mApi = nullptr; } + sGnss = nullptr; } GnssAPIClient* Gnss::getApi() { diff --git a/android/2.0/Gnss.cpp b/android/2.0/Gnss.cpp index be4efac3..4fa5b63a 100644 --- a/android/2.0/Gnss.cpp +++ b/android/2.0/Gnss.cpp @@ -41,7 +41,7 @@ namespace V2_0 { namespace implementation { using ::android::hardware::gnss::visibility_control::V1_0::implementation::GnssVisibilityControl; - +static sp sGnss; static std::string getVersionString() { static std::string version; if (!version.empty()) @@ -88,10 +88,14 @@ void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who } void location_on_battery_status_changed(bool charging) { - LOC_LOGd("%s: battery status changed to %s charging", __func__, charging ? "" : "not "); + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not"); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } } Gnss::Gnss() { ENTRY_LOG_CALLFLOW(); + sGnss = this; // register health client to listen on battery change loc_extn_battery_properties_listener_init(location_on_battery_status_changed); // clear pending GnssConfig @@ -105,6 +109,7 @@ Gnss::~Gnss() { delete mApi; mApi = nullptr; } + sGnss = nullptr; } GnssAPIClient* Gnss::getApi() { diff --git a/core/SystemStatus.cpp b/core/SystemStatus.cpp index 18cb99c6..9ca126f8 100644 --- a/core/SystemStatus.cpp +++ b/core/SystemStatus.cpp @@ -1723,5 +1723,18 @@ bool SystemStatus::eventConnectionStatus(bool connected, int8_t type, return true; } +/****************************************************************************** +@brief API to update power connect state + +@param[In] power connect status + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::updatePowerConnectState(bool charging) +{ + SystemStatusPowerConnectState s(charging); + mSysStatusObsvr.notify({&s}); + return true; +} } // namespace loc_core diff --git a/core/SystemStatus.h b/core/SystemStatus.h index f3467e2f..94f7f0be 100644 --- a/core/SystemStatus.h +++ b/core/SystemStatus.h @@ -858,6 +858,7 @@ public: bool setDefaultGnssEngineStates(void); bool eventConnectionStatus(bool connected, int8_t type, bool roaming, NetworkHandle networkHandle); + bool updatePowerConnectState(bool charging); }; } // namespace loc_core diff --git a/gnss/location_gnss.cpp b/gnss/location_gnss.cpp index 88fa15d9..76839b62 100644 --- a/gnss/location_gnss.cpp +++ b/gnss/location_gnss.cpp @@ -78,6 +78,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 const GnssInterface gGnssInterface = { sizeof(GnssInterface), @@ -115,7 +116,8 @@ static const GnssInterface gGnssInterface = { enableNfwLocationAccess, nfwInit, getPowerStateChanges, - injectLocationExt + injectLocationExt, + updateBatteryStatus }; #ifndef DEBUG_X86 @@ -382,3 +384,9 @@ static void injectLocationExt(const GnssLocationInfoNotification &locationInfo) gGnssAdapter->injectLocationExtCommand(locationInfo); } } + +static void updateBatteryStatus(bool charging) { + if (NULL != gGnssAdapter) { + gGnssAdapter->getSystemStatus()->updatePowerConnectState(charging); + } +} diff --git a/location/location_interface.h b/location/location_interface.h index 80f37c24..fb15bea6 100644 --- a/location/location_interface.h +++ b/location/location_interface.h @@ -87,6 +87,7 @@ struct GnssInterface { void (*nfwInit)(const NfwCbInfo& cbInfo); void (*getPowerStateChanges)(void* powerStateCb); void (*injectLocationExt)(const GnssLocationInfoNotification &locationInfo); + void (*updateBatteryStatus)(bool charging); }; struct BatchingInterface {