From 75a2fb5441559c5cbacb92dee8de32942ed0935a Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 22 Jan 2018 11:26:49 -0800 Subject: [PATCH 1/3] health: move util modules to utils/ Test: pass Change-Id: I5eb5202d75e26146d0d40fb726a0722cf8bf9e0f --- health/2.0/{ => utils}/libhealthhalutils/Android.bp | 0 health/2.0/{ => utils}/libhealthhalutils/HealthHalUtils.cpp | 0 .../libhealthhalutils/include/healthhalutils/HealthHalUtils.h | 0 .../libhealthstoragedefault}/Android.bp | 0 .../libhealthstoragedefault}/StorageHealthDefault.cpp | 0 .../libhealthstoragedefault}/include/StorageHealthDefault.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename health/2.0/{ => utils}/libhealthhalutils/Android.bp (100%) rename health/2.0/{ => utils}/libhealthhalutils/HealthHalUtils.cpp (100%) rename health/2.0/{ => utils}/libhealthhalutils/include/healthhalutils/HealthHalUtils.h (100%) rename health/2.0/{libstoragehealthdefault => utils/libhealthstoragedefault}/Android.bp (100%) rename health/2.0/{libstoragehealthdefault => utils/libhealthstoragedefault}/StorageHealthDefault.cpp (100%) rename health/2.0/{libstoragehealthdefault => utils/libhealthstoragedefault}/include/StorageHealthDefault.h (100%) diff --git a/health/2.0/libhealthhalutils/Android.bp b/health/2.0/utils/libhealthhalutils/Android.bp similarity index 100% rename from health/2.0/libhealthhalutils/Android.bp rename to health/2.0/utils/libhealthhalutils/Android.bp diff --git a/health/2.0/libhealthhalutils/HealthHalUtils.cpp b/health/2.0/utils/libhealthhalutils/HealthHalUtils.cpp similarity index 100% rename from health/2.0/libhealthhalutils/HealthHalUtils.cpp rename to health/2.0/utils/libhealthhalutils/HealthHalUtils.cpp diff --git a/health/2.0/libhealthhalutils/include/healthhalutils/HealthHalUtils.h b/health/2.0/utils/libhealthhalutils/include/healthhalutils/HealthHalUtils.h similarity index 100% rename from health/2.0/libhealthhalutils/include/healthhalutils/HealthHalUtils.h rename to health/2.0/utils/libhealthhalutils/include/healthhalutils/HealthHalUtils.h diff --git a/health/2.0/libstoragehealthdefault/Android.bp b/health/2.0/utils/libhealthstoragedefault/Android.bp similarity index 100% rename from health/2.0/libstoragehealthdefault/Android.bp rename to health/2.0/utils/libhealthstoragedefault/Android.bp diff --git a/health/2.0/libstoragehealthdefault/StorageHealthDefault.cpp b/health/2.0/utils/libhealthstoragedefault/StorageHealthDefault.cpp similarity index 100% rename from health/2.0/libstoragehealthdefault/StorageHealthDefault.cpp rename to health/2.0/utils/libhealthstoragedefault/StorageHealthDefault.cpp diff --git a/health/2.0/libstoragehealthdefault/include/StorageHealthDefault.h b/health/2.0/utils/libhealthstoragedefault/include/StorageHealthDefault.h similarity index 100% rename from health/2.0/libstoragehealthdefault/include/StorageHealthDefault.h rename to health/2.0/utils/libhealthstoragedefault/include/StorageHealthDefault.h From 4ad11a94741ca0108b48764395029b3a2ff9528b Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 22 Jan 2018 11:26:01 -0800 Subject: [PATCH 2/3] health: move duplicate HealthServiceCommon ... to hardware/interfaces. HealthServiceCommon becomes two separate libraries: - libhealthservicedefault for services on vendor - libhealthservicehealthd for healthd Test: boots Bug: 63702641 Change-Id: I40235cef7d4fa62103629bf507b0401e3f939654 --- health/2.0/utils/libhealthservice/Android.bp | 29 ++++++ .../libhealthservice/HealthServiceCommon.cpp | 92 +++++++++++++++++++ .../include/health2/service.h | 22 +++++ 3 files changed, 143 insertions(+) create mode 100644 health/2.0/utils/libhealthservice/Android.bp create mode 100644 health/2.0/utils/libhealthservice/HealthServiceCommon.cpp create mode 100644 health/2.0/utils/libhealthservice/include/health2/service.h diff --git a/health/2.0/utils/libhealthservice/Android.bp b/health/2.0/utils/libhealthservice/Android.bp new file mode 100644 index 0000000000..88c38f2125 --- /dev/null +++ b/health/2.0/utils/libhealthservice/Android.bp @@ -0,0 +1,29 @@ +// Reasonable defaults for android.hardware.health@2.0-service.. +// Vendor service can customize by implementing functions defined in +// libhealthd and libhealthstoragedefault. + + +cc_library_static { + name: "libhealthservice", + vendor_available: true, + srcs: ["HealthServiceCommon.cpp"], + + export_include_dirs: ["include"], + + cflags: [ + "-Wall", + "-Werror", + ], + shared_libs: [ + "android.hardware.health@2.0", + ], + static_libs: [ + "android.hardware.health@2.0-impl", + "android.hardware.health@1.0-convert", + ], + export_static_lib_headers: [ + "android.hardware.health@1.0-convert", + ], + header_libs: ["libhealthd_headers"], + export_header_lib_headers: ["libhealthd_headers"], +} diff --git a/health/2.0/utils/libhealthservice/HealthServiceCommon.cpp b/health/2.0/utils/libhealthservice/HealthServiceCommon.cpp new file mode 100644 index 0000000000..acb4501c08 --- /dev/null +++ b/health/2.0/utils/libhealthservice/HealthServiceCommon.cpp @@ -0,0 +1,92 @@ +/* + * 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. + */ + +#define LOG_TAG "health@2.0/" +#include + +#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 std::string gInstanceName; + +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 << gInstanceName << " Hal is starting up..."; + + gBinderFd = setupTransportPolling(); + + if (gBinderFd >= 0) { + if (healthd_register_event(gBinderFd, binder_event)) + LOG(ERROR) << LOG_TAG << gInstanceName << ": Register for binder events failed"; + } + + android::sp service = Health::initInstance(config); + CHECK_EQ(service->registerAsService(gInstanceName), android::OK) + << LOG_TAG << gInstanceName << ": Failed to register HAL"; + + LOG(INFO) << LOG_TAG << gInstanceName << ": 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 health_service_main(const char* instance) { + gInstanceName = instance; + if (gInstanceName.empty()) { + gInstanceName = "default"; + } + healthd_mode_ops = &healthd_mode_service_2_0_ops; + LOG(INFO) << LOG_TAG << gInstanceName << ": Hal starting main loop..."; + return healthd_main(); +} diff --git a/health/2.0/utils/libhealthservice/include/health2/service.h b/health/2.0/utils/libhealthservice/include/health2/service.h new file mode 100644 index 0000000000..d260568301 --- /dev/null +++ b/health/2.0/utils/libhealthservice/include/health2/service.h @@ -0,0 +1,22 @@ +/* + * Copyright 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. + */ + +#ifndef ANDROID_HARDWARE_HEALTH_V2_0_SERVICE_COMMON +#define ANDROID_HARDWARE_HEALTH_V2_0_SERVICE_COMMON + +int health_service_main(const char* instance = ""); + +#endif // ANDROID_HARDWARE_HEALTH_V2_0_SERVICE_COMMON From fed3bfa4bc8c8f28bc7f5fd36556910673cd5fe4 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 19 Jan 2018 13:17:34 -0800 Subject: [PATCH 3/3] health: add README. Test: none Bug: 63702641 Change-Id: I1d23c0cdf56516585e7c6dd0db577784baa7b74e --- health/2.0/README | 99 +++++++++++++++++++++++++++++++++++++++++ health/2.0/utils/README | 28 ++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 health/2.0/README create mode 100644 health/2.0/utils/README diff --git a/health/2.0/README b/health/2.0/README new file mode 100644 index 0000000000..a0a5f08669 --- /dev/null +++ b/health/2.0/README @@ -0,0 +1,99 @@ +Upgrading from health@1.0 HAL + +0. Remove android.hardware.health@1.0* from PRDOUCT_PACKAGES + in device///device.mk + +1. If the device does not have a vendor-specific libhealthd AND does not + implement storage-related APIs, just add the following to PRODUCT_PACKAGES: + android.hardware.health@2.0-service + Otherwise, continue to Step 2. + +2. Create directory + device///health + +3. Create device///health/Android.bp + (or equivalent device///health/Android.mk) + +cc_binary { + name: "android.hardware.health@2.0-service.", + init_rc: ["android.hardware.health@2.0-service..rc"], + proprietary: true, + relative_install_path: "hw", + srcs: [ + "HealthService.cpp", + ], + + cflags: [ + "-Wall", + "-Werror", + ], + + static_libs: [ + "android.hardware.health@2.0-impl", + "android.hardware.health@1.0-convert", + "libhealthservice", + "libbatterymonitor", + ], + + shared_libs: [ + "libbase", + "libcutils", + "libhidlbase", + "libhidltransport", + "libutils", + "android.hardware.health@2.0", + ], + + header_libs: ["libhealthd_headers"], +} + +4. Create device///health/android.hardware.health@2.0-service..rc + +service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service. + class hal + user system + group system + +5. Create device///health/HealthService.cpp: + +#include +int main() { return health_service_main(); } + +6. libhealthd dependency: + +6.1 If the device has a vendor-specific libhealthd., add it to static_libs. + +6.2 If the device does not have a vendor-specific libhealthd, add the following + lines to HealthService.cpp: + +#include +void healthd_board_init(struct healthd_config*) {} + +int healthd_board_battery_update(struct android::BatteryProperties*) { + // return 0 to log periodic polled battery status to kernel log + return 0; +} + +7. Storage related APIs: + +7.1 If the device does not implement IHealth.getDiskStats and + IHealth.getStorageInfo, add libstoragehealthdefault to static_libs. + +7.2 If the device implements one of these two APIs, add and implement the + following functions in HealthService.cpp: + +void get_storage_info(std::vector& info) { + // ... +} +void get_disk_stats(std::vector& stats) { + // ... +} + +8. Update necessary SELinux permissions. For example, + +# device///sepolicy/vendor/file_contexts +/vendor/bin/hw/android\.hardware\.health@2\.0-service. u:object_r:hal_health_default_exec:s0 + +# device///sepolicy/vendor/hal_health_default.te +# Add device specific permissions to hal_health_default domain, especially +# if Step 6.2 or Step 7.2 is done. diff --git a/health/2.0/utils/README b/health/2.0/utils/README new file mode 100644 index 0000000000..1d5c27f35f --- /dev/null +++ b/health/2.0/utils/README @@ -0,0 +1,28 @@ +* libhealthhalutils + +A convenience library for (hwbinder) clients of health HAL to choose between +the "default" instance (served by vendor service) or "backup" instance (served +by healthd). C++ clients of health HAL should use this library instead of +calling IHealth::getService() directly. + +Its Java equivalent can be found in BatteryService.HealthServiceWrapper. + +* libhealthservice + +Common code for all (hwbinder) services of the health HAL, including healthd and +vendor health service android.hardware.health@2.0-service(.). main() in +those binaries calls health_service_main() directly. + +* libhealthstoragedefault + +Default implementation for storage related APIs for (hwbinder) services of the +health HAL. If an implementation of the health HAL do not wish to provide any +storage info, include this library. Otherwise, it should implement the following +two functions: + +void get_storage_info(std::vector& info) { + // ... +} +void get_disk_stats(std::vector& stats) { + // ... +}