Merge "health: Query new properties from BatteryMonitor." into main am: c601ec2ff5 am: e62ba8d5ba

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2865639

Change-Id: Ie8728c3484e08dc5dc9d9d0d2167771bd65d5ead
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
David Anderson 2023-12-12 21:14:42 +00:00 committed by Automerger Merge Worker
commit 0748629366

View file

@ -62,6 +62,18 @@ Health::Health(std::string_view instance_name, std::unique_ptr<struct healthd_co
Health::~Health() {}
static inline ndk::ScopedAStatus TranslateStatus(::android::status_t err) {
switch (err) {
case ::android::OK:
return ndk::ScopedAStatus::ok();
case ::android::NAME_NOT_FOUND:
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
default:
return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
IHealth::STATUS_UNKNOWN, ::android::statusToString(err).c_str());
}
}
//
// Getters.
//
@ -78,16 +90,7 @@ static ndk::ScopedAStatus GetProperty(::android::BatteryMonitor* monitor, int id
LOG(DEBUG) << "getProperty(" << id << ")"
<< " fails: (" << err << ") " << ::android::statusToString(err);
}
switch (err) {
case ::android::OK:
return ndk::ScopedAStatus::ok();
case ::android::NAME_NOT_FOUND:
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
default:
return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
IHealth::STATUS_UNKNOWN, ::android::statusToString(err).c_str());
}
return TranslateStatus(err);
}
ndk::ScopedAStatus Health::getChargeCounterUah(int32_t* out) {
@ -153,8 +156,21 @@ ndk::ScopedAStatus Health::getBatteryHealthData(BatteryHealthData* out) {
!res.isOk()) {
LOG(WARNING) << "Cannot get Battery_state_of_health: " << res.getDescription();
}
out->batterySerialNumber = std::nullopt;
out->batteryPartStatus = BatteryPartStatus::UNSUPPORTED;
if (auto res = battery_monitor_.getSerialNumber(&out->batterySerialNumber);
res != ::android::OK) {
LOG(WARNING) << "Cannot get Battery_serial_number: "
<< TranslateStatus(res).getDescription();
}
int64_t part_status = static_cast<int64_t>(BatteryPartStatus::UNSUPPORTED);
if (auto res = GetProperty<int64_t>(&battery_monitor_, ::android::BATTERY_PROP_PART_STATUS,
static_cast<int64_t>(BatteryPartStatus::UNSUPPORTED),
&part_status);
!res.isOk()) {
LOG(WARNING) << "Cannot get Battery_part_status: " << res.getDescription();
}
out->batteryPartStatus = static_cast<BatteryPartStatus>(part_status);
return ndk::ScopedAStatus::ok();
}