diff options
author | Hridya Valsaraju <hridya@google.com> | 2018-09-28 11:41:22 -0700 |
---|---|---|
committer | Hridya Valsaraju <hridya@google.com> | 2018-09-28 14:28:49 -0700 |
commit | 47658caae4ded29374c12e96394636b71cf834af (patch) | |
tree | 1e395e74395fc64aa65acdbe0b473a5885d1c256 /fastboot/device/variables.cpp | |
parent | 7c9bbe948b446b6e995ea9fdd3a3226362372ca9 (diff) |
Interface with health HAL to read battery voltage
Bug: 78793464
Test: fastboot getvar battery-voltage
Change-Id: Ie0763e4f08327ec7649c5629066eb73e8142e0e6
Diffstat (limited to 'fastboot/device/variables.cpp')
-rw-r--r-- | fastboot/device/variables.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp index bcf13a540..01415d72b 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -24,6 +24,7 @@ #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <ext4_utils/ext4_utils.h> +#include <healthhalutils/HealthHalUtils.h> #include "fastboot_device.h" #include "flashing.h" @@ -117,6 +118,30 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string return true; } +bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, + std::string* message) { + using android::hardware::health::V2_0::HealthInfo; + using android::hardware::health::V2_0::Result; + + auto health_hal = device->health_hal(); + if (!health_hal) { + *message = "Health HAL not found"; + return false; + } + + Result ret; + auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { + *message = std::to_string(info.legacy.batteryVoltage); + ret = result; + }); + if (!ret_val.isOk() || (ret != Result::SUCCESS)) { + *message = "Unable to get battery voltage"; + return false; + } + + return true; +} + bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); |