OSDN Git Service

health: add health HAL and it's default implementation.
authorSandeep Patil <sspatil@google.com>
Wed, 9 Nov 2016 00:35:04 +0000 (16:35 -0800)
committerSandeep Patil <sspatil@google.com>
Fri, 11 Nov 2016 17:28:23 +0000 (09:28 -0800)
The default Health HAL implementation continues to depend on
libhealthd.<target> BOARD_HAL_STATIC_LIBRARY in order to make
sure healthd continues to work.

New device specific Health HAL implentations don't need to
compile with healthd STATIC_HAL.

Test: Tested healthd with and without the static hal implementation
on Angler.

BUG: b/32724915

Change-Id: I25d439f24a4178666614faf196423ffc8ccafafb
Signed-off-by: Sandeep Patil <sspatil@google.com>
12 files changed:
health/1.0/Android.bp [new file with mode: 0644]
health/1.0/Android.mk [new file with mode: 0644]
health/1.0/IHealth.hal [new file with mode: 0644]
health/1.0/default/Android.mk [new file with mode: 0644]
health/1.0/default/Health.cpp [new file with mode: 0644]
health/1.0/default/Health.h [new file with mode: 0644]
health/1.0/default/convert.cpp [new file with mode: 0644]
health/1.0/default/include/hal_conversion.h [new file with mode: 0644]
health/1.0/default/libhealthd/Android.mk [new file with mode: 0644]
health/1.0/default/libhealthd/healthd_board_default.cpp [new file with mode: 0644]
health/1.0/types.hal [new file with mode: 0644]
health/Android.bp [new file with mode: 0644]

