From 00ebc75aef885736d30946c4f81392abadff57d6 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 7 Oct 2019 12:25:23 -0700 Subject: [PATCH] [REFACTOR] health 2.0: battery monitor returns health info 2.0 BatteryMonitor returns HealthInfo structs directly. Modify code to adapt to this behavior. Test: health VTS test 2.0 Bug: 142260281 Change-Id: I5e6605e46bb4f8bb08c1356e5f2233880e6f9d14 --- health/2.0/default/Health.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/health/2.0/default/Health.cpp b/health/2.0/default/Health.cpp index c0c5a404c9..4225fd8bb9 100644 --- a/health/2.0/default/Health.cpp +++ b/health/2.0/default/Health.cpp @@ -17,11 +17,15 @@ #include #include +#include #include #include #include +using HealthInfo_1_0 = android::hardware::health::V1_0::HealthInfo; +using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo; + extern void healthd_battery_update_internal(bool); namespace android { @@ -149,7 +153,9 @@ Return Health::update() { // Retrieve all information and call healthd_mode_ops->battery_update, which calls // notifyListeners. battery_monitor_->updateValues(); - struct BatteryProperties props = getBatteryProperties(battery_monitor_.get()); + const HealthInfo_1_0& health_info = battery_monitor_->getHealthInfo_1_0(); + struct BatteryProperties props; + convertFromHealthInfo(health_info, &props); bool log = healthd_board_battery_update(&props); if (log) { battery_monitor_->logValues(); @@ -253,10 +259,7 @@ Return Health::getHealthInfo(getHealthInfo_cb _hidl_cb) { using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo; updateAndNotify(nullptr); - struct android::BatteryProperties p = getBatteryProperties(battery_monitor_.get()); - - V1_0::HealthInfo batteryInfo; - convertToHealthInfo(&p, batteryInfo); + HealthInfo healthInfo = battery_monitor_->getHealthInfo_2_0(); std::vector info; get_storage_info(info); @@ -272,8 +275,6 @@ Return Health::getHealthInfo(getHealthInfo_cb _hidl_cb) { currentAvg = static_cast(prop.valueInt64); } - V2_0::HealthInfo healthInfo = {}; - healthInfo.legacy = std::move(batteryInfo); healthInfo.batteryCurrentAverage = currentAvg; healthInfo.diskStats = stats; healthInfo.storageInfos = info;