am 62729a1d: am 565e4c6a: Merge "healthd: Adds cycle_count, current_now and full_charge properties."

* commit '62729a1d195cd27b353da24be21bd0a855884431':
  healthd: Adds cycle_count, current_now and full_charge properties.
This commit is contained in:
Ruchi Kandoi 2015-08-26 00:22:11 +00:00 committed by Android Git Automerger
commit 9e8eb9930b
3 changed files with 64 additions and 6 deletions

View file

@ -194,6 +194,15 @@ bool BatteryMonitor::update(void) {
getIntField(mHealthdConfig->batteryCapacityPath); getIntField(mHealthdConfig->batteryCapacityPath);
props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
if (!mHealthdConfig->batteryCurrentNowPath.isEmpty())
props.batteryCurrent = getIntField(mHealthdConfig->batteryCurrentNowPath) / 1000;
if (!mHealthdConfig->batteryFullChargePath.isEmpty())
props.batteryFullCharge = getIntField(mHealthdConfig->batteryFullChargePath);
if (!mHealthdConfig->batteryCycleCountPath.isEmpty())
props.batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath);
props.batteryTemperature = mBatteryFixedTemperature ? props.batteryTemperature = mBatteryFixedTemperature ?
mBatteryFixedTemperature : mBatteryFixedTemperature :
getIntField(mHealthdConfig->batteryTemperaturePath); getIntField(mHealthdConfig->batteryTemperaturePath);
@ -245,7 +254,7 @@ bool BatteryMonitor::update(void) {
if (logthis) { if (logthis) {
char dmesgline[256]; char dmesgline[256];
size_t len;
if (props.batteryPresent) { if (props.batteryPresent) {
snprintf(dmesgline, sizeof(dmesgline), snprintf(dmesgline, sizeof(dmesgline),
"battery l=%d v=%d t=%s%d.%d h=%d st=%d", "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
@ -255,19 +264,27 @@ bool BatteryMonitor::update(void) {
abs(props.batteryTemperature % 10), props.batteryHealth, abs(props.batteryTemperature % 10), props.batteryHealth,
props.batteryStatus); props.batteryStatus);
len = strlen(dmesgline);
if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
int c = getIntField(mHealthdConfig->batteryCurrentNowPath); len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
char b[20]; " c=%d", props.batteryCurrent);
}
snprintf(b, sizeof(b), " c=%d", c / 1000); if (!mHealthdConfig->batteryFullChargePath.isEmpty()) {
strlcat(dmesgline, b, sizeof(dmesgline)); len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
" fc=%d", props.batteryFullCharge);
}
if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) {
len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
" cc=%d", props.batteryCycleCount);
} }
} else { } else {
snprintf(dmesgline, sizeof(dmesgline), snprintf(dmesgline, sizeof(dmesgline),
"battery none"); "battery none");
} }
size_t len = strlen(dmesgline); len = strlen(dmesgline);
snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s",
props.chargerAcOnline ? "a" : "", props.chargerAcOnline ? "a" : "",
props.chargerUsbOnline ? "u" : "", props.chargerUsbOnline ? "u" : "",
@ -394,6 +411,21 @@ void BatteryMonitor::dumpState(int fd) {
snprintf(vs, sizeof(vs), "charge counter: %d\n", v); snprintf(vs, sizeof(vs), "charge counter: %d\n", v);
write(fd, vs, strlen(vs)); write(fd, vs, strlen(vs));
} }
if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
snprintf(vs, sizeof(vs), "current now: %d\n", props.batteryCurrent);
write(fd, vs, strlen(vs));
}
if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) {
snprintf(vs, sizeof(vs), "cycle count: %d\n", props.batteryCycleCount);
write(fd, vs, strlen(vs));
}
if (!mHealthdConfig->batteryFullChargePath.isEmpty()) {
snprintf(vs, sizeof(vs), "Full charge: %d\n", props.batteryFullCharge);
write(fd, vs, strlen(vs));
}
} }
void BatteryMonitor::init(struct healthd_config *hc) { void BatteryMonitor::init(struct healthd_config *hc) {
@ -476,6 +508,14 @@ void BatteryMonitor::init(struct healthd_config *hc) {
} }
} }
if (mHealthdConfig->batteryFullChargePath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/charge_full",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->batteryFullChargePath = path;
}
if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) { if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
path.clear(); path.clear();
path.appendFormat("%s/%s/current_now", path.appendFormat("%s/%s/current_now",
@ -484,6 +524,14 @@ void BatteryMonitor::init(struct healthd_config *hc) {
mHealthdConfig->batteryCurrentNowPath = path; mHealthdConfig->batteryCurrentNowPath = path;
} }
if (mHealthdConfig->batteryCycleCountPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/cycle_count",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->batteryCycleCountPath = path;
}
if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
path.clear(); path.clear();
path.appendFormat("%s/%s/current_avg", path.appendFormat("%s/%s/current_avg",
@ -553,6 +601,12 @@ void BatteryMonitor::init(struct healthd_config *hc) {
KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n");
if (mHealthdConfig->batteryTechnologyPath.isEmpty()) if (mHealthdConfig->batteryTechnologyPath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n");
if (mHealthdConfig->batteryCurrentNowPath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryCurrentNowPath not found\n");
if (mHealthdConfig->batteryFullChargePath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryFullChargePath not found\n");
if (mHealthdConfig->batteryCycleCountPath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryCycleCountPath not found\n");
} }
if (property_get("ro.boot.fake_battery", pval, NULL) > 0 if (property_get("ro.boot.fake_battery", pval, NULL) > 0

View file

@ -52,6 +52,8 @@ static struct healthd_config healthd_config = {
.batteryCurrentNowPath = String8(String8::kEmptyString), .batteryCurrentNowPath = String8(String8::kEmptyString),
.batteryCurrentAvgPath = String8(String8::kEmptyString), .batteryCurrentAvgPath = String8(String8::kEmptyString),
.batteryChargeCounterPath = String8(String8::kEmptyString), .batteryChargeCounterPath = String8(String8::kEmptyString),
.batteryFullChargePath = String8(String8::kEmptyString),
.batteryCycleCountPath = String8(String8::kEmptyString),
.energyCounter = NULL, .energyCounter = NULL,
.boot_min_cap = 0, .boot_min_cap = 0,
.screen_on = NULL, .screen_on = NULL,

View file

@ -65,6 +65,8 @@ struct healthd_config {
android::String8 batteryCurrentNowPath; android::String8 batteryCurrentNowPath;
android::String8 batteryCurrentAvgPath; android::String8 batteryCurrentAvgPath;
android::String8 batteryChargeCounterPath; android::String8 batteryChargeCounterPath;
android::String8 batteryFullChargePath;
android::String8 batteryCycleCountPath;
int (*energyCounter)(int64_t *); int (*energyCounter)(int64_t *);
int boot_min_cap; int boot_min_cap;