diff --git a/health/1.0/Android.bp b/health/1.0/Android.bp
new file mode 100644 (file)
index 0000000..fb3d8c0
--- /dev/null
@@ -0,0 +1,51 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+    name: "android.hardware.health@1.0_genc++",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.health@1.0",
+    srcs: [
+        "types.hal",
+        "IHealth.hal",
+    ],
+    out: [
+        "android/hardware/health/1.0/types.cpp",
+        "android/hardware/health/1.0/HealthAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hardware.health@1.0_genc++_headers",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.health@1.0",
+    srcs: [
+        "types.hal",
+        "IHealth.hal",
+    ],
+    out: [
+        "android/hardware/health/1.0/types.h",
+        "android/hardware/health/1.0/IHealth.h",
+        "android/hardware/health/1.0/IHwHealth.h",
+        "android/hardware/health/1.0/BnHealth.h",
+        "android/hardware/health/1.0/BpHealth.h",
+        "android/hardware/health/1.0/BsHealth.h",
+    ],
+}
+
+cc_library_shared {
+    name: "android.hardware.health@1.0",
+    generated_sources: ["android.hardware.health@1.0_genc++"],
+    generated_headers: ["android.hardware.health@1.0_genc++_headers"],
+    export_generated_headers: ["android.hardware.health@1.0_genc++_headers"],
+    shared_libs: [
+        "libhidl",
+        "libhwbinder",
+        "libutils",
+        "libcutils",
+    ],
+    export_shared_lib_headers: [
+        "libhidl",
+        "libhwbinder",
+        "libutils",
+    ],
+}
diff --git a/health/1.0/Android.mk b/health/1.0/Android.mk
new file mode 100644 (file)
index 0000000..776a2c2
--- /dev/null
@@ -0,0 +1,270 @@
+# This file is autogenerated by hidl-gen. Do not edit manually.
+
+LOCAL_PATH := $(call my-dir)
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.health@1.0-java
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(local-generated-sources-dir)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+#
+# Build types.hal (BatteryHealth)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/BatteryHealth.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.BatteryHealth
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (BatteryStatus)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/BatteryStatus.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.BatteryStatus
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (HealthConfig)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/HealthConfig.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.HealthConfig
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (HealthInfo)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/HealthInfo.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.HealthInfo
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (Result)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/Result.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.Result
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IHealth.hal
+#
+GEN := $(intermediates)/android/hardware/health/1.0/IHealth.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IHealth.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::IHealth
+
+$(GEN): $(LOCAL_PATH)/IHealth.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_JAVA_LIBRARY)
+
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.health@1.0-java-static
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(local-generated-sources-dir)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+#
+# Build types.hal (BatteryHealth)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/BatteryHealth.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.BatteryHealth
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (BatteryStatus)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/BatteryStatus.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.BatteryStatus
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (HealthConfig)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/HealthConfig.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.HealthConfig
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (HealthInfo)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/HealthInfo.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.HealthInfo
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build types.hal (Result)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/Result.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::types.Result
+
+$(GEN): $(LOCAL_PATH)/types.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IHealth.hal
+#
+GEN := $(intermediates)/android/hardware/health/1.0/IHealth.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IHealth.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0::IHealth
+
+$(GEN): $(LOCAL_PATH)/IHealth.hal
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.health@1.0-java-constants
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(local-generated-sources-dir)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+#
+GEN := $(intermediates)/android/hardware/health/1.0/Constants.java
+$(GEN): $(HIDL)
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/IHealth.hal
+
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava-constants -randroid.hardware:hardware/interfaces \
+        android.hardware.health@1.0
+
+$(GEN):
+       $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+# Avoid dependency cycle of framework.jar -> this-library -> framework.jar
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := core-oj
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/health/1.0/IHealth.hal b/health/1.0/IHealth.hal
new file mode 100644 (file)
index 0000000..3828589
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.health@1.0;
+
+interface IHealth {
+    /**
+     * This function lets you change healthd configuration from default if
+     * desired. It must be called exactly once at startup time.
+     *
+     * The configuration values are described in 'struct HealthConfig'.
+     * To use default configuration, simply return without modifying the
+     * fields of the config parameter.
+     *
+     * @param default healthd configuration.
+     */
+    init(HealthConfig config) generates (HealthConfig configOut);
+
+    /**
+     * This function is a hook to update/change device's HealthInfo (as described
+     * in 'struct HealthInfo').
+     *
+     * 'HealthInfo' describes device's battery and charging status, typically
+     * read from kernel. These values may be modified in this call.
+     *
+     * @param   Device Health info as described in 'struct HealthInfo'.
+     * @return  skipLogging Indication to the caller to add 'or' skip logging the health
+     *          information. Return 'true' to skip logging the update.
+     * @return  infoOut HealthInfo to be sent to client code. (May or may
+     *          not be modified).
+     */
+    update(HealthInfo info) generates (bool skipLogging, HealthInfo infoOut);
+
+    /**
+     * This function is called by healthd when framework queries for remaining
+     * energy in the Battery through BatteryManager APIs.
+     *
+     * @return  result Result of querying enery counter for the battery.
+     * @return  energy Battery remaining energy in nanowatt-hours.
+     *          Must be '0' if result is anything other than Result::SUCCESS.
+     */
+    energyCounter() generates (Result result, int64_t energy);
+};
diff --git a/health/1.0/default/Android.mk b/health/1.0/default/Android.mk
new file mode 100644 (file)
index 0000000..324912e
--- /dev/null
@@ -0,0 +1,37 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.health@1.0-impl
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_C_INCLUDES := system/core/healthd/include system/core/base/include
+LOCAL_SRC_FILES := \
+    Health.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+    libcutils \
+    libhidl \
+    libhwbinder \
+    liblog \
+    libutils \
+    android.hardware.health@1.0 \
+
+LOCAL_STATIC_LIBRARIES := android.hardware.health@1.0-convert
+
+LOCAL_HAL_STATIC_LIBRARIES := libhealthd
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.health@1.0-convert
+LOCAL_SRC_FILES := convert.cpp
+LOCAL_C_INCLUDES := system/core/healthd/include system/core/base/include
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_SHARED_LIBRARIES := \
+    libcutils \
+    libhidl \
+    libutils \
+    android.hardware.health@1.0 \
+
+include $(BUILD_STATIC_LIBRARY)
+
+include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/health/1.0/default/Health.cpp b/health/1.0/default/Health.cpp
new file mode 100644 (file)
index 0000000..1a02956
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "health-hal"
+
+#include <Health.h>
+#include <include/hal_conversion.h>
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::health::V1_0::hal_conversion::convertToHealthConfig;
+using ::android::hardware::health::V1_0::hal_conversion::convertFromHealthConfig;
+using ::android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
+using ::android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo;
+
+// Methods from ::android::hardware::health::V1_0::IHealth follow.
+Return<void> Health::init(const HealthConfig& config, init_cb _hidl_cb)  {
+    struct healthd_config healthd_config = {};
+    HealthConfig configOut;
+
+    // To keep working with existing healthd static HALs,
+    // convert the new HealthConfig to the old healthd_config
+    // and back.
+
+    convertFromHealthConfig(config, &healthd_config);
+    healthd_board_init(&healthd_config);
+    mGetEnergyCounter = healthd_config.energyCounter;
+    convertToHealthConfig(&healthd_config, configOut);
+
+    _hidl_cb(configOut);
+
+    return Void();
+}
+
+Return<void> Health::update(const HealthInfo& info, update_cb _hidl_cb)  {
+    struct android::BatteryProperties p = {};
+    HealthInfo infoOut;
+
+    // To keep working with existing healthd static HALs,
+    // convert the new HealthInfo to android::Batteryproperties
+    // and back.
+
+    convertFromHealthInfo(info, &p);
+    int skipLogging = healthd_board_battery_update(&p);
+    convertToHealthInfo(&p, infoOut);
+
+    _hidl_cb(!!skipLogging, infoOut);
+
+    return Void();
+}
+
+Return<void> Health::energyCounter(energyCounter_cb _hidl_cb) {
+    int64_t energy = 0;
+    Result result = Result::NOT_SUPPORTED;
+
+    if (mGetEnergyCounter) {
+        int status = mGetEnergyCounter(&energy);
+        if (status == 0) {
+            result = Result::SUCCESS;
+        }
+    }
+
+    _hidl_cb(result, energy);
+
+   return Void();
+}
+
+IHealth* HIDL_FETCH_IHealth(const char* /* name */) {
+    return new Health();
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace health
+}  // namespace hardware
+}  // namespace android
diff --git a/health/1.0/default/Health.h b/health/1.0/default/Health.h
new file mode 100644 (file)
index 0000000..c05751f
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef HIDL_GENERATED_android_hardware_health_V1_0_Health_H_
+#define HIDL_GENERATED_android_hardware_health_V1_0_Health_H_
+
+#include <android/hardware/health/1.0/IHealth.h>
+#include <hidl/Status.h>
+#include <hidl/MQDescriptor.h>
+#include <healthd/healthd.h>
+#include <utils/String8.h>
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::health::V1_0::HealthInfo;
+using ::android::hardware::health::V1_0::HealthConfig;
+using ::android::hardware::health::V1_0::IHealth;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Health : public IHealth {
+    // Methods from ::android::hardware::health::V1_0::IHealth follow.
+    Return<void> init(const HealthConfig& config, init_cb _hidl_cb)  override;
+    Return<void> update(const HealthInfo& info, update_cb _hidl_cb)  override;
+    Return<void> energyCounter(energyCounter_cb _hidl_cb) override;
+private:
+    std::function<int(int64_t *)> mGetEnergyCounter;
+};
+
+extern "C" IHealth* HIDL_FETCH_IHealth(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace health
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_health_V1_0_Health_H_
diff --git a/health/1.0/default/convert.cpp b/health/1.0/default/convert.cpp
new file mode 100644 (file)
index 0000000..7f1e3c4
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/hal_conversion.h"
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V1_0 {
+namespace hal_conversion {
+
+void convertToHealthConfig(const struct healthd_config *hc, HealthConfig& config) {
+    config.periodicChoresIntervalFast = hc->periodic_chores_interval_fast;
+    config.periodicChoresIntervalSlow = hc->periodic_chores_interval_slow;
+
+    config.batteryStatusPath        = hc->batteryStatusPath.string();
+    config.batteryHealthPath        = hc->batteryHealthPath.string();
+    config.batteryPresentPath       = hc->batteryPresentPath.string();
+    config.batteryCapacityPath      = hc->batteryCapacityPath.string();
+    config.batteryVoltagePath       = hc->batteryVoltagePath.string();
+    config.batteryTemperaturePath   = hc->batteryTemperaturePath.string();
+    config.batteryTechnologyPath    = hc->batteryTechnologyPath.string();
+    config.batteryCurrentNowPath    = hc->batteryCurrentNowPath.string();
+    config.batteryCurrentAvgPath    = hc->batteryCurrentAvgPath.string();
+    config.batteryChargeCounterPath = hc->batteryChargeCounterPath.string();
+    config.batteryFullChargePath    = hc->batteryFullChargePath.string();
+    config.batteryCycleCountPath    = hc->batteryCycleCountPath.string();
+
+}
+
+void convertFromHealthConfig(const HealthConfig& c, struct healthd_config *hc) {
+    hc->periodic_chores_interval_fast = c.periodicChoresIntervalFast;
+    hc->periodic_chores_interval_slow = c.periodicChoresIntervalSlow;
+
+    hc->batteryStatusPath =
+        android::String8(c.batteryStatusPath.c_str(),
+                         c.batteryStatusPath.size());
+
+    hc->batteryHealthPath =
+        android::String8(c.batteryHealthPath.c_str(),
+                         c.batteryHealthPath.size());
+
+    hc->batteryPresentPath =
+        android::String8(c.batteryPresentPath.c_str(),
+                         c.batteryPresentPath.size());
+
+    hc->batteryCapacityPath =
+        android::String8(c.batteryCapacityPath.c_str(),
+                         c.batteryCapacityPath.size());
+
+    hc->batteryVoltagePath =
+        android::String8(c.batteryVoltagePath.c_str(),
+                         c.batteryVoltagePath.size());
+
+    hc->batteryTemperaturePath =
+        android::String8(c.batteryTemperaturePath.c_str(),
+                         c.batteryTemperaturePath.size());
+
+    hc->batteryTechnologyPath =
+        android::String8(c.batteryTechnologyPath.c_str(),
+                         c.batteryTechnologyPath.size());
+
+    hc->batteryCurrentNowPath =
+        android::String8(c.batteryCurrentNowPath.c_str(),
+                         c.batteryCurrentNowPath.size());
+
+    hc->batteryCurrentAvgPath =
+        android::String8(c.batteryCurrentAvgPath.c_str(),
+                         c.batteryCurrentNowPath.size());
+
+    hc->batteryChargeCounterPath =
+        android::String8(c.batteryChargeCounterPath.c_str(),
+                         c.batteryChargeCounterPath.size());
+
+    hc->batteryFullChargePath =
+        android::String8(c.batteryFullChargePath.c_str(),
+                         c.batteryFullChargePath.size());
+
+    hc->batteryCycleCountPath =
+        android::String8(c.batteryCycleCountPath.c_str(),
+                         c.batteryCycleCountPath.size());
+
+    // energyCounter is handled through special means so all calls to
+    // the function go across the HALs
+
+    // boot_min_cap - never used in Android (only in charger-mode).
+
+    // screen_on - never used in Android (only in charger mode).
+}
+
+void convertToHealthInfo(const struct android::BatteryProperties *p,
+                                 HealthInfo& info) {
+    info.chargerAcOnline        = p->chargerAcOnline;
+    info.chargerUsbOnline       = p->chargerUsbOnline;
+    info.chargerWirelessOnline  = p->chargerWirelessOnline;
+    info.maxChargingCurrent     = p->maxChargingCurrent;
+    info.maxChargingVoltage     = p->maxChargingVoltage;
+    info.batteryStatus          = static_cast<BatteryStatus>(p->batteryStatus);
+    info.batteryHealth          = static_cast<BatteryHealth>(p->batteryHealth);
+    info.batteryPresent         = p->batteryPresent;
+    info.batteryLevel           = p->batteryLevel;
+    info.batteryVoltage         = p->batteryVoltage;
+    info.batteryTemperature     = p->batteryTemperature;
+    info.batteryCurrent         = p->batteryCurrent;
+    info.batteryCycleCount      = p->batteryCycleCount;
+    info.batteryFullCharge      = p->batteryFullCharge;
+    info.batteryChargeCounter   = p->batteryChargeCounter;
+    info.batteryTechnology      = p->batteryTechnology;
+}
+
+void convertFromHealthInfo(const HealthInfo& info,
+                                   struct android::BatteryProperties *p) {
+    p->chargerAcOnline          = info.chargerAcOnline;
+    p->chargerUsbOnline         = info.chargerUsbOnline;
+    p->chargerWirelessOnline    = info.chargerWirelessOnline;
+    p->maxChargingCurrent       = info.maxChargingCurrent;
+    p->maxChargingVoltage       = info.maxChargingVoltage;
+    p->batteryStatus            = static_cast<int>(info.batteryStatus);
+    p->batteryHealth            = static_cast<int>(info.batteryHealth);
+    p->batteryPresent           = info.batteryPresent;
+    p->batteryLevel             = info.batteryLevel;
+    p->batteryVoltage           = info.batteryVoltage;
+    p->batteryTemperature       = info.batteryTemperature;
+    p->batteryCurrent           = info.batteryCurrent;
+    p->batteryCycleCount        = info.batteryCycleCount;
+    p->batteryFullCharge        = info.batteryFullCharge;
+    p->batteryChargeCounter     = info.batteryChargeCounter;
+    p->batteryTechnology        = android::String8(info.batteryTechnology.c_str());
+}
+
+} // namespace hal_conversion
+} // namespace V1_0
+} // namespace health
+} // namespace hardware
+} // namespace android
diff --git a/health/1.0/default/include/hal_conversion.h b/health/1.0/default/include/hal_conversion.h
new file mode 100644 (file)
index 0000000..a92b208
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_INTERFACES_HEALTH_V1_0_DEFAULT_INCLUDE_HAL_CONVERSION_H_
+#define HARDWARE_INTERFACES_HEALTH_V1_0_DEFAULT_INCLUDE_HAL_CONVERSION_H_
+
+#include <android/hardware/health/1.0/IHealth.h>
+#include <healthd/healthd.h>
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V1_0 {
+namespace hal_conversion {
+
+void convertToHealthConfig(const struct healthd_config *hc,
+                            HealthConfig& config);
+void convertFromHealthConfig(const HealthConfig& c, struct healthd_config *hc);
+
+void convertToHealthInfo(const struct android::BatteryProperties *p,
+                                 HealthInfo& info);
+void convertFromHealthInfo(const HealthInfo& info,
+                                 struct android::BatteryProperties *p);
+
+}  // namespace hal_conversion
+}  // namespace V1_0
+}  // namespace sensors
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HARDWARE_INTERFACES_HEALTH_V1_0_DEFAULT_INCLUDE_HAL_CONVERSION_H_
diff --git a/health/1.0/default/libhealthd/Android.mk b/health/1.0/default/libhealthd/Android.mk
new file mode 100644 (file)
index 0000000..a5f4445
--- /dev/null
@@ -0,0 +1,10 @@
+# Copyright 2016 The Android Open Source Project
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := healthd_board_default.cpp
+LOCAL_MODULE := libhealthd.default
+LOCAL_CFLAGS := -Werror
+LOCAL_C_INCLUDES := system/core/healthd/include system/core/base/include
+include $(BUILD_STATIC_LIBRARY)
diff --git a/health/1.0/default/libhealthd/healthd_board_default.cpp b/health/1.0/default/libhealthd/healthd_board_default.cpp
new file mode 100644 (file)
index 0000000..127f98e
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <healthd/healthd.h>
+
+void healthd_board_init(struct healthd_config*)
+{
+    // use defaults
+}
+
+int healthd_board_battery_update(struct android::BatteryProperties*)
+{
+    // return 0 to log periodic polled battery status to kernel log
+    return 0;
+}
diff --git a/health/1.0/types.hal b/health/1.0/types.hal
new file mode 100644 (file)
index 0000000..c5b5cc1
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.health@1.0;
+
+/*
+ * Possible return values for optional HAL method(s) like
+ * IHealth::energyCounter()
+ */
+enum Result : int32_t {
+    SUCCESS,
+    NOT_SUPPORTED,
+    UNKNOWN,
+};
+
+/*
+ * Possible values for Battery Status.
+ * Note: These are currently in sync with BatteryManager and must not
+ * be extended / altered.
+ */
+@export(name="", value_prefix="BATTERY_STATUS_")
+enum BatteryStatus : int32_t {
+    UNKNOWN = 1,
+    CHARGING = 2,
+    DISCHARGING = 3,
+    /*
+     * Battery is *not* charging - special case when charger is present
+     * but battery isn't charging
+     */
+    NOT_CHARGING = 4,
+    FULL = 5,
+};
+
+/*
+ * Possible values for Battery Health.
+ * Note: These are currently in sync with BatteryManager and must not
+ * be extended / altered.
+ */
+@export(name="", value_prefix="BATTERY_HEALTH_")
+enum BatteryHealth : int32_t {
+    UNKNOWN = 1,
+    GOOD = 2,
+    OVERHEAT = 3,
+    DEAD = 4,
+    OVER_VOLTAGE = 5,
+    /*
+     * Battery experienced an unknown/unspecifid failure.
+     */
+    UNSPECIFIED_FAILURE = 6,
+    COLD = 7,
+};
+
+struct HealthConfig {
+
+    /*
+     * periodicChoresIntervalFast is used while the device is not in
+     * suspend, or in suspend and connected to a charger (to watch for battery
+     * overheat due to charging)
+     */
+    int32_t periodicChoresIntervalFast;
+
+    /*
+     * periodicChoresIntervalSlow is used when the device is in suspend and
+     * not connected to a charger (to watch for a battery drained to zero
+     * remaining capacity).
+     */
+    int32_t periodicChoresIntervalSlow;
+
+    /*
+     * power_supply sysfs attribute file paths. Set these to specific paths
+     * to use for the associated battery parameters. Clients must search
+     * for appropriate power_supply attribute files to use, for any paths
+     * left empty after the HAL is initialized.
+     */
+
+    /*
+     * batteryStatusPath - file path to read battery charging status.
+     * (POWER_SUPPLY_PROP_STATUS)
+     */
+    string batteryStatusPath;
+
+
+    /*
+     * batteryHealthPath - file path to read battery health.
+     * (POWER_SUPPLY_PROP_HEALTH)
+     */
+    string batteryHealthPath;
+
+    /*
+     * batteryPresentPath - file path to read battery present status.
+     * (POWER_SUPPLY_PROP_PRESENT)
+     */
+    string batteryPresentPath;
+
+
+    /*
+     * batteryCapacityPath - file path to read remaining battery capacity.
+     * (POWER_SUPPLY_PROP_CAPACITY)
+     */
+    string batteryCapacityPath;
+
+    /*
+     * batteryVoltagePath - file path to read battery voltage.
+     * (POWER_SUPPLY_PROP_VOLTAGE_NOW)
+     */
+    string batteryVoltagePath;
+
+    /*
+     * batteryTemperaturePath - file path to read battery temperature in tenths
+     * of degree celcius. (POWER_SUPPLY_PROP_TEMP)
+     */
+    string batteryTemperaturePath;
+
+    /*
+     * batteryTechnologyPath - file path to read battery technology.
+     * (POWER_SUPPLY_PROP_TECHNOLOGY)
+     */
+    string batteryTechnologyPath;
+
+    /*
+     * batteryCurrentNowPath - file path to read battery instantaneous current.
+     * (POWER_SUPPLY_PROP_CURRENT_NOW)
+     */
+    string batteryCurrentNowPath;
+
+    /*
+     * batteryCurrentAvgPath - file path to read battery average current.
+     * (POWER_SUPPLY_PROP_CURRENT_AVG)
+     */
+    string batteryCurrentAvgPath;
+
+    /*
+     * batteryChargeCounterPath - file path to read battery accumulated charge.
+     * (POWER_SUPPLY_PROP_CHARGE_COUNTER)
+     */
+    string batteryChargeCounterPath;
+
+    /*
+     * batteryFullChargerPath - file path to read battery charge value when it
+     * is considered to be full. (POWER_SUPPLY_PROP_CHARGE_FULL)
+     */
+    string batteryFullChargePath;
+
+    /*
+     * batteryCycleCountPath - file path to read battery charge cycle count.
+     * (POWER_SUPPLY_PROP_CYCLE_COUNT)
+     */
+    string batteryCycleCountPath;
+};
+
+/*
+ * The parameter to healthd mainloop update calls
+ */
+struct HealthInfo {
+    /* AC charger state - 'true' if online */
+    bool chargerAcOnline;
+
+    /* USB charger state - 'true' if online */
+    bool chargerUsbOnline;
+
+    /* Wireless charger state - 'true' if online */
+    bool chargerWirelessOnline;
+
+    /* Maximum charging current supported by charger in uA */
+    int32_t maxChargingCurrent;
+
+    /* Maximum charging voltage supported by charger in uV */
+    int32_t maxChargingVoltage;
+
+    BatteryStatus batteryStatus;
+
+    BatteryHealth batteryHealth;
+
+    /* 'true' if battery is present */
+    bool batteryPresent;
+
+    /* Remaining battery capacity in percent */
+    int32_t batteryLevel;
+
+    /* Instantaneous battery voltage in uV */
+    int32_t batteryVoltage;
+
+    /* Instantaneous battery temperature in tenths of degree celcius */
+    int32_t batteryTemperature;
+
+    /* Instantaneous battery current in uA */
+    int32_t batteryCurrent;
+
+    /* Battery charge cycle count */
+    int32_t batteryCycleCount;
+
+    /* Battery charge value when it is considered to be "full" in uA-h */
+    int32_t batteryFullCharge;
+
+    /* Instantaneous battery capacity in uA-h */
+    int32_t batteryChargeCounter;
+
+    /* Battery technology, e.g. "Li-ion, Li-Poly" etc. */
+    string batteryTechnology;
+};
diff --git a/health/Android.bp b/health/Android.bp
new file mode 100644 (file)
index 0000000..bbb3e4b
--- /dev/null
@@ -0,0 +1,4 @@
+// This is an autogenerated file, do not edit.
+subdirs = [
+    "1.0",
+]