Merge "health: Query new properties from BatteryMonitor." into main
This commit is contained in:
commit
c601ec2ff5
1 changed files with 28 additions and 12 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue