diff --git a/health/HealthService.cpp b/health/HealthService.cpp index 7ad02c0..8b1d0f7 100644 --- a/health/HealthService.cpp +++ b/health/HealthService.cpp @@ -60,6 +60,10 @@ constexpr char kUFSName[]{"UFS0"}; constexpr char kTCPMPSYName[]{"tcpm-source-psy-usbpd0"}; +#define WLC_DIR "/sys/class/power_supply/wireless" +static bool needs_wlc_updates = false; +constexpr char kWlcCapacity[]{WLC_DIR "/capacity"}; + std::ifstream assert_open(const std::string &path) { std::ifstream stream(path); if (!stream.is_open()) { @@ -83,14 +87,26 @@ void fill_ufs_storage_attribute(StorageAttribute *attr) { } // anonymous namespace +static bool FileExists(const std::string &filename) { + struct stat buffer; + + return stat(filename.c_str(), &buffer) == 0; +} + void healthd_board_init(struct healthd_config *hc) { hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName)); + needs_wlc_updates = FileExists(kWlcCapacity); } int healthd_board_battery_update(struct android::BatteryProperties *props) { deviceHealth.update(props); battMetricsLogger.logBatteryProperties(props); shutdownMetrics.logShutdownVoltage(props); + + if (needs_wlc_updates && + !android::base::WriteStringToFile(std::to_string(props->batteryLevel), kWlcCapacity)) + LOG(INFO) << "Unable to write battery level to wireless capacity"; + return 0; }