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

Commit 6dcc45ed authored by Todd Poynor's avatar Todd Poynor
Browse files

healthd: Fixups for systems without batteries or removable batteries

* Replace unnecessary warnings about missing attributes with a more
  informative message when no battery devices provided by the system.

* Turn off periodic battery checks when no battery devices (thereby
  reducing unnecessary kernel log spam).

* Replace battery properties in log messages with a more informative
  message when no battery is provided or the battery is removed.

Change-Id: I68a514aa7315ae2b5d22cb8861d3c9b1b38035a1
parent 83dfaa88
Loading
Loading
Loading
Loading
+29 −16
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ bool BatteryMonitor::update(void) {
    if (!mHealthdConfig->batteryPresentPath.isEmpty())
        props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath);
    else
        props.batteryPresent = true;
        props.batteryPresent = mBatteryDevicePresent;

    props.batteryLevel = getIntField(mHealthdConfig->batteryCapacityPath);
    props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
@@ -250,6 +250,8 @@ bool BatteryMonitor::update(void) {

    if (logthis) {
        char dmesgline[256];

        if (props.batteryPresent)
            snprintf(dmesgline, sizeof(dmesgline),
                 "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
                 props.batteryLevel, props.batteryVoltage,
@@ -257,6 +259,9 @@ bool BatteryMonitor::update(void) {
                 abs(props.batteryTemperature / 10),
                 abs(props.batteryTemperature % 10), props.batteryHealth,
                 props.batteryStatus);
        else
            snprintf(dmesgline, sizeof(dmesgline),
                 "battery none");

        if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
            char b[20];
@@ -351,6 +356,8 @@ void BatteryMonitor::init(struct healthd_config *hc) {
                break;

            case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
                mBatteryDevicePresent = true;

                if (mHealthdConfig->batteryStatusPath.isEmpty()) {
                    path.clear();
                    path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH,
@@ -456,6 +463,11 @@ void BatteryMonitor::init(struct healthd_config *hc) {

    if (!mChargerNames.size())
        KLOG_ERROR(LOG_TAG, "No charger supplies found\n");
    if (!mBatteryDevicePresent) {
        KLOG_INFO(LOG_TAG, "No battery devices found\n");
        hc->periodic_chores_interval_fast = -1;
        hc->periodic_chores_interval_slow = -1;
    } else {
        if (mHealthdConfig->batteryStatusPath.isEmpty())
            KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n");
        if (mHealthdConfig->batteryHealthPath.isEmpty())
@@ -471,5 +483,6 @@ void BatteryMonitor::init(struct healthd_config *hc) {
        if (mHealthdConfig->batteryTechnologyPath.isEmpty())
            KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n");
    }
}

}; // namespace android
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class BatteryMonitor {
  private:
    struct healthd_config *mHealthdConfig;
    Vector<String8> mChargerNames;
    bool mBatteryDevicePresent;

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