diff --git a/healthd/Android.bp b/healthd/Android.bp index df12ff05e..c70278af3 100644 --- a/healthd/Android.bp +++ b/healthd/Android.bp @@ -26,12 +26,10 @@ cc_binary { vendor: true, relative_install_path: "hw", srcs: [ - "HealthServiceCommon.cpp", "HealthServiceDefault.cpp", ], cflags: [ - "-DHEALTH_INSTANCE_NAME=\"default\"", "-Wall", "-Werror", ], @@ -39,6 +37,7 @@ cc_binary { static_libs: [ "android.hardware.health@2.0-impl", "android.hardware.health@1.0-convert", + "libhealthservice", "libhealthstoragedefault", "libbatterymonitor", ], @@ -58,13 +57,11 @@ cc_binary { cc_binary { name: "healthd", srcs: [ - "HealthServiceCommon.cpp", "HealthServiceHealthd.cpp", ], local_include_dirs: ["include"], cflags: [ - "-DHEALTH_INSTANCE_NAME=\"backup\"", "-Wall", "-Werror", ], @@ -72,6 +69,7 @@ cc_binary { static_libs: [ "android.hardware.health@2.0-impl", "android.hardware.health@1.0-convert", + "libhealthservice", "libbatterymonitor", "libhealthstoragedefault", ], diff --git a/healthd/HealthServiceCommon.cpp b/healthd/HealthServiceCommon.cpp deleted file mode 100644 index a2ca44b05..000000000 --- a/healthd/HealthServiceCommon.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2017 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. - */ - -// This is a reference implementation for health@2.0 HAL. A vendor -// can write its own HealthService.cpp with customized init and update functions. - -#define LOG_TAG "health@2.0/" HEALTH_INSTANCE_NAME -#include - -#include -#include -#include -#include -#include - -using android::hardware::IPCThreadState; -using android::hardware::configureRpcThreadpool; -using android::hardware::handleTransportPoll; -using android::hardware::setupTransportPolling; -using android::hardware::health::V2_0::HealthInfo; -using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo; -using android::hardware::health::V2_0::IHealth; -using android::hardware::health::V2_0::implementation::Health; - -extern int healthd_main(void); - -static int gBinderFd = -1; - -static void binder_event(uint32_t /*epevents*/) { - if (gBinderFd >= 0) handleTransportPoll(gBinderFd); -} - -void healthd_mode_service_2_0_init(struct healthd_config* config) { - LOG(INFO) << LOG_TAG << " Hal is starting up..."; - - gBinderFd = setupTransportPolling(); - - if (gBinderFd >= 0) { - if (healthd_register_event(gBinderFd, binder_event)) - LOG(ERROR) << LOG_TAG << ": Register for binder events failed"; - } - - android::sp service = Health::initInstance(config); - CHECK_EQ(service->registerAsService(HEALTH_INSTANCE_NAME), android::OK) - << LOG_TAG << ": Failed to register HAL"; - - LOG(INFO) << LOG_TAG << ": Hal init done"; -} - -int healthd_mode_service_2_0_preparetowait(void) { - IPCThreadState::self()->flushCommands(); - return -1; -} - -void healthd_mode_service_2_0_heartbeat(void) { - // noop -} - -void healthd_mode_service_2_0_battery_update(struct android::BatteryProperties* prop) { - HealthInfo info; - convertToHealthInfo(prop, info.legacy); - Health::getImplementation()->notifyListeners(&info); -} - -static struct healthd_mode_ops healthd_mode_service_2_0_ops = { - .init = healthd_mode_service_2_0_init, - .preparetowait = healthd_mode_service_2_0_preparetowait, - .heartbeat = healthd_mode_service_2_0_heartbeat, - .battery_update = healthd_mode_service_2_0_battery_update, -}; - -int main() { - healthd_mode_ops = &healthd_mode_service_2_0_ops; - LOG(INFO) << LOG_TAG << ": Hal starting main loop..."; - return healthd_main(); -} diff --git a/healthd/HealthServiceDefault.cpp b/healthd/HealthServiceDefault.cpp index dbc480ffe..89ecc2fa4 100644 --- a/healthd/HealthServiceDefault.cpp +++ b/healthd/HealthServiceDefault.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include void healthd_board_init(struct healthd_config*) { @@ -32,3 +33,7 @@ int healthd_board_battery_update(struct android::BatteryProperties*) { // return 0 to log periodic polled battery status to kernel log return 0; } + +int main() { + return health_service_main(); +} diff --git a/healthd/HealthServiceHealthd.cpp b/healthd/HealthServiceHealthd.cpp index 72a446ad4..5fd2597d6 100644 --- a/healthd/HealthServiceHealthd.cpp +++ b/healthd/HealthServiceHealthd.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -86,3 +87,7 @@ int healthd_board_battery_update(struct android::BatteryProperties* props) { return logthis; } + +int main() { + return health_service_main("backup"); +}