diff options
author | Yifan Hong <elsk@google.com> | 2018-08-28 15:10:42 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2018-08-28 15:22:05 -0700 |
commit | b8691ae1686746bba76e57411afc0d9242ba2e56 (patch) | |
tree | c60daa6db91ec347ac9d4cd91d9d4e6126878915 | |
parent | f11db565adf794d73f6874a084cbd4ffa14aadd0 (diff) | |
download | extras-b8691ae1686746bba76e57411afc0d9242ba2e56.tar.gz |
perfprofd: use getHealthInfo for get_charging
get_charging returns whether the phone is connected
to a charger. The phone can be connected to a charger without
actually being charged.
Test: perfprofd_test
Bug: 112184119
Change-Id: I0b574c73043056c7ceceb38df343ba7c9dce4ebf
-rw-r--r-- | perfprofd/perfprofdcore.cc | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/perfprofd/perfprofdcore.cc b/perfprofd/perfprofdcore.cc index 9afeb203..00ec8a70 100644 --- a/perfprofd/perfprofdcore.cc +++ b/perfprofd/perfprofdcore.cc @@ -295,12 +295,12 @@ bool get_camera_active() bool get_charging() { #ifdef __ANDROID__ + using android::sp; using android::hardware::Return; - using android::hardware::health::V1_0::BatteryStatus; - using android::hardware::health::V2_0::Result; - using android::hardware::health::V2_0::IHealth; using android::hardware::health::V2_0::get_health_service; - using android::sp; + using android::hardware::health::V2_0::HealthInfo; + using android::hardware::health::V2_0::IHealth; + using android::hardware::health::V2_0::Result; sp<IHealth> service = get_health_service(); if (service == nullptr) { @@ -308,21 +308,23 @@ bool get_charging() return false; } Result res = Result::UNKNOWN; - BatteryStatus val = BatteryStatus::UNKNOWN; - Return<void> ret = service->getChargeStatus([&](Result out_res, BatteryStatus out_val) { - res = out_res; - val = out_val; - }); + HealthInfo val; + Return<void> ret = + service->getHealthInfo([&](Result out_res, HealthInfo out_val) { + res = out_res; + val = out_val; + }); if (!ret.isOk()) { LOG(ERROR) << "Failed to call getChargeStatus on health HAL: " << ret.description(); return false; } - if (res != Result::SUCCESS || val == BatteryStatus::UNKNOWN) { - LOG(ERROR) << "Failed to retrieve charge status from health HAL: result = " << toString(res) - << ", status = " << toString(val); + if (res != Result::SUCCESS) { + LOG(ERROR) << "Failed to retrieve charge status from health HAL: result = " + << toString(res); return false; } - return val == BatteryStatus::CHARGING || val == BatteryStatus::FULL; + return val.legacy.chargerAcOnline || val.legacy.chargerUsbOnline || + val.legacy.chargerWirelessOnline; #else return false; #endif |