diff --git a/device.mk b/device.mk index 41afbb9..99d5113 100644 --- a/device.mk +++ b/device.mk @@ -186,7 +186,7 @@ PRODUCT_COPY_FILES += \ # Health PRODUCT_PACKAGES += \ - android.hardware.health@2.0-service.rpi + android.hardware.health-service.rpi # Kernel PRODUCT_COPY_FILES += \ diff --git a/health/Android.bp b/health/Android.bp index c969bf9..033aeea 100644 --- a/health/Android.bp +++ b/health/Android.bp @@ -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 cc_binary { - name: "android.hardware.health@2.0-service.rpi", - init_rc: ["android.hardware.health@2.0-service.rpi.rc"], - vintf_fragments: ["android.hardware.health@2.0-service.rpi.xml"], - proprietary: true, + name: "android.hardware.health-service.rpi", relative_install_path: "hw", + vendor: true, + init_rc: ["android.hardware.health-service.rpi.rc"], + vintf_fragments: ["android.hardware.health-service.rpi.xml"], srcs: [ - "HealthService.cpp", - ], - cflags: [ - "-Wall", - "-Werror", + "HealthImpl.cpp", + "main.cpp", ], static_libs: [ - "android.hardware.health@2.0-impl", - "android.hardware.health@1.0-convert", - "libhealthservice", + "android.hardware.health-translate-ndk", "libbatterymonitor", - "libhealthstoragedefault", + "libhealthloop", + "libhealth_aidl_impl", ], shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", "libhidlbase", + "liblog", "libutils", - "android.hardware.health@2.0", + "android.hardware.health-V1-ndk", ], - header_libs: ["libhealthd_headers"], + overrides: ["charger"], } diff --git a/health/HealthImpl.cpp b/health/HealthImpl.cpp new file mode 100644 index 0000000..c452ab9 --- /dev/null +++ b/health/HealthImpl.cpp @@ -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 diff --git a/health/HealthImpl.h b/health/HealthImpl.h new file mode 100644 index 0000000..49f77e9 --- /dev/null +++ b/health/HealthImpl.h @@ -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 + +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 diff --git a/health/HealthService.cpp b/health/HealthService.cpp deleted file mode 100644 index 51b9574..0000000 --- a/health/HealthService.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2021-2022 KonstaKANG - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -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; -} diff --git a/health/android.hardware.health-service.rpi.rc b/health/android.hardware.health-service.rpi.rc new file mode 100644 index 0000000..18b5fab --- /dev/null +++ b/health/android.hardware.health-service.rpi.rc @@ -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 diff --git a/health/android.hardware.health-service.rpi.xml b/health/android.hardware.health-service.rpi.xml new file mode 100644 index 0000000..98026cb --- /dev/null +++ b/health/android.hardware.health-service.rpi.xml @@ -0,0 +1,7 @@ + + + android.hardware.health + 1 + IHealth/default + + diff --git a/health/android.hardware.health@2.0-service.rpi.rc b/health/android.hardware.health@2.0-service.rpi.rc deleted file mode 100644 index 4f20720..0000000 --- a/health/android.hardware.health@2.0-service.rpi.rc +++ /dev/null @@ -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 diff --git a/health/android.hardware.health@2.0-service.rpi.xml b/health/android.hardware.health@2.0-service.rpi.xml deleted file mode 100644 index a86714b..0000000 --- a/health/android.hardware.health@2.0-service.rpi.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.health - hwbinder - 2.0 - - IHealth - default - - - diff --git a/health/main.cpp b/health/main.cpp new file mode 100644 index 0000000..877780e --- /dev/null +++ b/health/main.cpp @@ -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 +#include + +using ::aidl::android::hardware::health::HalHealthLoop; +using ::aidl::android::hardware::health::HealthImpl; + +int main() { + auto config = std::make_unique(); + android::hardware::health::InitHealthdConfig(config.get()); + auto binder = ndk::SharedRefBase::make("default", std::move(config)); + auto hal_health_loop = std::make_shared(binder, binder); + return hal_health_loop->StartLoop(); +} diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 7933e00..4926abb 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -31,7 +31,7 @@ /vendor/lib(64)?/libminigbm_gralloc_gbm_mesa\.so u:object_r:same_process_hal_file:s0 # 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 /sys/class/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0