Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c601ec2f authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

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

parents 1fd75302 8b413eb4
Loading
Loading
Loading
Loading
+28 −12
Original line number Diff line number Diff line
@@ -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();
}