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 <gspj@google.com>
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index d2a7947..2847e35 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -130,6 +130,21 @@
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<std::string>& /* args */,
std::string* message) {
int32_t battery_voltage = 0;
@@ -185,6 +200,17 @@
return false;
}
+bool GetBatterySoC(FastbootDevice* device, const std::vector<std::string>& /* 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<std::string>& /* args */,
std::string* message) {
std::string suffix = device->GetCurrentSlot();