From 4db762a4d97ddb8d4347161fb0970d0cd27f5e67 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 10 Jul 2018 15:49:21 -0700 Subject: [PATCH] healthd: add android.hardware.health@2.0-impl-default.recovery Test: build recovery Bug: 80132328 Change-Id: I253bd1a756f3b94f6470da12bfc4488313a16aa4 --- health/2.0/README | 46 +++++++++++++++++++ health/2.0/default/Android.bp | 54 +++++++++++++++++----- health/2.0/default/HealthImplDefault.cpp | 58 ++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 health/2.0/default/HealthImplDefault.cpp diff --git a/health/2.0/README b/health/2.0/README index 9f77b8372f..44e2828f0d 100644 --- a/health/2.0/README +++ b/health/2.0/README @@ -107,3 +107,49 @@ void get_disk_stats(std::vector& stats) { # 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 with appropriate +strings): + +// Android.bp +cc_library_shared { + name: "android.hardware.health@2.0-impl-", + recovery_available: true, + relative_install_path: "hw", + static_libs: [ + "android.hardware.health@2.0-impl", + "libhealthd." + // 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 +#include +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- diff --git a/health/2.0/default/Android.bp b/health/2.0/default/Android.bp index 6301a06e3f..a85a70459b 100644 --- a/health/2.0/default/Android.bp +++ b/health/2.0/default/Android.bp @@ -1,15 +1,11 @@ -// 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, - recovery_available: true, - srcs: [ - "Health.cpp", - "healthd_common.cpp", - ], +cc_defaults { + name: "android.hardware.health@2.0-impl_defaults", - export_include_dirs: ["include"], + recovery_available: true, + cflags: [ + "-Wall", + "-Werror", + ], shared_libs: [ "libbase", @@ -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- 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 0000000000..15346bf6e9 --- /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 +#include + +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; +}