fastboot: Add getvar commands to query battery part info.
This adds two commands to test the new v3 Health HAL, to query the
battery serial number (unlocked devices only) and part status.
Bug: 309792384
Test: adb reboot fastboot
fastboot getvar battery-part-status
fastboot getvar battery-serial-number
Change-Id: Ie0a14eda06483d047544833124c327fb88ba43a2
diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp
index bd936ae..e522f4d 100644
--- a/fastboot/device/commands.cpp
+++ b/fastboot/device/commands.cpp
@@ -147,6 +147,8 @@
{FB_VAR_SECURITY_PATCH_LEVEL, {GetSecurityPatchLevel, nullptr}},
{FB_VAR_TREBLE_ENABLED, {GetTrebleEnabled, nullptr}},
{FB_VAR_MAX_FETCH_SIZE, {GetMaxFetchSize, nullptr}},
+ {FB_VAR_BATTERY_SERIAL_NUMBER, {GetBatterySerialNumber, nullptr}},
+ {FB_VAR_BATTERY_PART_STATUS, {GetBatteryPartStatus, nullptr}},
};
static bool GetVarAll(FastbootDevice* device) {
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index 2847e35..77210ab 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -570,3 +570,79 @@
return true;
}
+
+bool GetBatterySerialNumber(FastbootDevice* device, const std::vector<std::string>&,
+ std::string* message) {
+ auto health_hal = device->health_hal();
+ if (!health_hal) {
+ return false;
+ }
+
+ if (GetDeviceLockStatus()) {
+ return device->WriteFail("Device is locked");
+ }
+
+ *message = "unsupported";
+
+ int32_t version = 0;
+ auto res = health_hal->getInterfaceVersion(&version);
+ if (!res.isOk()) {
+ return device->WriteFail("Unable to query battery data");
+ }
+ if (version >= 3) {
+ using aidl::android::hardware::health::BatteryHealthData;
+
+ BatteryHealthData data;
+ auto res = health_hal->getBatteryHealthData(&data);
+ if (!res.isOk()) {
+ return device->WriteFail("Unable to query battery data");
+ }
+ if (data.batterySerialNumber) {
+ *message = *data.batterySerialNumber;
+ }
+ }
+ return true;
+}
+
+bool GetBatteryPartStatus(FastbootDevice* device, const std::vector<std::string>&,
+ std::string* message) {
+ auto health_hal = device->health_hal();
+ if (!health_hal) {
+ return false;
+ }
+
+ using aidl::android::hardware::health::BatteryPartStatus;
+
+ BatteryPartStatus status = BatteryPartStatus::UNSUPPORTED;
+
+ int32_t version = 0;
+ auto res = health_hal->getInterfaceVersion(&version);
+ if (!res.isOk()) {
+ return device->WriteFail("Unable to query battery data");
+ }
+ if (version >= 3) {
+ using aidl::android::hardware::health::BatteryHealthData;
+
+ BatteryHealthData data;
+ auto res = health_hal->getBatteryHealthData(&data);
+ if (!res.isOk()) {
+ return device->WriteFail("Unable to query battery data");
+ }
+ status = data.batteryPartStatus;
+ }
+ switch (status) {
+ case BatteryPartStatus::UNSUPPORTED:
+ *message = "unsupported";
+ break;
+ case BatteryPartStatus::ORIGINAL:
+ *message = "original";
+ break;
+ case BatteryPartStatus::REPLACED:
+ *message = "replaced";
+ break;
+ default:
+ *message = "unknown";
+ break;
+ }
+ return true;
+}
diff --git a/fastboot/device/variables.h b/fastboot/device/variables.h
index 9a46786..99d1355 100644
--- a/fastboot/device/variables.h
+++ b/fastboot/device/variables.h
@@ -67,6 +67,10 @@
std::string* message);
bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& args,
std::string* message);
+bool GetBatterySerialNumber(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message);
+bool GetBatteryPartStatus(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message);
bool GetSuperPartitionName(FastbootDevice* device, const std::vector<std::string>& args,
std::string* message);
bool GetSnapshotUpdateStatus(FastbootDevice* device, const std::vector<std::string>& args,