mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:23:37 +00:00
healthd: add android.hardware.health@2.0-impl-default.recovery
Test: build recovery Bug: 80132328 Change-Id: I253bd1a756f3b94f6470da12bfc4488313a16aa4
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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-<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",
|
||||
],
|
||||
}
|
||||
|
||||
58
health/2.0/default/HealthImplDefault.cpp
Normal file
58
health/2.0/default/HealthImplDefault.cpp
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user