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

Commit 9ed4eb61 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BatteryMonitor: report battery health from health status"

parents ee065fe0 b57f68ae
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ BatteryMonitor::BatteryMonitor()
      mBatteryDevicePresent(false),
      mBatteryFixedCapacity(0),
      mBatteryFixedTemperature(0),
      mBatteryHealthStatus(BatteryMonitor::BH_UNKNOWN),
      mHealthInfo(std::make_unique<HealthInfo>()) {
    initHealthInfo(mHealthInfo.get());
}
@@ -230,6 +231,23 @@ BatteryHealth getBatteryHealth(const char* status) {
    return *ret;
}

BatteryHealth getBatteryHealthStatus(int status) {
    BatteryHealth value;

    if (status == BatteryMonitor::BH_NOMINAL)
        value = BatteryHealth::GOOD;
    else if (status == BatteryMonitor::BH_MARGINAL)
        value = BatteryHealth::FAIR;
    else if (status == BatteryMonitor::BH_NEEDS_REPLACEMENT)
        value = BatteryHealth::DEAD;
    else if (status == BatteryMonitor::BH_FAILED)
        value = BatteryHealth::UNSPECIFIED_FAILURE;
    else
        value = BatteryHealth::UNKNOWN;

    return value;
}

BatteryChargingPolicy getBatteryChargingPolicy(const char* chargingPolicy) {
    static SysfsStringEnumMap<BatteryChargingPolicy> batteryChargingPolicyMap[] = {
            {"0", BatteryChargingPolicy::INVALID},   {"1", BatteryChargingPolicy::DEFAULT},
@@ -377,6 +395,9 @@ void BatteryMonitor::updateValues(void) {
    if (!mHealthdConfig->batteryStateOfHealthPath.isEmpty())
        mHealthInfo->batteryStateOfHealth = getIntField(mHealthdConfig->batteryStateOfHealthPath);

    if (!mHealthdConfig->batteryHealthStatusPath.isEmpty())
        mBatteryHealthStatus = getIntField(mHealthdConfig->batteryHealthStatusPath);

    if (!mHealthdConfig->batteryManufacturingDatePath.isEmpty())
        mHealthInfo->batteryHealthData->batteryManufacturingDateSeconds =
                getIntField(mHealthdConfig->batteryManufacturingDatePath);
@@ -397,8 +418,13 @@ void BatteryMonitor::updateValues(void) {
    if (readFromFile(mHealthdConfig->batteryStatusPath, &buf) > 0)
        mHealthInfo->batteryStatus = getBatteryStatus(buf.c_str());

    // Backward compatible with android.hardware.health V1
    if (mBatteryHealthStatus < BatteryMonitor::BH_MARGINAL) {
        if (readFromFile(mHealthdConfig->batteryHealthPath, &buf) > 0)
            mHealthInfo->batteryHealth = getBatteryHealth(buf.c_str());
    } else {
        mHealthInfo->batteryHealth = getBatteryHealthStatus(mBatteryHealthStatus);
    }

    if (readFromFile(mHealthdConfig->batteryTechnologyPath, &buf) > 0)
        mHealthInfo->batteryTechnology = String8(buf.c_str());
@@ -878,6 +904,12 @@ void BatteryMonitor::init(struct healthd_config *hc) {
                    }
                }

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

                if (mHealthdConfig->batteryManufacturingDatePath.isEmpty()) {
                    path.clear();
                    path.appendFormat("%s/%s/manufacturing_date", POWER_SUPPLY_SYSFS_PATH, name);
@@ -957,6 +989,8 @@ void BatteryMonitor::init(struct healthd_config *hc) {
            KLOG_WARNING(LOG_TAG, "batteryFullChargeDesignCapacityUahPath. not found\n");
        if (mHealthdConfig->batteryStateOfHealthPath.isEmpty())
            KLOG_WARNING(LOG_TAG, "batteryStateOfHealthPath not found\n");
        if (mHealthdConfig->batteryHealthStatusPath.isEmpty())
            KLOG_WARNING(LOG_TAG, "batteryHealthStatusPath not found\n");
        if (mHealthdConfig->batteryManufacturingDatePath.isEmpty())
            KLOG_WARNING(LOG_TAG, "batteryManufacturingDatePath not found\n");
        if (mHealthdConfig->batteryFirstUsageDatePath.isEmpty())
+9 −0
Original line number Diff line number Diff line
@@ -56,6 +56,14 @@ class BatteryMonitor {
        ANDROID_POWER_SUPPLY_TYPE_DOCK
    };

    enum BatteryHealthStatus {
        BH_UNKNOWN = -1,
        BH_NOMINAL,
        BH_MARGINAL,
        BH_NEEDS_REPLACEMENT,
        BH_FAILED,
    };

    BatteryMonitor();
    ~BatteryMonitor();
    void init(struct healthd_config *hc);
@@ -85,6 +93,7 @@ class BatteryMonitor {
    bool mBatteryDevicePresent;
    int mBatteryFixedCapacity;
    int mBatteryFixedTemperature;
    int mBatteryHealthStatus;
    std::unique_ptr<aidl::android::hardware::health::HealthInfo> mHealthInfo;
};

+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ struct healthd_config {
    android::String8 batteryChargeTimeToFullNowPath;
    android::String8 batteryFullChargeDesignCapacityUahPath;
    android::String8 batteryStateOfHealthPath;
    android::String8 batteryHealthStatusPath;
    android::String8 batteryManufacturingDatePath;
    android::String8 batteryFirstUsageDatePath;
    android::String8 chargingStatePath;