health: Introduce batteryless aidl HAL

Change-Id: I9877cb3cd4a6b55a59249aeae58060e616d2cd28
This commit is contained in:
Aaron Kling 2024-05-12 20:58:26 -05:00 committed by Bruno Martins
parent 0b534a8050
commit 7cbd562024
5 changed files with 129 additions and 1 deletions

View file

@ -1,9 +1,58 @@
/*
* Copyright (C) 2022-2023 The LineageOS Project
* Copyright (C) 2022-2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
cc_defaults {
name: "android.hardware.health-service.batteryless-defaults",
relative_install_path: "hw",
vintf_fragments: ["android.hardware.health-service.batteryless.xml"],
vendor: true,
recovery_available: true,
defaults: [
"libhealth_aidl_impl_user",
],
include_dirs: [
"system/core/healthd",
"system/core/healthd/include",
"system/core/healthd/include_charger"
],
static_libs: [
"libhealth_aidl_impl",
],
srcs: [
"service-batteryless.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
}
cc_binary {
name: "android.hardware.health-service.batteryless",
recovery: false,
vendor: true,
defaults: ["android.hardware.health-service.batteryless-defaults"],
init_rc: ["android.hardware.health-service.batteryless.rc"],
overrides: ["charger"],
}
cc_binary {
name: "android.hardware.health-service.batteryless_recovery",
vendor: false,
recovery: true,
defaults: ["android.hardware.health-service.batteryless-defaults"],
init_rc: ["android.hardware.health-service.batteryless_recovery.rc"],
overrides: ["charger.recovery"],
}
cc_binary {
name: "vendor.lineage.health-service.default",
defaults: ["health_charging_control_defaults"],

View file

@ -0,0 +1,6 @@
service vendor.health-default /vendor/bin/hw/android.hardware.health-service.batteryless
class hal
user system
group system
capabilities WAKE_ALARM BLOCK_SUSPEND
file /dev/kmsg w

View file

@ -0,0 +1,13 @@
<!--
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Copyright (C) 2024 The LineageOS Project
SPDX-License-Identifier: BSD-3-Clause-Clear
-->
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.health</name>
<version>1</version>
<fqname>IHealth/default</fqname>
</hal>
</manifest>

View file

@ -0,0 +1,7 @@
service vendor.health-recovery /system/bin/hw/android.hardware.health-service.batteryless_recovery
class hal
seclabel u:r:hal_health_default:s0
user system
group system
capabilities WAKE_ALARM BLOCK_SUSPEND
file /dev/kmsg w

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Copyright (C) 2024 The LineageOS Project
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#define LOG_TAG "android.hardware.health-service.batteryless"
#include <android-base/logging.h>
#include <android/binder_interface_utils.h>
#include <cutils/klog.h>
#include <health-impl/ChargerUtils.h>
#include <health-impl/Health.h>
#include <health/utils.h>
using aidl::android::hardware::health::BatteryHealth;
using aidl::android::hardware::health::BatteryStatus;
using aidl::android::hardware::health::HalHealthLoop;
using aidl::android::hardware::health::Health;
namespace aidl::android::hardware::health {
class HealthImpl : public Health {
public:
HealthImpl(std::string_view instance_name, std::unique_ptr<struct healthd_config>&& config)
: Health(instance_name, std::move(config)) {}
protected:
void UpdateHealthInfo(HealthInfo* health_info) override {
health_info->chargerAcOnline = true;
health_info->chargerUsbOnline = false;
health_info->chargerWirelessOnline = false;
health_info->chargerDockOnline = false;
health_info->batteryStatus = BatteryStatus::UNKNOWN;
health_info->batteryHealth = BatteryHealth::UNKNOWN;
health_info->batteryPresent = false;
health_info->batteryLevel = 100;
}
};
} // namespace aidl::android::hardware::health
int main() {
#ifdef __ANDROID_RECOVERY__
android::base::InitLogging(NULL, android::base::KernelLogger);
#endif
auto config = std::make_unique<healthd_config>();
::android::hardware::health::InitHealthdConfig(config.get());
auto binder = ndk::SharedRefBase::make<aidl::android::hardware::health::HealthImpl>(
"default", std::move(config));
KLOG_INFO(LOG_TAG, "Starting health HAL.");
auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
return hal_health_loop->StartLoop();
}