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

Commit c133b719 authored by Todd Poynor's avatar Todd Poynor
Browse files

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
parent 0ea259ae
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <unistd.h>
#include <batteryservice/BatteryService.h>
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
#include <cutils/klog.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/Vector.h>


@@ -272,6 +273,40 @@ bool BatteryMonitor::update(void) {
            props.chargerWirelessOnline;
            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) {
void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) {
    String8 path;
    String8 path;


+2 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef HEALTHD_BATTERYMONITOR_H
#ifndef HEALTHD_BATTERYMONITOR_H
#define HEALTHD_BATTERYMONITOR_H
#define HEALTHD_BATTERYMONITOR_H


#include <batteryservice/BatteryService.h>
#include <binder/IInterface.h>
#include <binder/IInterface.h>
#include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/Vector.h>
@@ -41,6 +42,7 @@ class BatteryMonitor {


    void init(struct healthd_config *hc, bool nosvcmgr);
    void init(struct healthd_config *hc, bool nosvcmgr);
    bool update(void);
    bool update(void);
    status_t getProperty(int id, struct BatteryProperty *val);


  private:
  private:
    struct healthd_config *mHealthdConfig;
    struct healthd_config *mHealthdConfig;
+4 −0
Original line number Original line Diff line number Diff line
@@ -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) {
void BatteryPropertiesRegistrar::binderDied(const wp<IBinder>& who) {
    Mutex::Autolock _l(mRegistrationLock);
    Mutex::Autolock _l(mRegistrationLock);


+1 −0
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ private:


    void registerListener(const sp<IBatteryPropertiesListener>& listener);
    void registerListener(const sp<IBatteryPropertiesListener>& listener);
    void unregisterListener(const sp<IBatteryPropertiesListener>& listener);
    void unregisterListener(const sp<IBatteryPropertiesListener>& listener);
    status_t getProperty(int id, struct BatteryProperty *val);
    void binderDied(const wp<IBinder>& who);
    void binderDied(const wp<IBinder>& who);
};
};