From be17a4f23529da0b769b745e3296e4e4e5ef06c5 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 11 Oct 2017 10:40:56 -0700 Subject: [PATCH] Update for expanding @2.0::HealthInfo. Health service also sends other fields in callbacks. Test: builds Bug: 62229583 Change-Id: Icb9215c263ba34055e77db3dbb047998bb2da4e8 --- healthd/Health.cpp | 15 ++++++++++++--- healthd/HealthService.cpp | 8 ++++---- healthd/include/health2/Health.h | 3 +-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/healthd/Health.cpp b/healthd/Health.cpp index 74f3eec21..ec05398f4 100644 --- a/healthd/Health.cpp +++ b/healthd/Health.cpp @@ -120,7 +120,7 @@ Return Health::update() { } // Retrieve all information and call healthd_mode_ops->battery_update, which calls - // notifyListeners. + // updateAndNotify. bool chargerOnline = battery_monitor_->update(); // adjust uevent / wakealarm periods @@ -129,10 +129,19 @@ Return Health::update() { return Result::SUCCESS; } -void Health::notifyListeners(const HealthInfo& info) { +void Health::updateAndNotify(HealthInfo* info) { + // update 2.0 specific fields + struct BatteryProperty prop; + if (battery_monitor_->getProperty(BATTERY_PROP_CURRENT_AVG, &prop) == OK) + info->batteryCurrentAverage = static_cast(prop.valueInt64); + if (battery_monitor_->getProperty(BATTERY_PROP_CAPACITY, &prop) == OK) + info->batteryCapacity = static_cast(prop.valueInt64); + if (battery_monitor_->getProperty(BATTERY_PROP_ENERGY_COUNTER, &prop) == OK) + info->energyCounter = prop.valueInt64; + std::lock_guard _lock(callbacks_lock_); for (auto it = callbacks_.begin(); it != callbacks_.end();) { - auto ret = (*it)->healthInfoChanged(info); + auto ret = (*it)->healthInfoChanged(*info); if (!ret.isOk() && ret.isDeadObject()) { it = callbacks_.erase(it); } else { diff --git a/healthd/HealthService.cpp b/healthd/HealthService.cpp index e8a1a85e2..29a29ed4c 100644 --- a/healthd/HealthService.cpp +++ b/healthd/HealthService.cpp @@ -28,8 +28,8 @@ using android::hardware::IPCThreadState; using android::hardware::configureRpcThreadpool; -using android::hardware::health::V1_0::HealthInfo; using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo; +using android::hardware::health::V2_0::HealthInfo; using android::hardware::health::V2_0::IHealth; using android::hardware::health::V2_0::implementation::Health; @@ -89,9 +89,9 @@ void healthd_mode_service_2_0_battery_update(struct android::BatteryProperties* // Implementation-defined update logic goes here. An implementation // can make modifications to prop before broadcasting it to all callbacks. - HealthInfo info; - convertToHealthInfo(prop, info); - static_cast(gHealth.get())->notifyListeners(info); + HealthInfo info{}; + convertToHealthInfo(prop, info.legacy); + static_cast(gHealth.get())->updateAndNotify(&info); } static struct healthd_mode_ops healthd_mode_service_2_0_ops = { diff --git a/healthd/include/health2/Health.h b/healthd/include/health2/Health.h index 4e78380e7..d390b92fe 100644 --- a/healthd/include/health2/Health.h +++ b/healthd/include/health2/Health.h @@ -16,7 +16,6 @@ namespace V2_0 { namespace implementation { using V1_0::BatteryStatus; -using V1_0::HealthInfo; using ::android::hidl::base::V1_0::IBase; @@ -25,7 +24,7 @@ struct Health : public IHealth, hidl_death_recipient { Health(struct healthd_config* c); // TODO(b/62229583): clean up and hide these functions. - void notifyListeners(const HealthInfo& info); + void updateAndNotify(HealthInfo* info); // Methods from IHealth follow. Return registerCallback(const sp& callback) override;