summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorYingjie Wang <yingjiewang@codeaurora.org>2019-10-14 18:21:15 +0800
committerGerrit - the friendly Code Review server <code-review@localhost>2019-10-29 22:03:30 -0700
commitae1d9031eff622838da1596737d871c16dcc9e2e (patch)
tree4fa5113ea3f61b537cb5eabbf082b5c694199300 /android
parent5c568ca1bdd64c4de4a29695457db6bd81d0f5d8 (diff)
downloadgps-ae1d9031eff622838da1596737d871c16dcc9e2e.tar.gz
Add listener for the initial battery status
Listen to the initial charging status as DPO mode depends on it; Change ALOG to LOC_LOG. Change-Id: Ic61f76038f0e464b18ade8c9b20c058de35748c8 CRs-fixed: 2544828
Diffstat (limited to 'android')
-rw-r--r--android/1.0/Gnss.cpp2
-rw-r--r--android/1.1/Gnss.cpp2
-rw-r--r--android/2.0/Gnss.cpp2
-rw-r--r--android/utils/Android.mk3
-rw-r--r--android/utils/battery_listener.cpp70
5 files changed, 45 insertions, 34 deletions
diff --git a/android/1.0/Gnss.cpp b/android/1.0/Gnss.cpp
index d85e0a4..4aac432 100644
--- a/android/1.0/Gnss.cpp
+++ b/android/1.0/Gnss.cpp
@@ -56,6 +56,8 @@ void location_on_battery_status_changed(bool charging) {
Gnss::Gnss() {
ENTRY_LOG_CALLFLOW();
sGnss = this;
+ // initilize gnss interface at first in case needing notify battery status
+ sGnss->getGnssInterface()->initialize();
// register health client to listen on battery change
loc_extn_battery_properties_listener_init(location_on_battery_status_changed);
// clear pending GnssConfig
diff --git a/android/1.1/Gnss.cpp b/android/1.1/Gnss.cpp
index bea556f..277dbc1 100644
--- a/android/1.1/Gnss.cpp
+++ b/android/1.1/Gnss.cpp
@@ -97,6 +97,8 @@ void location_on_battery_status_changed(bool charging) {
Gnss::Gnss() {
ENTRY_LOG_CALLFLOW();
sGnss = this;
+ // initilize gnss interface at first in case needing notify battery status
+ sGnss->getGnssInterface()->initialize();
// register health client to listen on battery change
loc_extn_battery_properties_listener_init(location_on_battery_status_changed);
// clear pending GnssConfig
diff --git a/android/2.0/Gnss.cpp b/android/2.0/Gnss.cpp
index af76b72..2276c14 100644
--- a/android/2.0/Gnss.cpp
+++ b/android/2.0/Gnss.cpp
@@ -96,6 +96,8 @@ void location_on_battery_status_changed(bool charging) {
Gnss::Gnss() {
ENTRY_LOG_CALLFLOW();
sGnss = this;
+ // initilize gnss interface at first in case needing notify battery status
+ sGnss->getGnssInterface()->initialize();
// register health client to listen on battery change
loc_extn_battery_properties_listener_init(location_on_battery_status_changed);
// clear pending GnssConfig
diff --git a/android/utils/Android.mk b/android/utils/Android.mk
index 76732c2..0e4c953 100644
--- a/android/utils/Android.mk
+++ b/android/utils/Android.mk
@@ -26,6 +26,9 @@ LOCAL_SHARED_LIBRARIES := \
android.hardware.power@1.2 \
libbase
+LOCAL_HEADER_LIBRARIES := \
+ libgps.utils_headers \
+
LOCAL_STATIC_LIBRARIES := libhealthhalutils
LOCAL_CFLAGS += -DBATTERY_LISTENER_ENABLED
diff --git a/android/utils/battery_listener.cpp b/android/utils/battery_listener.cpp
index a790702..8547e41 100644
--- a/android/utils/battery_listener.cpp
+++ b/android/utils/battery_listener.cpp
@@ -31,12 +31,15 @@
#undef LOG_TAG
#endif
#define LOG_TAG "LocSvc_BatteryListener"
+#define LOG_NDEBUG 0
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <android/hardware/health/2.0/IHealth.h>
#include <healthhalutils/HealthHalUtils.h>
#include <hidl/HidlTransportSupport.h>
#include <thread>
+#include <log_util.h>
+
using android::hardware::interfacesEqual;
using android::hardware::Return;
using android::hardware::Void;
@@ -99,24 +102,25 @@ status_t BatteryListenerImpl::init()
} while(tries < GET_HEALTH_SVC_RETRY_CNT);
if (mHealth == NULL) {
- ALOGE("no health service found, retries %d", tries);
+ LOC_LOGe("no health service found, retries %d", tries);
return NO_INIT;
} else {
- ALOGI("Get health service in %d tries", tries);
+ LOC_LOGi("Get health service in %d tries", tries);
}
mStatus = BatteryStatus::UNKNOWN;
auto ret = mHealth->getChargeStatus([&](Result r, BatteryStatus status) {
if (r != Result::SUCCESS) {
- ALOGE("batterylistener: cannot get battery status");
+ LOC_LOGe("batterylistener: cannot get battery status");
return;
}
mStatus = status;
});
- if (!ret.isOk())
- ALOGE("batterylistener: get charge status transaction error");
-
- if (mStatus == BatteryStatus::UNKNOWN)
- ALOGW("batterylistener: init: invalid battery status");
+ if (!ret.isOk()) {
+ LOC_LOGe("batterylistener: get charge status transaction error");
+ }
+ if (mStatus == BatteryStatus::UNKNOWN) {
+ LOC_LOGw("batterylistener: init: invalid battery status");
+ }
mDone = false;
mThread = std::make_unique<std::thread>([this]() {
std::unique_lock<std::mutex> l(mLock);
@@ -146,7 +150,7 @@ status_t BatteryListenerImpl::init()
}
default:
bool c = statusToBool(local_status);
- ALOGI("healthInfo cb thread: cb %s", c ? "CHARGING" : "NOT CHARGING");
+ LOC_LOGi("healthInfo cb thread: cb %s", c ? "CHARGING" : "NOT CHARGING");
l.unlock();
mCb(c);
l.lock();
@@ -156,13 +160,14 @@ status_t BatteryListenerImpl::init()
});
auto reg = mHealth->registerCallback(this);
if (!reg.isOk()) {
- ALOGE("Transaction error in registeringCb to HealthHAL death: %s",
+ LOC_LOGe("Transaction error in registeringCb to HealthHAL death: %s",
reg.description().c_str());
}
auto linked = mHealth->linkToDeath(this, 0 /* cookie */);
if (!linked.isOk() || linked == false) {
- ALOGE("Transaction error in linking to HealthHAL death: %s", linked.description().c_str());
+ LOC_LOGe("Transaction error in linking to HealthHAL death: %s",
+ linked.description().c_str());
}
return NO_ERROR;
}
@@ -181,7 +186,7 @@ BatteryListenerImpl::~BatteryListenerImpl()
mHealth->unlinkToDeath(this);
auto r = mHealth->unlinkToDeath(this);
if (!r.isOk() || r == false) {
- ALOGE("Transaction error in unregister to HealthHAL death: %s",
+ LOC_LOGe("Transaction error in unregister to HealthHAL death: %s",
r.description().c_str());
}
}
@@ -195,10 +200,10 @@ void BatteryListenerImpl::serviceDied(uint64_t cookie __unused,
{
std::lock_guard<std::mutex> _l(mLock);
if (mHealth == NULL || !interfacesEqual(mHealth, who.promote())) {
- ALOGE("health not initialized or unknown interface died");
+ LOC_LOGe("health not initialized or unknown interface died");
return;
}
- ALOGI("health service died, reinit");
+ LOC_LOGi("health service died, reinit");
mDone = true;
}
mThread->join();
@@ -212,9 +217,8 @@ void BatteryListenerImpl::serviceDied(uint64_t cookie __unused,
// NOT_CHARGING and CHARGING concurrencies.
// Replace single var by a list if this assumption is broken
Return<void> BatteryListenerImpl::healthInfoChanged(
- const hardware::health::V2_0::HealthInfo& info)
-{
- ALOGV("healthInfoChanged: %d", info.legacy.batteryStatus);
+ const hardware::health::V2_0::HealthInfo& info) {
+ LOC_LOGv("healthInfoChanged: %d", info.legacy.batteryStatus);
std::unique_lock<std::mutex> l(mLock);
if (info.legacy.batteryStatus != mStatus) {
mStatus = info.legacy.batteryStatus;
@@ -224,29 +228,29 @@ Return<void> BatteryListenerImpl::healthInfoChanged(
}
static sp<BatteryListenerImpl> batteryListener;
-status_t batteryPropertiesListenerInit(BatteryListenerImpl::cb_fn_t cb)
-{
- ALOGV("batteryPropertiesListenerInit entry");
+
+bool batteryPropertiesListenerIsCharging() {
+ return batteryListener->isCharging();
+}
+
+status_t batteryPropertiesListenerInit(BatteryListenerImpl::cb_fn_t cb) {
batteryListener = new BatteryListenerImpl(cb);
+ bool isCharging = batteryPropertiesListenerIsCharging();
+ LOC_LOGv("charging status: %s charging", isCharging ? "" : "not");;
+ if (isCharging) {
+ cb(isCharging);
+ }
return NO_ERROR;
}
-status_t batteryPropertiesListenerDeinit()
-{
+status_t batteryPropertiesListenerDeinit() {
batteryListener.clear();
return OK;
}
-bool batteryPropertiesListenerIsCharging()
-{
- return batteryListener->isCharging();
-}
-
} // namespace android
-void loc_extn_battery_properties_listener_init(battery_status_change_fn_t fn)
-{
- ALOGV("loc_extn_battery_properties_listener_init entry");
+void loc_extn_battery_properties_listener_init(battery_status_change_fn_t fn) {
if (!sIsBatteryListened) {
std::thread t1(android::batteryPropertiesListenerInit,
[=](bool charging) { fn(charging); });
@@ -255,12 +259,10 @@ void loc_extn_battery_properties_listener_init(battery_status_change_fn_t fn)
}
}
-void loc_extn_battery_properties_listener_deinit()
-{
+void loc_extn_battery_properties_listener_deinit() {
android::batteryPropertiesListenerDeinit();
}
-bool loc_extn_battery_properties_is_charging()
-{
+bool loc_extn_battery_properties_is_charging() {
return android::batteryPropertiesListenerIsCharging();
}