From 47658caae4ded29374c12e96394636b71cf834af Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Fri, 28 Sep 2018 11:41:22 -0700 Subject: Interface with health HAL to read battery voltage Bug: 78793464 Test: fastboot getvar battery-voltage Change-Id: Ie0763e4f08327ec7649c5629066eb73e8142e0e6 --- fastboot/device/variables.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'fastboot/device/variables.cpp') 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 #include #include +#include #include "fastboot_device.h" #include "flashing.h" @@ -117,6 +118,30 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector& /* 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& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); -- cgit v1.2.3