healthd: break link between BatteryMonitor and BatteryPropertiesRegistrar
Make it easier to later separate out binder-related code.
Add helper functions healthd_battery_update(), healthd_get_property() to
allow these operations without needing references to the BatteryMonitor
object.
Change-Id: Ie584bf53e5178ce0a098d0d940d6c311fdff62d4
diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp
index 900cc42..62f4d11 100644
--- a/healthd/healthd.cpp
+++ b/healthd/healthd.cpp
@@ -31,6 +31,7 @@
#include <cutils/uevent.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
+#include <utils/Errors.h>
using namespace android;
@@ -90,7 +91,11 @@
KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n");
}
-static void battery_update(void) {
+status_t healthd_get_property(int id, struct BatteryProperty *val) {
+ return gBatteryMonitor->getProperty(id, val);
+}
+
+void healthd_battery_update(void) {
// Fast wake interval when on charger (watch for overheat);
// slow wake interval when on battery (watch for drained battery).
@@ -115,7 +120,7 @@
}
static void periodic_chores() {
- battery_update();
+ healthd_battery_update();
}
static void uevent_init(void) {
@@ -145,7 +150,7 @@
while (*cp) {
if (!strcmp(cp, "SUBSYSTEM=" POWER_SUPPLY_SUBSYSTEM)) {
- battery_update();
+ healthd_battery_update();
break;
}