From dbf22f7b1a91dc8072bd323c9898ae54d331390f Mon Sep 17 00:00:00 2001 From: Rajeswari N Date: Tue, 30 Jun 2020 10:27:46 +0530 Subject: [PATCH] power: conversion from hidl to aidl Added aidl specific changes Change-Id: Iaba27ba991db960b8e0721047910de4da1c20934 --- Android.mk | 9 +- Power.cpp | 115 ++++++++++++++------------ Power.h | 54 +++++------- android.hardware.power-service.rc | 4 + android.hardware.power@1.2-service.rc | 4 - service.cpp => main.cpp | 62 ++++---------- power-vendor-product.mk | 4 +- power.xml | 6 ++ 8 files changed, 114 insertions(+), 144 deletions(-) create mode 100644 android.hardware.power-service.rc delete mode 100644 android.hardware.power@1.2-service.rc rename service.cpp => main.cpp (55%) create mode 100644 power.xml diff --git a/Android.mk b/Android.mk index 209521c..84b9e54 100644 --- a/Android.mk +++ b/Android.mk @@ -7,10 +7,10 @@ ifeq ($(call is-vendor-board-platform,QCOM),true) include $(CLEAR_VARS) LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libxml2 libbase libhidlbase libhidltransport libutils android.hardware.power@1.2 +LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libxml2 libbase libutils android.hardware.power-ndk_platform libbinder_ndk LOCAL_HEADER_LIBRARIES += libutils_headers LOCAL_HEADER_LIBRARIES += libhardware_headers -LOCAL_SRC_FILES := power-common.c metadata-parser.c utils.c list.c hint-data.c powerhintparser.c service.cpp Power.cpp +LOCAL_SRC_FILES := power-common.c metadata-parser.c utils.c list.c hint-data.c powerhintparser.c Power.cpp main.cpp LOCAL_C_INCLUDES := external/libxml2/include \ external/icu/icu4c/source/common @@ -92,11 +92,12 @@ LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable LOCAL_VENDOR_MODULE := true include $(BUILD_SHARED_LIBRARY) else -LOCAL_MODULE := android.hardware.power@1.2-service -LOCAL_INIT_RC := android.hardware.power@1.2-service.rc +LOCAL_MODULE := android.hardware.power-service +LOCAL_INIT_RC := android.hardware.power-service.rc LOCAL_MODULE_TAGS := optional LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable LOCAL_VENDOR_MODULE := true +LOCAL_VINTF_FRAGMENTS := power.xml include $(BUILD_EXECUTABLE) endif diff --git a/Power.cpp b/Power.cpp index 81c0a85..3ccecbd 100644 --- a/Power.cpp +++ b/Power.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2019,2020 The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,74 +29,83 @@ #define LOG_TAG "QTI PowerHAL" -#include -#include #include "Power.h" -#include "power-common.h" +#include + +#include + +#include +#include +#include + +using ::aidl::android::hardware::power::BnPower; +using ::aidl::android::hardware::power::IPower; +using ::aidl::android::hardware::power::Mode; +using ::aidl::android::hardware::power::Boost; + +using ::ndk::ScopedAStatus; +using ::ndk::SharedRefBase; + +namespace aidl { namespace android { namespace hardware { namespace power { -namespace V1_2 { -namespace implementation { +namespace impl { -using ::android::hardware::power::V1_0::Feature; -using ::android::hardware::power::V1_0::PowerHint; -using ::android::hardware::power::V1_0::PowerStatePlatformSleepState; -using ::android::hardware::power::V1_0::Status; -using ::android::hardware::power::V1_1::PowerStateSubsystem; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; - -Power::Power() { - power_init(); +void setInteractive(bool interactive) { + set_interactive(interactive ? 1:0); } -Return Power::setInteractive(bool interactive) { - set_interactive(interactive ? 1:0); - return Void(); +ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { + LOG(INFO) << "Power setMode: " << static_cast(type) << " to: " << enabled; + switch(type){ + case Mode::DOUBLE_TAP_TO_WAKE: + case Mode::LOW_POWER: + case Mode::FIXED_PERFORMANCE: + case Mode::LAUNCH: + case Mode::EXPENSIVE_RENDERING: + case Mode::DEVICE_IDLE: + case Mode::DISPLAY_INACTIVE: + case Mode::AUDIO_STREAMING_LOW_LATENCY: + case Mode::CAMERA_STREAMING_SECURE: + case Mode::CAMERA_STREAMING_LOW: + case Mode::CAMERA_STREAMING_MID: + case Mode::CAMERA_STREAMING_HIGH: + case Mode::VR: + LOG(INFO) << "Mode " << static_cast(type) << "Not Supported"; + break; + case Mode::INTERACTIVE: + setInteractive(enabled); + power_hint(POWER_HINT_INTERACTION, NULL); + break; + case Mode::SUSTAINED_PERFORMANCE: + power_hint(POWER_HINT_SUSTAINED_PERFORMANCE, NULL); + break; + } + return ndk::ScopedAStatus::ok(); } -Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { - - power_hint(static_cast(hint), data ? (&data) : NULL); - return Void(); +ndk::ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) { + LOG(INFO) << "Power isModeSupported: " << static_cast(type); + *_aidl_return = false; + return ndk::ScopedAStatus::ok(); } -Return Power::setFeature(Feature feature, bool activate) { - return Void(); +ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { + LOG(INFO) << "Power setBoost: " << static_cast(type) + << ", duration: " << durationMs; + return ndk::ScopedAStatus::ok(); } -Return Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) { - - hidl_vec states; - states.resize(0); - - _hidl_cb(states, Status::SUCCESS); - return Void(); +ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) { + LOG(INFO) << "Power isBoostSupported: " << static_cast(type); + *_aidl_return = false; + return ndk::ScopedAStatus::ok(); } -Return Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) { - - hidl_vec subsystems; - - _hidl_cb(subsystems, Status::SUCCESS); - return Void(); -} - -Return Power::powerHintAsync(PowerHint_1_0 hint, int32_t data) { - - return powerHint(hint, data); -} - -Return Power::powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) { - - return powerHint(static_cast (hint), data); -} - -} // namespace implementation -} // namespace V1_2 +} // namespace impl } // namespace power } // namespace hardware } // namespace android +} // namespace aidl \ No newline at end of file diff --git a/Power.h b/Power.h index a787590..c512e0c 100644 --- a/Power.h +++ b/Power.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2019,2020 The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -27,48 +27,32 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ANDROID_HARDWARE_POWER_V1_2_POWER_H -#define ANDROID_HARDWARE_POWER_V1_2_POWER_H +#ifndef ANDROID_HARDWARE_POWER_POWER_H +#define ANDROID_HARDWARE_POWER_POWER_H -#include -#include -#include -#include +#include +#include "power-common.h" +namespace aidl { namespace android { namespace hardware { namespace power { -namespace V1_2 { -namespace implementation { +namespace impl { -using ::android::hardware::power::V1_0::Feature; -using PowerHint_1_0 = ::android::hardware::power::V1_0::PowerHint; -using PowerHint_1_2 = ::android::hardware::power::V1_2::PowerHint; -using ::android::hardware::power::V1_2::IPower; -using ::android::hardware::Return; -using ::android::hardware::Void; - -struct Power : public IPower { - // Methods from ::android::hardware::power::V1_0::IPower follow. - - Power(); - - Return setInteractive(bool interactive) override; - Return powerHint(PowerHint_1_0 hint, int32_t data) override; - Return setFeature(Feature feature, bool activate) override; - Return getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) override; - - // Methods from ::android::hardware::power::V1_1::IPower follow - Return getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override; - Return powerHintAsync(PowerHint_1_0 hint, int32_t data) override; - // Methods from ::android::hardware::power::V1_2::IPower follow - Return powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) override; +class Power : public BnPower { + public: + Power() : BnPower(){ + power_init(); + } + ndk::ScopedAStatus setMode(Mode type, bool enabled) override; + ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override; + ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; + ndk::ScopedAStatus isBoostSupported(Boost type, bool* _aidl_return) override; }; -} // namespace implementation -} // namespace V1_2 +} // namespace impl } // namespace power } // namespace hardware } // namespace android - -#endif // ANDROID_HARDWARE_POWER_V1_2_POWER_H +} // namespace aidl +#endif // ANDROID_HARDWARE_POWER_POWER_H diff --git a/android.hardware.power-service.rc b/android.hardware.power-service.rc new file mode 100644 index 0000000..7885506 --- /dev/null +++ b/android.hardware.power-service.rc @@ -0,0 +1,4 @@ +service vendor.power /vendor/bin/hw/android.hardware.power-service + class hal + user system + group system diff --git a/android.hardware.power@1.2-service.rc b/android.hardware.power@1.2-service.rc deleted file mode 100644 index 8a1c347..0000000 --- a/android.hardware.power@1.2-service.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.power-hal-1-2 /vendor/bin/hw/android.hardware.power@1.2-service - class hal - user system - group system diff --git a/service.cpp b/main.cpp similarity index 55% rename from service.cpp rename to main.cpp index 902c661..8389368 100644 --- a/service.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2020, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -27,55 +27,25 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define LOG_TAG "android.hardware.power@1.2-service" - -#include -#include -#include #include "Power.h" -using android::sp; -using android::status_t; -using android::OK; +#include +#include +#include -// libhwbinder: -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -// Generated HIDL files -using android::hardware::power::V1_2::IPower; -using android::hardware::power::V1_2::implementation::Power; +using aidl::android::hardware::power::impl::Power; int main() { - - status_t status; - android::sp service = nullptr; - - ALOGI("Power HAL Service 1.2 is starting."); - - service = new Power(); - if (service == nullptr) { - ALOGE("Can not create an instance of Power HAL interface."); - - goto shutdown; + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr vib = ndk::SharedRefBase::make(); + const std::string instance = std::string() + Power::descriptor + "/default"; + LOG(INFO) << "Instance " << instance; + binder_status_t status = AServiceManager_addService(vib->asBinder().get(), instance.c_str()); + LOG(INFO) << "Status " << status; + if(status != STATUS_OK){ + LOG(ERROR) << "Could not register" << instance; } - configureRpcThreadpool(1, true /*callerWillJoin*/); - - status = service->registerAsService(); - if (status != OK) { - ALOGE("Could not register service for Power HAL(%d).", status); - goto shutdown; - } - - ALOGI("Power Service is ready"); - joinRpcThreadpool(); - //Should not pass this line - -shutdown: - // In normal operation, we don't expect the thread pool to exit - - ALOGE("Power Service is shutting down"); - return 1; -} - + ABinderProcess_joinThreadPool(); + return 1; // should not reach +} \ No newline at end of file diff --git a/power-vendor-product.mk b/power-vendor-product.mk index 8dda07e..1b1e99c 100644 --- a/power-vendor-product.mk +++ b/power-vendor-product.mk @@ -1,6 +1,6 @@ #Power product definitions -PRODUCT_PACKAGES += android.hardware.power@1.2-impl -PRODUCT_PACKAGES += android.hardware.power@1.2-service +PRODUCT_PACKAGES += android.hardware.power-service +PRODUCT_PACKAGES += android.hardware.power-impl #Powerhint File ifeq ($(TARGET_BOARD_PLATFORM),msmnile) diff --git a/power.xml b/power.xml new file mode 100644 index 0000000..33558e1 --- /dev/null +++ b/power.xml @@ -0,0 +1,6 @@ + + + android.hardware.power + IPower/default + + \ No newline at end of file