Merge changes from topic "health2_passthru"

* changes:
  healthd: charger use health 2.0 HAL
  healthd: move healthd_board_init call to Health::Health() c-tor
diff --git a/healthd/Android.mk b/healthd/Android.mk
index c1a82c2..d725f73 100644
--- a/healthd/Android.mk
+++ b/healthd/Android.mk
@@ -47,6 +47,8 @@
     $(LOCAL_PATH)/include
 
 LOCAL_STATIC_LIBRARIES := \
+    android.hardware.health@2.0 \
+    android.hardware.health@1.0 \
     libminui \
     libpng \
     libz \
@@ -74,7 +76,6 @@
 endif
 
 LOCAL_SRC_FILES := \
-    healthd_common.cpp \
     charger.cpp \
 
 LOCAL_MODULE := charger
@@ -96,6 +97,13 @@
 endif
 
 LOCAL_STATIC_LIBRARIES := \
+    android.hardware.health@2.0-impl \
+    android.hardware.health@2.0 \
+    android.hardware.health@1.0 \
+    libhidltransport \
+    libhidlbase \
+    libhwbinder \
+    libvndksupport \
     libhealthd_charger \
     libhealthd_draw \
     libbatterymonitor \
diff --git a/healthd/Health.cpp b/healthd/Health.cpp
index d271811..822f664 100644
--- a/healthd/Health.cpp
+++ b/healthd/Health.cpp
@@ -16,6 +16,8 @@
 sp<Health> Health::instance_;
 
 Health::Health(struct healthd_config* c) {
+    // TODO(b/69268160): remove when libhealthd is removed.
+    healthd_board_init(c);
     battery_monitor_ = std::make_unique<BatteryMonitor>();
     battery_monitor_->init(c);
 }
diff --git a/healthd/HealthServiceCommon.cpp b/healthd/HealthServiceCommon.cpp
index 68ff526..266ca3a 100644
--- a/healthd/HealthServiceCommon.cpp
+++ b/healthd/HealthServiceCommon.cpp
@@ -53,13 +53,6 @@
             LOG(ERROR) << LOG_TAG << ": Register for binder events failed";
     }
 
-    // Implementation-defined init logic goes here.
-    // 1. config->periodic_chores_interval_* variables
-    // 2. config->battery*Path variables
-    // 3. config->energyCounter. In this implementation, energyCounter is not defined.
-    // TODO(b/68724651): healthd_board_* functions should be removed in health@2.0
-    healthd_board_init(config);
-
     android::sp<IHealth> service = Health::initInstance(config);
     CHECK_EQ(service->registerAsService(HEALTH_INSTANCE_NAME), android::OK)
         << LOG_TAG << ": Failed to register HAL";
@@ -77,9 +70,6 @@
 }
 
 void healthd_mode_service_2_0_battery_update(struct android::BatteryProperties* prop) {
-    // Implementation-defined update logic goes here. An implementation
-    // can make modifications to prop before broadcasting it to all callbacks.
-
     HealthInfo info;
     convertToHealthInfo(prop, info);
     Health::getImplementation()->notifyListeners(info);
diff --git a/healthd/HealthServiceDefault.cpp b/healthd/HealthServiceDefault.cpp
index 42e76d9..dbc480f 100644
--- a/healthd/HealthServiceDefault.cpp
+++ b/healthd/HealthServiceDefault.cpp
@@ -17,10 +17,18 @@
 #include <healthd/healthd.h>
 
 void healthd_board_init(struct healthd_config*) {
+    // Implementation-defined init logic goes here.
+    // 1. config->periodic_chores_interval_* variables
+    // 2. config->battery*Path variables
+    // 3. config->energyCounter. In this implementation, energyCounter is not defined.
+
     // use defaults
 }
 
 int healthd_board_battery_update(struct android::BatteryProperties*) {
+    // Implementation-defined update logic goes here. An implementation
+    // can make modifications to prop before broadcasting it to all callbacks.
+
     // return 0 to log periodic polled battery status to kernel log
     return 0;
 }
diff --git a/healthd/charger.cpp b/healthd/charger.cpp
index 5a8fe1a..ede14f2 100644
--- a/healthd/charger.cpp
+++ b/healthd/charger.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "charger"
 #define KLOG_LEVEL 6
 
+#include <health2/Health.h>
 #include <healthd/healthd.h>
 
 #include <stdlib.h>
@@ -62,7 +63,9 @@
 };
 #endif
 
-static void healthd_mode_nop_init(struct healthd_config* /*config*/) {
+static void healthd_mode_nop_init(struct healthd_config* config) {
+    using android::hardware::health::V2_0::implementation::Health;
+    Health::initInstance(config);
 }
 
 static int healthd_mode_nop_preparetowait(void) {
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index 4f77e7a..61e7465 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -49,6 +49,7 @@
 #include "AnimationParser.h"
 #include "healthd_draw.h"
 
+#include <health2/Health.h>
 #include <healthd/healthd.h>
 
 using namespace android;
@@ -612,6 +613,8 @@
 }
 
 void healthd_mode_charger_init(struct healthd_config* config) {
+    using android::hardware::health::V2_0::implementation::Health;
+
     int ret;
     charger* charger = &charger_state;
     int i;
@@ -666,6 +669,10 @@
     charger->next_screen_transition = -1;
     charger->next_key_check = -1;
     charger->next_pwr_check = -1;
+
+    // Initialize Health implementation (which initializes the internal BatteryMonitor).
+    Health::initInstance(config);
+
     healthd_config = config;
     charger->boot_min_cap = config->boot_min_cap;
 }