healthd: clean up unused code

With migration to health 2.0 HAL, there are unused code paths
that can be removed.

Test: health VTS test
Test: charger_test
Bug: 68724651
Change-Id: I9af2f95432529a0bf6e10980a99014d570dfce93
diff --git a/healthd/Android.bp b/healthd/Android.bp
index ed1413e..95bb5f5 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -27,8 +27,6 @@
         "healthd_common.cpp",
     ],
 
-    cflags: ["-DHEALTHD_USE_HEALTH_2_0"],
-
     export_include_dirs: ["include"],
 
     shared_libs: [
diff --git a/healthd/Android.mk b/healthd/Android.mk
index 5f10f1e..63c9d27 100644
--- a/healthd/Android.mk
+++ b/healthd/Android.mk
@@ -89,12 +89,6 @@
 ifeq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
 LOCAL_CFLAGS += -DCHARGER_NO_UI
 endif
-ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_FAST),)
-LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_FAST=$(BOARD_PERIODIC_CHORES_INTERVAL_FAST)
-endif
-ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_SLOW),)
-LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_SLOW=$(BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
-endif
 
 CHARGER_STATIC_LIBRARIES := \
     android.hardware.health@2.0-impl \
diff --git a/healthd/charger_test.cpp b/healthd/charger_test.cpp
index acc0f5b..a7e2161 100644
--- a/healthd/charger_test.cpp
+++ b/healthd/charger_test.cpp
@@ -27,7 +27,7 @@
 #include <thread>
 #include <vector>
 
-#include <healthd/healthd.h>
+#include <health2/Health.h>
 
 #define LOG_THIS(fmt, ...)     \
     ALOGE(fmt, ##__VA_ARGS__); \
@@ -97,6 +97,16 @@
     return status;
 }
 
+::android::hardware::hidl_handle createHidlHandle(const char* filepath) {
+    int fd = creat(filepath, S_IRUSR | S_IWUSR);
+    if (fd < 0) return {};
+    native_handle_t* nativeHandle = native_handle_create(1, 0);
+    nativeHandle->data[0] = fd;
+    ::android::hardware::hidl_handle handle;
+    handle.setTo(nativeHandle, true /* shouldOwn */);
+    return handle;
+}
+
 void healthd_board_init(struct healthd_config* config) {
     config->periodic_chores_interval_fast = 60;
     config->periodic_chores_interval_slow = 600;
@@ -129,6 +139,8 @@
 extern int healthd_charger_main(int argc, char** argv);
 
 int main(int argc, char** argv) {
+    using android::hardware::health::V2_0::implementation::Health;
+
     const char* dumpFile = "/data/local/tmp/dump.txt";
 
     std::thread bgThread([=] {
@@ -141,12 +153,7 @@
         exit(1);
     }
 
-    int fd = creat(dumpFile, S_IRUSR | S_IWUSR);
-    if (fd < 0) {
-        exit(errno);
-    }
-    healthd_dump_battery_state(fd);
-    close(fd);
+    Health::getImplementation()->debug(createHidlHandle(dumpFile), {} /* options */);
 
     std::string content = openToString(dumpFile);
     int status = expectContains(content, {
diff --git a/healthd/healthd_common.cpp b/healthd/healthd_common.cpp
index 140c49d..3006644 100644
--- a/healthd/healthd_common.cpp
+++ b/healthd/healthd_common.cpp
@@ -33,25 +33,14 @@
 #include <sys/timerfd.h>
 #include <utils/Errors.h>
 
-#ifdef HEALTHD_USE_HEALTH_2_0
 #include <health2/Health.h>
-#endif
 
 using namespace android;
 
-#ifndef BOARD_PERIODIC_CHORES_INTERVAL_FAST
-  // Periodic chores fast interval in seconds
-  #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
-#else
-  #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (BOARD_PERIODIC_CHORES_INTERVAL_FAST)
-#endif
-
-#ifndef BOARD_PERIODIC_CHORES_INTERVAL_SLOW
-  // Periodic chores fast interval in seconds
-  #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
-#else
-  #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
-#endif
+// Periodic chores fast interval in seconds
+#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
+// Periodic chores fast interval in seconds
+#define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
 
 static struct healthd_config healthd_config = {
     .periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST,
@@ -88,11 +77,7 @@
 
 static int wakealarm_wake_interval = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST;
 
-#ifndef HEALTHD_USE_HEALTH_2_0
-static BatteryMonitor* gBatteryMonitor = nullptr;
-#else
 using ::android::hardware::health::V2_0::implementation::Health;
-#endif
 
 struct healthd_mode_ops *healthd_mode_ops = nullptr;
 
@@ -135,81 +120,6 @@
         KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n");
 }
 
-#ifdef HEALTHD_USE_HEALTH_2_0
-status_t convertStatus(android::hardware::health::V2_0::Result r) {
-    using android::hardware::health::V2_0::Result;
-    switch(r) {
-        case Result::SUCCESS:       return OK;
-        case Result::NOT_SUPPORTED: return BAD_VALUE;
-        case Result::NOT_FOUND:     return NAME_NOT_FOUND;
-        case Result::CALLBACK_DIED: return DEAD_OBJECT;
-        case Result::UNKNOWN: // fallthrough
-        default:
-            return UNKNOWN_ERROR;
-    }
-}
-#endif
-
-status_t healthd_get_property(int id, struct BatteryProperty *val) {
-#ifndef HEALTHD_USE_HEALTH_2_0
-    return gBatteryMonitor->getProperty(id, val);
-#else
-    using android::hardware::health::V1_0::BatteryStatus;
-    using android::hardware::health::V2_0::Result;
-    val->valueInt64 = INT64_MIN;
-    status_t err = UNKNOWN_ERROR;
-    switch (id) {
-        case BATTERY_PROP_CHARGE_COUNTER: {
-            Health::getImplementation()->getChargeCounter([&](Result r, int32_t v) {
-                err = convertStatus(r);
-                val->valueInt64 = v;
-            });
-            break;
-        }
-        case BATTERY_PROP_CURRENT_NOW: {
-            Health::getImplementation()->getCurrentNow([&](Result r, int32_t v) {
-                err = convertStatus(r);
-                val->valueInt64 = v;
-            });
-            break;
-        }
-        case BATTERY_PROP_CURRENT_AVG: {
-            Health::getImplementation()->getCurrentAverage([&](Result r, int32_t v) {
-                err = convertStatus(r);
-                val->valueInt64 = v;
-            });
-            break;
-        }
-        case BATTERY_PROP_CAPACITY: {
-            Health::getImplementation()->getCapacity([&](Result r, int32_t v) {
-                err = convertStatus(r);
-                val->valueInt64 = v;
-            });
-            break;
-        }
-        case BATTERY_PROP_ENERGY_COUNTER: {
-            Health::getImplementation()->getEnergyCounter([&](Result r, int64_t v) {
-                err = convertStatus(r);
-                val->valueInt64 = v;
-            });
-            break;
-        }
-        case BATTERY_PROP_BATTERY_STATUS: {
-            Health::getImplementation()->getChargeStatus([&](Result r, BatteryStatus v) {
-                err = convertStatus(r);
-                val->valueInt64 = static_cast<int64_t>(v);
-            });
-            break;
-        }
-        default: {
-            err = BAD_VALUE;
-            break;
-        }
-    }
-    return err;
-#endif
-}
-
 void healthd_battery_update_internal(bool charger_online) {
     // Fast wake interval when on charger (watch for overheat);
     // slow wake interval when on battery (watch for drained battery).
@@ -233,26 +143,8 @@
                 -1 : healthd_config.periodic_chores_interval_fast * 1000;
 }
 
-void healthd_battery_update(void) {
-#ifndef HEALTHD_USE_HEALTH_2_0
-    healthd_battery_update_internal(gBatteryMonitor->update());
-#else
+static void healthd_battery_update(void) {
     Health::getImplementation()->update();
-#endif
-}
-
-void healthd_dump_battery_state(int fd) {
-#ifndef HEALTHD_USE_HEALTH_2_0
-    gBatteryMonitor->dumpState(fd);
-#else
-    native_handle_t* nativeHandle = native_handle_create(1, 0);
-    nativeHandle->data[0] = fd;
-    ::android::hardware::hidl_handle handle;
-    handle.setTo(nativeHandle, true /* shouldOwn */);
-    Health::getImplementation()->debug(handle, {} /* options */);
-#endif
-
-    fsync(fd);
 }
 
 static void periodic_chores() {
@@ -368,21 +260,10 @@
         return -1;
     }
 
-#ifndef HEALTHD_USE_HEALTH_2_0
-    healthd_board_init(&healthd_config);
-#else
-    // healthd_board_* functions are removed in health@2.0
-#endif
-
     healthd_mode_ops->init(&healthd_config);
     wakealarm_init();
     uevent_init();
 
-#ifndef HEALTHD_USE_HEALTH_2_0
-    gBatteryMonitor = new BatteryMonitor();
-    gBatteryMonitor->init(&healthd_config);
-#endif
-
     return 0;
 }
 
diff --git a/healthd/include/healthd/healthd.h b/healthd/include/healthd/healthd.h
index 97c7a8c..c01e8d7 100644
--- a/healthd/include/healthd/healthd.h
+++ b/healthd/include/healthd/healthd.h
@@ -81,15 +81,6 @@
 // Global helper functions
 
 int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup = EVENT_NO_WAKEUP_FD);
-void healthd_battery_update();
-
-// deprecated.
-// TODO(b/62229583): This function should be removed since it is only used by
-// BatteryPropertiesRegistrar.
-android::status_t healthd_get_property(int id,
-    struct android::BatteryProperty *val);
-
-void healthd_dump_battery_state(int fd);
 
 struct healthd_mode_ops {
     void (*init)(struct healthd_config *config);