diff options
author | David Anderson <dvander@google.com> | 2023-12-12 04:00:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-12-12 04:00:47 +0000 |
commit | 99a33df54466fa9ca5283c2ac92e546651f0044a (patch) | |
tree | 7d0abf4e6d5bbde5db9f6607bf8f19e35009d05e /fastboot | |
parent | 314818029cbde8cc2252fd2d36123454d2965f95 (diff) | |
parent | 2cb36706f40a7afac9159126a97421b37e2ef8dc (diff) | |
download | core-99a33df54466fa9ca5283c2ac92e546651f0044a.tar.gz |
Merge changes from topic "health-v3" into main
* changes:
fastboot: Add getvar commands to query battery part info.
Update fastbootd to use Health AIDL HAL V3.
Update healthd to use Health AIDL HAL V3.
Update storaged to use Health AIDL HAL V3.
Diffstat (limited to 'fastboot')
-rw-r--r-- | fastboot/Android.bp | 2 | ||||
-rw-r--r-- | fastboot/constants.h | 2 | ||||
-rw-r--r-- | fastboot/device/commands.cpp | 2 | ||||
-rw-r--r-- | fastboot/device/variables.cpp | 76 | ||||
-rw-r--r-- | fastboot/device/variables.h | 4 |
5 files changed, 85 insertions, 1 deletions
diff --git a/fastboot/Android.bp b/fastboot/Android.bp index f85d1dea4..c0445f359 100644 --- a/fastboot/Android.bp +++ b/fastboot/Android.bp @@ -170,7 +170,7 @@ cc_binary { "android.hardware.fastboot@1.1", "android.hardware.fastboot-V1-ndk", "android.hardware.health@2.0", - "android.hardware.health-V2-ndk", + "android.hardware.health-V3-ndk", "libasyncio", "libbase", "libbinder_ndk", diff --git a/fastboot/constants.h b/fastboot/constants.h index a80330746..af4d1eb12 100644 --- a/fastboot/constants.h +++ b/fastboot/constants.h @@ -82,3 +82,5 @@ #define FB_VAR_TREBLE_ENABLED "treble-enabled" #define FB_VAR_MAX_FETCH_SIZE "max-fetch-size" #define FB_VAR_DMESG "dmesg" +#define FB_VAR_BATTERY_SERIAL_NUMBER "battery-serial-number" +#define FB_VAR_BATTERY_PART_STATUS "battery-part-status" diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp index bd936ae77..e522f4d4d 100644 --- a/fastboot/device/commands.cpp +++ b/fastboot/device/commands.cpp @@ -147,6 +147,8 @@ const std::unordered_map<std::string, VariableHandlers> kVariableMap = { {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 2847e35ab..77210abcb 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -570,3 +570,79 @@ bool GetDmesg(FastbootDevice* device) { 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 9a4678641..99d1355ef 100644 --- a/fastboot/device/variables.h +++ b/fastboot/device/variables.h @@ -67,6 +67,10 @@ bool GetBatterySoC(FastbootDevice* device, const std::vector<std::string>& args, 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, |