From 7fa8dd655ac242fef79184a611aa9e5d7a8c62eb Mon Sep 17 00:00:00 2001 From: Harry Pan Date: Tue, 3 Oct 2023 17:48:26 +0000 Subject: [PATCH] Add new fastbootd battery-soc variable Introduce new battery-soc variable to read battery SSOC, this benefits manufacturing to better track the SSOC after FSI image flashing in the userspace fastbootd using the same approach as Android space, otherwise it is difficult to implement the entire battery SW stack from Android to fastboot bootloader and generate the same test experience monotonically. Bug: 303561559 Test: fastboot getvar battery-soc # in fastbootd Change-Id: Ia3f68e314263d7dd4d4c45a908a0a49db6e761f9 Signed-off-by: Harry Pan --- fastboot/constants.h | 1 + fastboot/device/commands.cpp | 1 + fastboot/device/variables.cpp | 26 ++++++++++++++++++++++++++ fastboot/device/variables.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/fastboot/constants.h b/fastboot/constants.h index ad169d1dc..a80330746 100644 --- a/fastboot/constants.h +++ b/fastboot/constants.h @@ -69,6 +69,7 @@ #define FB_VAR_VARIANT "variant" #define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge" #define FB_VAR_BATTERY_VOLTAGE "battery-voltage" +#define FB_VAR_BATTERY_SOC "battery-soc" #define FB_VAR_BATTERY_SOC_OK "battery-soc-ok" #define FB_VAR_SUPER_PARTITION_NAME "super-partition-name" #define FB_VAR_SNAPSHOT_UPDATE_STATUS "snapshot-update-status" diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp index 6de598f69..bd936ae77 100644 --- a/fastboot/device/commands.cpp +++ b/fastboot/device/commands.cpp @@ -134,6 +134,7 @@ const std::unordered_map kVariableMap = { {FB_VAR_IS_FORCE_DEBUGGABLE, {GetIsForceDebuggable, nullptr}}, {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}}, {FB_VAR_BATTERY_VOLTAGE, {GetBatteryVoltage, nullptr}}, + {FB_VAR_BATTERY_SOC, {GetBatterySoC, nullptr}}, {FB_VAR_BATTERY_SOC_OK, {GetBatterySoCOk, nullptr}}, {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}, {FB_VAR_SUPER_PARTITION_NAME, {GetSuperPartitionName, nullptr}}, diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp index d2a794715..2847e35ab 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -130,6 +130,21 @@ bool GetBatteryVoltageHelper(FastbootDevice* device, int32_t* battery_voltage) { return true; } +bool GetBatterySoCHelper(FastbootDevice* device, int32_t* battery_soc) { + using aidl::android::hardware::health::HealthInfo; + + auto health_hal = device->health_hal(); + if (!health_hal) { + return false; + } + + HealthInfo health_info; + auto res = health_hal->getHealthInfo(&health_info); + if (!res.isOk()) return false; + *battery_soc = health_info.batteryLevel; + return true; +} + bool GetBatterySoCOk(FastbootDevice* device, const std::vector& /* args */, std::string* message) { int32_t battery_voltage = 0; @@ -185,6 +200,17 @@ bool GetBatteryVoltage(FastbootDevice* device, const std::vector& / return false; } +bool GetBatterySoC(FastbootDevice* device, const std::vector& /* args */, + std::string* message) { + int32_t battery_soc = 0; + if (GetBatterySoCHelper(device, &battery_soc)) { + *message = std::to_string(battery_soc); + return true; + } + *message = "Unable to get battery soc"; + return false; +} + bool GetCurrentSlot(FastbootDevice* device, const std::vector& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); diff --git a/fastboot/device/variables.h b/fastboot/device/variables.h index 3b2d48447..9a4678641 100644 --- a/fastboot/device/variables.h +++ b/fastboot/device/variables.h @@ -63,6 +63,8 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector& args, std::string* message); +bool GetBatterySoC(FastbootDevice* device, const std::vector& args, + std::string* message); bool GetBatterySoCOk(FastbootDevice* device, const std::vector& args, std::string* message); bool GetSuperPartitionName(FastbootDevice* device, const std::vector& args,