Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3db03a5a authored by Todd Poynor's avatar Todd Poynor
Browse files

healthd: Set fixed battery level and temperature via properties

setprop persist.sys.battery.capacity 77
setprop persist.sys.battery.temperature 123

and reboot to cause a fixed battery level of 77% and temperature of 12.3C
to be reported to Android.

Typically used on power evaluation boards without batteries connected.

Bug: 14839868
Change-Id: Ibae5e16429d05891cb0787d74a2fe93b07013699
parent acc13d7b
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <unistd.h>
#include <batteryservice/BatteryService.h>
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
#include <cutils/klog.h>
#include <cutils/properties.h>
#include <sys/types.h>
#include <sys/types.h>
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/String8.h>
@@ -184,10 +185,14 @@ bool BatteryMonitor::update(void) {
    else
    else
        props.batteryPresent = mBatteryDevicePresent;
        props.batteryPresent = mBatteryDevicePresent;


    props.batteryLevel = getIntField(mHealthdConfig->batteryCapacityPath);
    props.batteryLevel = mBatteryFixedCapacity ?
        mBatteryFixedCapacity :
        getIntField(mHealthdConfig->batteryCapacityPath);
    props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
    props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;


    props.batteryTemperature = getIntField(mHealthdConfig->batteryTemperaturePath);
    props.batteryTemperature = mBatteryFixedTemperature ?
        mBatteryFixedTemperature :
        getIntField(mHealthdConfig->batteryTemperaturePath);


    const int SIZE = 128;
    const int SIZE = 128;
    char buf[SIZE];
    char buf[SIZE];
@@ -367,6 +372,7 @@ void BatteryMonitor::dumpState(int fd) {


void BatteryMonitor::init(struct healthd_config *hc) {
void BatteryMonitor::init(struct healthd_config *hc) {
    String8 path;
    String8 path;
    char pval[PROPERTY_VALUE_MAX];


    mHealthdConfig = hc;
    mHealthdConfig = hc;
    DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH);
    DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH);
@@ -523,6 +529,12 @@ void BatteryMonitor::init(struct healthd_config *hc) {
        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 (property_get("persist.sys.battery.capacity", pval, NULL) > 0)
        mBatteryFixedCapacity = (int) strtol(pval, NULL, 10);

    if (property_get("persist.sys.battery.temperature", pval, NULL) > 0)
        mBatteryFixedTemperature = (int) strtol(pval, NULL, 10);
}
}


}; // namespace android
}; // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,8 @@ class BatteryMonitor {
    struct healthd_config *mHealthdConfig;
    struct healthd_config *mHealthdConfig;
    Vector<String8> mChargerNames;
    Vector<String8> mChargerNames;
    bool mBatteryDevicePresent;
    bool mBatteryDevicePresent;
    int mBatteryFixedCapacity;
    int mBatteryFixedTemperature;
    struct BatteryProperties props;
    struct BatteryProperties props;


    int getBatteryStatus(const char* status);
    int getBatteryStatus(const char* status);