[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
diff --git a/health/2.0/default/Health.cpp b/health/2.0/default/Health.cpp
index c0c5a40..4225fd8 100644
--- a/health/2.0/default/Health.cpp
+++ b/health/2.0/default/Health.cpp
@@ -17,11 +17,15 @@
#include <android-base/logging.h>
#include <android-base/file.h>
+#include <android/hardware/health/2.0/types.h>
#include <health2/Health.h>
#include <hal_conversion.h>
#include <hidl/HidlTransportSupport.h>
+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 @@
// 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 @@
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<StorageInfo> info;
get_storage_info(info);
@@ -272,8 +275,6 @@
currentAvg = static_cast<int32_t>(prop.valueInt64);
}
- V2_0::HealthInfo healthInfo = {};
- healthInfo.legacy = std::move(batteryInfo);
healthInfo.batteryCurrentAverage = currentAvg;
healthInfo.diskStats = stats;
healthInfo.storageInfos = info;