Skip to content
Permalink
Browse files

Merge "healthd: Add dock battery support" into cm-11.0

  • Loading branch information
maniac103 authored and Gerrit Code Review committed Dec 15, 2013
2 parents d851160 + 4bc9f63 commit ed81dd4fe2215fff401ae72c567e434218ff426c
Showing with 229 additions and 4 deletions.
  1. +184 −3 healthd/BatteryMonitor.cpp
  2. +4 −1 healthd/BatteryMonitor.h
  3. +13 −0 healthd/healthd.cpp
  4. +28 −0 healthd/healthd.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -131,6 +132,8 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String
{ "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS },
{ "DockAC", ANDROID_POWER_SUPPLY_TYPE_DOCK_AC },
{ "DockBattery", ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY },
{ NULL, 0 },
};

@@ -173,14 +176,23 @@ bool BatteryMonitor::update(void) {
struct BatteryProperties props;
bool logthis;

props.dockBatterySupported = mHealthdConfig->dockBatterySupported;

props.chargerAcOnline = false;
props.chargerDockAcOnline = false;
props.chargerUsbOnline = false;
props.chargerWirelessOnline = false;

props.batteryStatus = BATTERY_STATUS_UNKNOWN;
props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
props.batteryCurrentNow = INT_MIN;
props.batteryChargeCounter = INT_MIN;

props.dockBatteryStatus = BATTERY_STATUS_UNKNOWN;
props.dockBatteryHealth = BATTERY_HEALTH_UNKNOWN;
props.dockBatteryCurrentNow = INT_MIN;
props.dockBatteryChargeCounter = INT_MIN;

if (!mHealthdConfig->batteryPresentPath.isEmpty())
props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath);
else
@@ -210,6 +222,42 @@ bool BatteryMonitor::update(void) {
if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0)
props.batteryTechnology = String8(buf);

// Dock battery (only if supported by the device)
if (mHealthdConfig->dockBatterySupported) {
if (!mHealthdConfig->dockBatteryPresentPath.isEmpty())
props.dockBatteryPresent = getBooleanField(mHealthdConfig->dockBatteryPresentPath);
else
props.dockBatteryPresent = false;

props.dockBatteryLevel = getIntField(mHealthdConfig->dockBatteryCapacityPath);
props.dockBatteryVoltage = getIntField(mHealthdConfig->dockBatteryVoltagePath) / 1000;

if (!mHealthdConfig->dockBatteryCurrentNowPath.isEmpty())
props.dockBatteryCurrentNow = getIntField(mHealthdConfig->dockBatteryCurrentNowPath);

if (!mHealthdConfig->dockBatteryChargeCounterPath.isEmpty()) {
props.dockBatteryChargeCounter = getIntField(
mHealthdConfig->dockBatteryChargeCounterPath);
}

props.dockBatteryTemperature = getIntField(mHealthdConfig->dockBatteryTemperaturePath);

if (readFromFile(mHealthdConfig->dockBatteryStatusPath, buf, SIZE) > 0)
props.dockBatteryStatus = getBatteryStatus(buf);

if (readFromFile(mHealthdConfig->dockBatteryHealthPath, buf, SIZE) > 0)
props.dockBatteryHealth = getBatteryHealth(buf);

if (readFromFile(mHealthdConfig->dockBatteryTechnologyPath, buf, SIZE) > 0)
props.dockBatteryTechnology = String8(buf);
} else {
props.dockBatteryPresent = false;
props.dockBatteryLevel = 0;
props.dockBatteryVoltage = 0;
props.dockBatteryTemperature = 0;
props.dockBatteryTechnology = String8(String8::kEmptyString);
}

unsigned int i;

for (i = 0; i < mChargerNames.size(); i++) {
@@ -232,6 +280,9 @@ bool BatteryMonitor::update(void) {
case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
props.chargerWirelessOnline = true;
break;
case ANDROID_POWER_SUPPLY_TYPE_DOCK_AC:
props.chargerDockAcOnline = mHealthdConfig->dockBatterySupported;
break;
default:
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
mChargerNames[i].string());
@@ -251,25 +302,45 @@ bool BatteryMonitor::update(void) {
abs(props.batteryTemperature / 10),
abs(props.batteryTemperature % 10), props.batteryHealth,
props.batteryStatus);
char dockdmesgline[256];
if (mHealthdConfig->dockBatterySupported) {
snprintf(dockdmesgline, sizeof(dockdmesgline),
" dockBattery l=%d v=%d t=%s%d.%d h=%d st=%d",
props.dockBatteryLevel, props.dockBatteryVoltage,
props.dockBatteryTemperature < 0 ? "-" : "",
abs(props.dockBatteryTemperature / 10),
abs(props.dockBatteryTemperature % 10), props.dockBatteryHealth,
props.dockBatteryStatus);
} else {
snprintf(dockdmesgline, sizeof(dockdmesgline), "");
}

if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
char b[20];

snprintf(b, sizeof(b), " c=%d", props.batteryCurrentNow / 1000);
strlcat(dmesgline, b, sizeof(dmesgline));
}
if (mHealthdConfig->dockBatterySupported &&
!mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) {
char b[20];

snprintf(b, sizeof(b), " c=%d", props.dockBatteryCurrentNow / 1000);
strlcat(dockdmesgline, b, sizeof(dockdmesgline));
}

