summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2018-07-10 15:49:21 -0700
committerYifan Hong <elsk@google.com>2018-07-18 16:04:39 -0700
commit4db762a4d97ddb8d4347161fb0970d0cd27f5e67 (patch)
treed728217ca6da452bd69606b8ece7271827c69f4d /health
parent345bac071eb1a08429665aa27654bf48bf998dd8 (diff)
downloadandroid_hardware_interfaces-4db762a4d97ddb8d4347161fb0970d0cd27f5e67.tar.gz
android_hardware_interfaces-4db762a4d97ddb8d4347161fb0970d0cd27f5e67.tar.bz2
android_hardware_interfaces-4db762a4d97ddb8d4347161fb0970d0cd27f5e67.zip
healthd: add android.hardware.health@2.0-impl-default.recovery
Test: build recovery Bug: 80132328 Change-Id: I253bd1a756f3b94f6470da12bfc4488313a16aa4
Diffstat (limited to 'health')
-rw-r--r--health/2.0/README46
-rw-r--r--health/2.0/default/Android.bp52
-rw-r--r--health/2.0/default/HealthImplDefault.cpp58
3 files changed, 146 insertions, 10 deletions
diff --git a/health/2.0/README b/health/2.0/README
index 9f77b8372..44e2828f0 100644
--- a/health/2.0/README
+++ b/health/2.0/README
@@ -107,3 +107,49 @@ void get_disk_stats(std::vector<struct DiskStats>& stats) {
# device/<manufacturer>/<device>/sepolicy/vendor/hal_health_default.te
# Add device specific permissions to hal_health_default domain, especially
# if Step 6.1 or Step 7.2 is done.
+
+9. Implementing health HAL in recovery. The health HAL is used for battery
+status checks during OTA for non-A/B devices. If the health HAL is not
+implemented in recovery, is_battery_ok() will always return true.
+
+9.1 If the device does not have a vendor-specific libhealthd, nothing needs to
+be done. A "backup" implementation is provided in
+android.hardware.health@2.0-impl-default, which is always installed to recovery
+image by default.
+
+9.2 If the device do have a vendor-specific libhealthd, implement the following
+module and include it in PRODUCT_PACKAGES (replace <device> with appropriate
+strings):
+
+// Android.bp
+cc_library_shared {
+ name: "android.hardware.health@2.0-impl-<device>",
+ recovery_available: true,
+ relative_install_path: "hw",
+ static_libs: [
+ "android.hardware.health@2.0-impl",
+ "libhealthd.<device>"
+ // Include the following if Step 7.1, otherwise do Step 7.2
+ "libhealthstoragedefault",
+ ],
+ srcs: [
+ "HealthImpl.cpp",
+ ],
+ overrides: [
+ "android.hardware.health@2.0-impl-default",
+ ],
+}
+
+// HealthImpl.cpp
+#include <health2/Health.h>
+#include <healthd/healthd.h>
+using android::hardware::health::V2_0::IHealth;
+using android::hardware::health::V2_0::implementation::Health;
+extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) {
+ const static std::string providedInstance{"default"};
+ if (providedInstance != name) return nullptr;
+ return Health::initInstance(&gHealthdConfig).get();
+}
+
+# device.mk
+PRODUCT_PACKAGES += android.hardware.health@2.0-impl-<device>
diff --git a/health/2.0/default/Android.bp b/health/2.0/default/Android.bp
index 6301a06e3..a85a70459 100644
--- a/health/2.0/default/Android.bp
+++ b/health/2.0/default/Android.bp
@@ -1,16 +1,12 @@
-// Helper library for implementing health HAL. It is recommended that a health
-// service or passthrough HAL link to this library.
-cc_library_static {
- name: "android.hardware.health@2.0-impl",
- vendor_available: true,
+cc_defaults {
+ name: "android.hardware.health@2.0-impl_defaults",
+
recovery_available: true,
- srcs: [
- "Health.cpp",
- "healthd_common.cpp",
+ cflags: [
+ "-Wall",
+ "-Werror",
],
- export_include_dirs: ["include"],
-
shared_libs: [
"libbase",
"libhidlbase",
@@ -27,3 +23,39 @@ cc_library_static {
"android.hardware.health@1.0-convert",
],
}
+
+// Helper library for implementing health HAL. It is recommended that a health
+// service or passthrough HAL link to this library.
+cc_library_static {
+ name: "android.hardware.health@2.0-impl",
+ defaults: ["android.hardware.health@2.0-impl_defaults"],
+
+ vendor_available: true,
+ srcs: [
+ "Health.cpp",
+ "healthd_common.cpp",
+ ],
+
+ export_include_dirs: ["include"],
+}
+
+// Default passthrough implementation for recovery. Vendors can implement
+// android.hardware.health@2.0-impl-recovery-<device> to customize the behavior
+// of the HAL in recovery.
+// The implementation does NOT start the uevent loop for polling.
+cc_library_shared {
+ name: "android.hardware.health@2.0-impl-default",
+ defaults: ["android.hardware.health@2.0-impl_defaults"],
+
+ recovery_available: true,
+ relative_install_path: "hw",
+
+ static_libs: [
+ "android.hardware.health@2.0-impl",
+ "libhealthstoragedefault",
+ ],
+
+ srcs: [
+ "HealthImplDefault.cpp",
+ ],
+}
diff --git a/health/2.0/default/HealthImplDefault.cpp b/health/2.0/default/HealthImplDefault.cpp
new file mode 100644
index 000000000..15346bf6e
--- /dev/null
+++ b/health/2.0/default/HealthImplDefault.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 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 <health2/Health.h>
+#include <healthd/healthd.h>
+
+using android::hardware::health::V2_0::IHealth;
+using android::hardware::health::V2_0::implementation::Health;
+
+static struct healthd_config gHealthdConfig = {
+ .batteryStatusPath = android::String8(android::String8::kEmptyString),
+ .batteryHealthPath = android::String8(android::String8::kEmptyString),
+ .batteryPresentPath = android::String8(android::String8::kEmptyString),
+ .batteryCapacityPath = android::String8(android::String8::kEmptyString),
+ .batteryVoltagePath = android::String8(android::String8::kEmptyString),
+ .batteryTemperaturePath = android::String8(android::String8::kEmptyString),
+ .batteryTechnologyPath = android::String8(android::String8::kEmptyString),
+ .batteryCurrentNowPath = android::String8(android::String8::kEmptyString),
+ .batteryCurrentAvgPath = android::String8(android::String8::kEmptyString),
+ .batteryChargeCounterPath = android::String8(android::String8::kEmptyString),
+ .batteryFullChargePath = android::String8(android::String8::kEmptyString),
+ .batteryCycleCountPath = android::String8(android::String8::kEmptyString),
+ .energyCounter = nullptr,
+ .boot_min_cap = 0,
+ .screen_on = nullptr};
+
+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;
+}
+
+extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) {
+ const static std::string providedInstance{"backup"};
+
+ if (providedInstance == name) {
+ // use defaults
+ // Health class stores static instance
+ return Health::initInstance(&gHealthdConfig).get();
+ }
+ return nullptr;
+}