summaryrefslogtreecommitdiffstats
path: root/healthd
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2013-08-14 17:39:13 -0700
committerTodd Poynor <toddpoynor@google.com>2013-08-22 02:00:26 +0000
commitc133b7198a02c8738aeef86d6cfd921a626adce7 (patch)
tree5dd42653c9d0378da6173fcbdd0fc317ee8ca0f0 /healthd
parent0ea259ae5f640848d24179ae6e4ad53a14783d9f (diff)
downloadsystem_core-c133b7198a02c8738aeef86d6cfd921a626adce7.zip
system_core-c133b7198a02c8738aeef86d6cfd921a626adce7.tar.gz
system_core-c133b7198a02c8738aeef86d6cfd921a626adce7.tar.bz2
healthd: read individual battery property value on demand
Adding support for batteryChargeCounter and batteryCurrentNow as parameters likely to be useful for power consumption analysis. Change-Id: Ib23b05d3c31c22ece0d21e55cc481c1b5dabe59e
Diffstat (limited to 'healthd')
-rw-r--r--healthd/BatteryMonitor.cpp35
-rw-r--r--healthd/BatteryMonitor.h2
-rw-r--r--healthd/BatteryPropertiesRegistrar.cpp4
-rw-r--r--healthd/BatteryPropertiesRegistrar.h1
4 files changed, 42 insertions, 0 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index 688c7ff..a2da3ee 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
+#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@@ -272,6 +273,40 @@ bool BatteryMonitor::update(void) {
props.chargerWirelessOnline;
}
+status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) {
+ status_t ret = BAD_VALUE;
+
+ switch(id) {
+ case BATTERY_PROP_CHARGE_COUNTER:
+ if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
+ val->valueInt =
+ getIntField(mHealthdConfig->batteryChargeCounterPath);
+ ret = NO_ERROR;
+ } else {
+ ret = NAME_NOT_FOUND;
+ }
+ break;
+
+ case BATTERY_PROP_CURRENT_NOW:
+ if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
+ val->valueInt =
+ getIntField(mHealthdConfig->batteryCurrentNowPath);
+ ret = NO_ERROR;
+ } else {
+ ret = NAME_NOT_FOUND;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (ret != NO_ERROR)
+ val->valueInt = INT_MIN;
+
+ return ret;
+}
+
void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {
String8 path;
diff --git a/healthd/BatteryMonitor.h b/healthd/BatteryMonitor.h
index ba291af..34b423d 100644
--- a/healthd/BatteryMonitor.h
+++ b/healthd/BatteryMonitor.h
@@ -17,6 +17,7 @@
#ifndef HEALTHD_BATTERYMONITOR_H
#define HEALTHD_BATTERYMONITOR_H
+#include <batteryservice/BatteryService.h>
#include <binder/IInterface.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@@ -41,6 +42,7 @@ class BatteryMonitor {
void init(struct healthd_config *hc, bool nosvcmgr);
bool update(void);
+ status_t getProperty(int id, struct BatteryProperty *val);
private:
struct healthd_config *mHealthdConfig;
diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp
index 6a33ad8..3e06866 100644
--- a/healthd/BatteryPropertiesRegistrar.cpp
+++ b/healthd/BatteryPropertiesRegistrar.cpp
@@ -67,6 +67,10 @@ void BatteryPropertiesRegistrar::unregisterListener(const sp<IBatteryPropertiesL
}
}
+status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty *val) {
+ return mBatteryMonitor->getProperty(id, val);
+}
+
void BatteryPropertiesRegistrar::binderDied(const wp<IBinder>& who) {
Mutex::Autolock _l(mRegistrationLock);
diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h
index 793ddad..0ce6c04 100644
--- a/healthd/BatteryPropertiesRegistrar.h
+++ b/healthd/BatteryPropertiesRegistrar.h
@@ -44,6 +44,7 @@ private:
void registerListener(const sp<IBatteryPropertiesListener>& listener);
void unregisterListener(const sp<IBatteryPropertiesListener>& listener);
+ status_t getProperty(int id, struct BatteryProperty *val);
void binderDied(const wp<IBinder>& who);
};