KLOG_INFO(LOG_TAG, "%s chg=%s%s%s\n", dmesgline,
KLOG_INFO(LOG_TAG, "%s%s chg=%s%s%s%s\n", dmesgline, dockdmesgline,
props.chargerAcOnline ? "a" : "",
props.chargerDockAcOnline ? "d" : "",
props.chargerUsbOnline ? "u" : "",
props.chargerWirelessOnline ? "w" : "");
}

if (mBatteryPropertiesRegistrar != NULL)
mBatteryPropertiesRegistrar->notifyListeners(props);

return props.chargerAcOnline | props.chargerUsbOnline |
props.chargerWirelessOnline;
return props.chargerAcOnline | props.chargerDockAcOnline |
props.chargerUsbOnline | props.chargerWirelessOnline;
}

void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {
@@ -294,6 +365,7 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {
path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name);
switch(readPowerSupplyType(path)) {
case ANDROID_POWER_SUPPLY_TYPE_AC:
case ANDROID_POWER_SUPPLY_TYPE_DOCK_AC:
case ANDROID_POWER_SUPPLY_TYPE_USB:
case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
path.clear();
@@ -391,6 +463,97 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {

break;

case ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY:
if (mHealthdConfig->dockBatterySupported) {
if (mHealthdConfig->dockBatteryStatusPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryStatusPath = path;
}

if (mHealthdConfig->dockBatteryHealthPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryHealthPath = path;
}

if (mHealthdConfig->dockBatteryPresentPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryPresentPath = path;
}

if (mHealthdConfig->dockBatteryCapacityPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryCapacityPath = path;
}

if (mHealthdConfig->dockBatteryVoltagePath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/voltage_now",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0) {
mHealthdConfig->dockBatteryVoltagePath = path;
} else {
path.clear();
path.appendFormat("%s/%s/batt_vol",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryVoltagePath = path;
}
}

if (mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/current_now",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryCurrentNowPath = path;
}

if (mHealthdConfig->dockBatteryChargeCounterPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/charge_counter",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryChargeCounterPath = path;
}

if (mHealthdConfig->dockBatteryTemperaturePath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path, R_OK) == 0) {
mHealthdConfig->dockBatteryTemperaturePath = path;
} else {
path.clear();
path.appendFormat("%s/%s/batt_temp",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryTemperaturePath = path;
}
}

if (mHealthdConfig->dockBatteryTechnologyPath.isEmpty()) {
path.clear();
path.appendFormat("%s/%s/technology",
POWER_SUPPLY_SYSFS_PATH, name);
if (access(path, R_OK) == 0)
mHealthdConfig->dockBatteryTechnologyPath = path;
}
}

break;

case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN:
break;
}
@@ -400,6 +563,7 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {

if (!mChargerNames.size())
KLOG_ERROR(LOG_TAG, "No charger supplies found\n");

if (mHealthdConfig->batteryStatusPath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n");
if (mHealthdConfig->batteryHealthPath.isEmpty())
@@ -415,6 +579,23 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {
if (mHealthdConfig->batteryTechnologyPath.isEmpty())
KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n");

if (mHealthdConfig->dockBatterySupported) {
if (mHealthdConfig->dockBatteryStatusPath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryStatusPath not found\n");
if (mHealthdConfig->dockBatteryHealthPath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryHealthPath not found\n");
if (mHealthdConfig->dockBatteryPresentPath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryPresentPath not found\n");
if (mHealthdConfig->dockBatteryCapacityPath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryCapacityPath not found\n");
if (mHealthdConfig->dockBatteryVoltagePath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryVoltagePath not found\n");
if (mHealthdConfig->dockBatteryTemperaturePath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryTemperaturePath not found\n");
if (mHealthdConfig->dockBatteryTechnologyPath.isEmpty())
KLOG_WARNING(LOG_TAG, "DockBatteryTechnologyPath not found\n");
}

if (nosvcmgr == false) {
mBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(this);
mBatteryPropertiesRegistrar->publish();
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +37,9 @@ class BatteryMonitor {
ANDROID_POWER_SUPPLY_TYPE_AC,
ANDROID_POWER_SUPPLY_TYPE_USB,
ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
ANDROID_POWER_SUPPLY_TYPE_BATTERY
ANDROID_POWER_SUPPLY_TYPE_BATTERY,
ANDROID_POWER_SUPPLY_TYPE_DOCK_AC,
ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY
};

void init(struct healthd_config *hc, bool nosvcmgr);
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +42,7 @@ using namespace android;
static struct healthd_config healthd_config = {
.periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST,
.periodic_chores_interval_slow = DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW,

.batteryStatusPath = String8(String8::kEmptyString),
.batteryHealthPath = String8(String8::kEmptyString),
.batteryPresentPath = String8(String8::kEmptyString),
@@ -50,6 +52,17 @@ static struct healthd_config healthd_config = {
.batteryTechnologyPath = String8(String8::kEmptyString),
.batteryCurrentNowPath = String8(String8::kEmptyString),
.batteryChargeCounterPath = String8(String8::kEmptyString),

.dockBatterySupported = false,
.dockBatteryStatusPath = String8(String8::kEmptyString),
.dockBatteryHealthPath = String8(String8::kEmptyString),
.dockBatteryPresentPath = String8(String8::kEmptyString),
.dockBatteryCapacityPath = String8(String8::kEmptyString),
.dockBatteryVoltagePath = String8(String8::kEmptyString),
.dockBatteryTemperaturePath = String8(String8::kEmptyString),
.dockBatteryTechnologyPath = String8(String8::kEmptyString),
.dockBatteryCurrentNowPath = String8(String8::kEmptyString),
.dockBatteryChargeCounterPath = String8(String8::kEmptyString),
};

#define POWER_SUPPLY_SUBSYSTEM "power_supply"
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +49,22 @@
// batteryCurrentNowPath: battery current (POWER_SUPPLY_PROP_CURRENT_NOW)
// batteryChargeCounterPath: battery accumulated charge
// (POWER_SUPPLY_PROP_CHARGE_COUNTER)
//
// dockBatteryStatusPath: dock charging status (POWER_SUPPLY_PROP_STATUS)
// dockBatteryHealthPath: dock battery health (POWER_SUPPLY_PROP_HEALTH)
// dockBatteryPresentPath: dock battery present (POWER_SUPPLY_PROP_PRESENT)
// dockBatteryCapacityPath: dock remaining capacity (POWER_SUPPLY_PROP_CAPACITY)
// dockBatteryVoltagePath: dock battery voltage (POWER_SUPPLY_PROP_VOLTAGE_NOW)
// dockBatteryTemperaturePath: dock battery temperature (POWER_SUPPLY_PROP_TEMP)
// dockBatteryTechnologyPath: dock battery technology (POWER_SUPPLY_PROP_TECHNOLOGY)
// dockBatteryCurrentNowPath: dock battery current (POWER_SUPPLY_PROP_CURRENT_NOW)
// dockBatteryChargeCounterPath: dock battery accumulated charge
// (POWER_SUPPLY_PROP_CHARGE_COUNTER)
//
// The property dockBatterySupported determines if the healthd subsystem will search
// and refresh all the power_supply sysfs attribute file paths for dock battery.
// Its value is false by default.
//

struct healthd_config {
int periodic_chores_interval_fast;
@@ -62,6 +79,17 @@ struct healthd_config {
android::String8 batteryTechnologyPath;
android::String8 batteryCurrentNowPath;
android::String8 batteryChargeCounterPath;

bool dockBatterySupported;
android::String8 dockBatteryStatusPath;
android::String8 dockBatteryHealthPath;
android::String8 dockBatteryPresentPath;
android::String8 dockBatteryCapacityPath;
android::String8 dockBatteryVoltagePath;
android::String8 dockBatteryTemperaturePath;
android::String8 dockBatteryTechnologyPath;
android::String8 dockBatteryCurrentNowPath;
android::String8 dockBatteryChargeCounterPath;
};

// The following are implemented in libhealthd_board to handle board-specific

0 comments on commit ed81dd4

Please sign in to comment.
You can’t perform that action at this time.