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
This commit is contained in:
Todd Poynor 2013-08-14 17:39:13 -07:00
parent 0ea259ae5f
commit c133b7198a
4 changed files with 42 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
};