From d5ed26a45ab400c44a1eff6fc31be55a82ed8ba9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 8 Dec 2023 15:12:24 -0800 Subject: [PATCH] healthd: Add support for the new Health HAL v3 properties. Add BATTERY_PROP_PART_STATUS support via getProperty. Add serial number support via a new helper function, since it doesn't fit neatly into the BatteryProperty structure. There are no sysfs nodes for this yet, so currently it is stubbed. Bug: 309792384 Test: fastboot getvar battery-part-status fastboot getvar battery-serial-number Change-Id: I3777e092d4ef26c02a7dd5420c9eaf1ec5aeae92 --- healthd/BatteryMonitor.cpp | 14 ++++++++++++++ healthd/include/healthd/BatteryMonitor.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 0c976322d..efd9907df 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -59,6 +59,7 @@ using aidl::android::hardware::health::BatteryChargingPolicy; using aidl::android::hardware::health::BatteryChargingState; using aidl::android::hardware::health::BatteryHealth; using aidl::android::hardware::health::BatteryHealthData; +using aidl::android::hardware::health::BatteryPartStatus; using aidl::android::hardware::health::BatteryStatus; using aidl::android::hardware::health::HealthInfo; @@ -596,6 +597,9 @@ int BatteryMonitor::getBatteryHealthData(int id) { if (!mHealthdConfig->batteryStateOfHealthPath.empty()) return getIntField(mHealthdConfig->batteryStateOfHealthPath); } + if (id == BATTERY_PROP_PART_STATUS) { + return static_cast(BatteryPartStatus::UNSUPPORTED); + } return 0; } @@ -679,6 +683,11 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { ret = OK; break; + case BATTERY_PROP_PART_STATUS: + val->valueInt64 = getBatteryHealthData(BATTERY_PROP_PART_STATUS); + ret = OK; + break; + default: break; } @@ -686,6 +695,11 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { return ret; } +status_t BatteryMonitor::getSerialNumber(std::optional* out) { + *out = std::nullopt; + return OK; +} + void BatteryMonitor::dumpState(int fd) { int v; char vs[128]; diff --git a/healthd/include/healthd/BatteryMonitor.h b/healthd/include/healthd/BatteryMonitor.h index e9998ba7a..b30458d3c 100644 --- a/healthd/include/healthd/BatteryMonitor.h +++ b/healthd/include/healthd/BatteryMonitor.h @@ -18,6 +18,7 @@ #define HEALTHD_BATTERYMONITOR_H #include +#include #include #include @@ -86,6 +87,8 @@ class BatteryMonitor { int getChargingPolicy(); int getBatteryHealthData(int id); + status_t getSerialNumber(std::optional* out); + static void logValues(const android::hardware::health::V2_1::HealthInfo& health_info, const struct healthd_config& healthd_config);