summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 345bac0)
raw | patch | inline | side by side (parent: 345bac0)
author | Yifan Hong <elsk@google.com> | |
Tue, 10 Jul 2018 22:49:21 +0000 (15:49 -0700) | ||
committer | Yifan Hong <elsk@google.com> | |
Wed, 18 Jul 2018 23:04:39 +0000 (16:04 -0700) |
health/2.0/README | patch | blob | history | |
health/2.0/default/Android.bp | patch | blob | history | |
health/2.0/default/HealthImplDefault.cpp | [new file with mode: 0644] | patch | blob |
diff --git a/health/2.0/README b/health/2.0/README
index 9f77b8372ff64cd7889b80577bc218b3d6e4b1a4..44e2828f0ded7d720402a239e28923f435b8ca26 100644 (file)
--- a/health/2.0/README
+++ b/health/2.0/README
# 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>
index 6301a06e3f8aee08fae51d6459404ca0a022013c..a85a70459bfedb61cfb6971a1c7766108538e9c7 100644 (file)
-// 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",
"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
--- /dev/null
@@ -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;
+}