From 9baa87db4777277400311d4bb4aa25cdaf9c5c54 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Thu, 5 Mar 2020 14:23:34 +0800 Subject: [PATCH] health: HAL 2.1 for sunfish Bug: 145943771 Test: lshal debug android.hardware.health@2.1::IHealth/default Change-Id: I84f20459f5579e318d8e9f5f9ce68a733df27c53 Signed-off-by: Jack Wu --- CleanSpec.mk | 6 ++ config.fs | 6 -- device.mk | 3 +- health/Android.bp | 20 ++-- health/{HealthService.cpp => Health.cpp} | 102 +++++++++++++++--- ...oid.hardware.health@2.0-service.sunfish.rc | 5 - manifest.xml | 9 -- 7 files changed, 105 insertions(+), 46 deletions(-) rename health/{HealthService.cpp => Health.cpp} (58%) delete mode 100644 health/android.hardware.health@2.0-service.sunfish.rc diff --git a/CleanSpec.mk b/CleanSpec.mk index 1a5781f1..e7b184cc 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -47,6 +47,12 @@ # Remove default android.hardware.health@2.0-service $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.health@2.0-service) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.health@2.0-service.rc) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.health@2.0-service.sunfish) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.health@2.0-service.sunfish.rc) + +# Remove health HAL 2.1 +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.health@2.1-service) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.health@2.1-service.rc) # Remove healthd $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/healthd) diff --git a/config.fs b/config.fs index dd5bcd4e..365f028a 100644 --- a/config.fs +++ b/config.fs @@ -68,12 +68,6 @@ user: AID_SYSTEM group: AID_SYSTEM caps: NET_BIND_SERVICE BLOCK_SUSPEND NET_ADMIN -[vendor/bin/hw/android.hardware.health@2.0-service.sunfish] -mode: 0755 -user: AID_SYSTEM -group: AID_SYSTEM -caps: WAKE_ALARM - [vendor/bin/loc_launcher] mode: 0755 user: AID_GPS diff --git a/device.mk b/device.mk index 47cb676a..2f538837 100644 --- a/device.mk +++ b/device.mk @@ -398,7 +398,8 @@ PRODUCT_PACKAGES += \ android.hardware.usb@1.2-service.sunfish PRODUCT_PACKAGES += \ - android.hardware.health@2.0-service.sunfish + android.hardware.health@2.1-impl-sunfish \ + android.hardware.health@2.1-service # Storage health HAL PRODUCT_PACKAGES += \ diff --git a/health/Android.bp b/health/Android.bp index 270ac53f..057c63d9 100644 --- a/health/Android.bp +++ b/health/Android.bp @@ -14,13 +14,14 @@ * limitations under the License. */ -cc_binary { - name: "android.hardware.health@2.0-service.sunfish", - init_rc: ["android.hardware.health@2.0-service.sunfish.rc"], +cc_library_shared { + name: "android.hardware.health@2.1-impl-sunfish", + stem: "android.hardware.health@2.0-impl-2.1-sunfish", + proprietary: true, relative_install_path: "hw", srcs: [ - "HealthService.cpp", + "Health.cpp", ], cflags: [ @@ -29,10 +30,10 @@ cc_binary { ], static_libs: [ - "android.hardware.health@2.0-impl", "android.hardware.health@1.0-convert", - "libhealthservice", "libbatterymonitor", + "libhealth2impl", + "libhealthloop", ], shared_libs: [ @@ -42,11 +43,6 @@ cc_binary { "libpixelhealth", "libutils", "android.hardware.health@2.0", - ], - - header_libs: ["libhealthd_headers"], - - overrides: [ - "healthd", + "android.hardware.health@2.1", ], } diff --git a/health/HealthService.cpp b/health/Health.cpp similarity index 58% rename from health/HealthService.cpp rename to health/Health.cpp index f6a4b157..95a27dbd 100644 --- a/health/HealthService.cpp +++ b/health/Health.cpp @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "android.hardware.health@2.0-service.sunfish" +#define LOG_TAG "android.hardware.health@2.1-impl-sunfish" #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include + #include #include #include @@ -34,9 +35,17 @@ namespace { +using namespace std::literals; + +using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo; +using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo; using android::hardware::health::V2_0::DiskStats; using android::hardware::health::V2_0::StorageAttribute; using android::hardware::health::V2_0::StorageInfo; +using android::hardware::health::V2_0::Result; +using ::android::hardware::health::V2_1::IHealth; +using android::hardware::health::InitHealthdConfig; + using hardware::google::pixel::health::BatteryMetricsLogger; using hardware::google::pixel::health::DeviceHealth; using hardware::google::pixel::health::LowBatteryShutdownMetrics; @@ -54,7 +63,7 @@ static DeviceHealth deviceHealth; constexpr char kUfsHealthEol[]{UFS_DIR "/health/eol"}; constexpr char kUfsHealthLifetimeA[]{UFS_DIR "/health/lifetimeA"}; constexpr char kUfsHealthLifetimeB[]{UFS_DIR "/health/lifetimeB"}; -constexpr char kUfsVersion[]{UFS_DIR "/device_descriptor/specification_version"}; +constexpr char kUfsVersion[]{UFS_DIR "/version"}; constexpr char kDiskStatsFile[]{"/sys/block/sda/stat"}; constexpr char kUFSName[]{"UFS0"}; @@ -89,20 +98,18 @@ void fill_ufs_storage_attribute(StorageAttribute *attr) { attr->name = kUFSName; } -} // anonymous namespace - -void healthd_board_init(struct healthd_config *hc) { +void private_healthd_board_init(struct healthd_config *hc) { hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName)); } -int healthd_board_battery_update(struct android::BatteryProperties *props) { +int private_healthd_board_battery_update(struct android::BatteryProperties *props) { deviceHealth.update(props); battMetricsLogger.logBatteryProperties(props); shutdownMetrics.logShutdownVoltage(props); return 0; } -void get_storage_info(std::vector &vec_storage_info) { +void private_get_storage_info(std::vector &vec_storage_info) { vec_storage_info.resize(1); StorageInfo *storage_info = &vec_storage_info[0]; fill_ufs_storage_attribute(&storage_info->attr); @@ -114,7 +121,7 @@ void get_storage_info(std::vector &vec_storage_info) { return; } -void get_disk_stats(std::vector &vec_stats) { +void private_get_disk_stats(std::vector &vec_stats) { vec_stats.resize(1); DiskStats *stats = &vec_stats[0]; fill_ufs_storage_attribute(&stats->attr); @@ -127,5 +134,74 @@ void get_disk_stats(std::vector &vec_stats) { stats->ioTicks >> stats->ioInQueue; return; } +} // anonymous namespace + +namespace android { +namespace hardware { +namespace health { +namespace V2_1 { +namespace implementation { +class HealthImpl : public Health { + public: + HealthImpl(std::unique_ptr&& config) + : Health(std::move(config)) {} + + Return getStorageInfo(getStorageInfo_cb _hidl_cb) override; + Return getDiskStats(getDiskStats_cb _hidl_cb) override; + + protected: + void UpdateHealthInfo(HealthInfo* health_info) override; + +}; + +void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) { + struct BatteryProperties props; + convertFromHealthInfo(health_info->legacy.legacy, &props); + private_healthd_board_battery_update(&props); + convertToHealthInfo(&props, health_info->legacy.legacy); +} -int main(void) { return health_service_main(); } +Return HealthImpl::getStorageInfo(getStorageInfo_cb _hidl_cb) +{ + std::vector info; + private_get_storage_info(info); + hidl_vec info_vec(info); + if (!info.size()) { + _hidl_cb(Result::NOT_SUPPORTED, info_vec); + } else { + _hidl_cb(Result::SUCCESS, info_vec); + } + return Void(); +} + +Return HealthImpl::getDiskStats(getDiskStats_cb _hidl_cb) +{ + std::vector stats; + private_get_disk_stats(stats); + hidl_vec stats_vec(stats); + if (!stats.size()) { + _hidl_cb(Result::NOT_SUPPORTED, stats_vec); + } else { + _hidl_cb(Result::SUCCESS, stats_vec); + } + return Void(); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace health +} // namespace hardware +} // namespace android + +extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) { + using ::android::hardware::health::V2_1::implementation::HealthImpl; + if (instance != "default"sv) { + return nullptr; + } + auto config = std::make_unique(); + InitHealthdConfig(config.get()); + + private_healthd_board_init(config.get()); + + return new HealthImpl(std::move(config)); +} diff --git a/health/android.hardware.health@2.0-service.sunfish.rc b/health/android.hardware.health@2.0-service.sunfish.rc deleted file mode 100644 index 107d8bfb..00000000 --- a/health/android.hardware.health@2.0-service.sunfish.rc +++ /dev/null @@ -1,5 +0,0 @@ -service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.sunfish - class hal - user system - group system - file /dev/kmsg w diff --git a/manifest.xml b/manifest.xml index e6190ec5..0ffc290c 100644 --- a/manifest.xml +++ b/manifest.xml @@ -36,15 +36,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. default - - android.hardware.health - hwbinder - 2.0 - - IHealth - default - - android.hardware.audio hwbinder