health: convert to aidl hal

* hardware/interfaces/health/aidl/default
This commit is contained in:
Konsta
2023-07-28 22:09:01 +03:00
parent cc4df73839
commit b11baea4dd
11 changed files with 137 additions and 54 deletions

View File

@@ -186,7 +186,7 @@ PRODUCT_COPY_FILES += \
# Health # Health
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
android.hardware.health@2.0-service.rpi android.hardware.health-service.rpi
# Kernel # Kernel
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \

View File

@@ -1,33 +1,32 @@
// Copyright (C) 2021-2022 KonstaKANG // Copyright (C) 2018 The Android Open Source Project
// Copyright (C) 2023 KonstaKANG
// //
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
cc_binary { cc_binary {
name: "android.hardware.health@2.0-service.rpi", name: "android.hardware.health-service.rpi",
init_rc: ["android.hardware.health@2.0-service.rpi.rc"],
vintf_fragments: ["android.hardware.health@2.0-service.rpi.xml"],
proprietary: true,
relative_install_path: "hw", relative_install_path: "hw",
vendor: true,
init_rc: ["android.hardware.health-service.rpi.rc"],
vintf_fragments: ["android.hardware.health-service.rpi.xml"],
srcs: [ srcs: [
"HealthService.cpp", "HealthImpl.cpp",
], "main.cpp",
cflags: [
"-Wall",
"-Werror",
], ],
static_libs: [ static_libs: [
"android.hardware.health@2.0-impl", "android.hardware.health-translate-ndk",
"android.hardware.health@1.0-convert",
"libhealthservice",
"libbatterymonitor", "libbatterymonitor",
"libhealthstoragedefault", "libhealthloop",
"libhealth_aidl_impl",
], ],
shared_libs: [ shared_libs: [
"libbase", "libbase",
"libbinder_ndk",
"libcutils", "libcutils",
"libhidlbase", "libhidlbase",
"liblog",
"libutils", "libutils",
"android.hardware.health@2.0", "android.hardware.health-V1-ndk",
], ],
header_libs: ["libhealthd_headers"], overrides: ["charger"],
} }

38
health/HealthImpl.cpp Normal file
View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2023 KonstaKANG
*
* 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 "HealthImpl.h"
using ::aidl::android::hardware::health::BatteryHealth;
using ::aidl::android::hardware::health::BatteryStatus;
using ::aidl::android::hardware::health::HealthInfo;
namespace aidl::android::hardware::health {
void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
health_info->chargerAcOnline = true;
health_info->batteryLevel = 100;
health_info->batteryStatus = BatteryStatus::CHARGING;
health_info->batteryHealth = BatteryHealth::GOOD;
}
ndk::ScopedAStatus HealthImpl::getChargeStatus(BatteryStatus* out) {
*out = BatteryStatus::CHARGING;
return ndk::ScopedAStatus::ok();
}
} // namespace aidl::android::hardware::health

37
health/HealthImpl.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2023 KonstaKANG
*
* 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.
*/
#pragma once
#include <health-impl/Health.h>
using ::aidl::android::hardware::health::Health;
namespace aidl::android::hardware::health {
class HealthImpl : public Health {
public:
using Health::Health;
virtual ~HealthImpl() {}
ndk::ScopedAStatus getChargeStatus(BatteryStatus* out) override;
protected:
void UpdateHealthInfo(HealthInfo* health_info) override;
};
} // namespace aidl::android::hardware::health

View File

@@ -1,20 +0,0 @@
/*
* Copyright (C) 2021-2022 KonstaKANG
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <health2/service.h>
#include <healthd/healthd.h>
int main() {
return health_service_main();
}
void healthd_board_init(struct healthd_config*) {}
int healthd_board_battery_update(struct android::BatteryProperties* battery_props) {
battery_props->chargerAcOnline = true;
battery_props->batteryLevel = 100;
return 0;
}

View File

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

View File

@@ -0,0 +1,7 @@
<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

@@ -1,5 +0,0 @@
service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.rpi
class hal
user system
group system
file /dev/kmsg w

View File

@@ -1,11 +0,0 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.health</name>
<transport>hwbinder</transport>
<version>2.0</version>
<interface>
<name>IHealth</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

32
health/main.cpp Normal file
View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2023 KonstaKANG
*
* 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 "HealthImpl.h"
#include <android/binder_interface_utils.h>
#include <health/utils.h>
using ::aidl::android::hardware::health::HalHealthLoop;
using ::aidl::android::hardware::health::HealthImpl;
int main() {
auto config = std::make_unique<healthd_config>();
android::hardware::health::InitHealthdConfig(config.get());
auto binder = ndk::SharedRefBase::make<HealthImpl>("default", std::move(config));
auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
return hal_health_loop->StartLoop();
}

View File

@@ -31,7 +31,7 @@
/vendor/lib(64)?/libminigbm_gralloc_gbm_mesa\.so u:object_r:same_process_hal_file:s0 /vendor/lib(64)?/libminigbm_gralloc_gbm_mesa\.so u:object_r:same_process_hal_file:s0
# Health # Health
/vendor/bin/hw/android\.hardware\.health@2\.0-service.rpi u:object_r:hal_health_default_exec:s0 /vendor/bin/hw/android\.hardware\.health-service\.rpi u:object_r:hal_health_default_exec:s0
# Lights # Lights
/sys/class/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0 /sys/class/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0