From bd66d5bf2e8e2cec3333d5476708bd5d02d74395 Mon Sep 17 00:00:00 2001 From: Cosmin Tanislav Date: Thu, 22 Aug 2024 13:26:43 +0300 Subject: [PATCH] powershare: add default implementation Change-Id: If14d0e2038c604d6da5e383df638fd138e7aea26 --- powershare/1.0/default/Android.bp | 21 ++++++++ powershare/1.0/default/PowerShare.cpp | 51 +++++++++++++++++++ powershare/1.0/default/PowerShare.h | 40 +++++++++++++++ powershare/1.0/default/service.cpp | 31 +++++++++++ ....lineage.powershare@1.0-service.default.rc | 4 ++ ...lineage.powershare@1.0-service.default.xml | 11 ++++ 6 files changed, 158 insertions(+) create mode 100644 powershare/1.0/default/Android.bp create mode 100644 powershare/1.0/default/PowerShare.cpp create mode 100644 powershare/1.0/default/PowerShare.h create mode 100644 powershare/1.0/default/service.cpp create mode 100644 powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.rc create mode 100644 powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.xml diff --git a/powershare/1.0/default/Android.bp b/powershare/1.0/default/Android.bp new file mode 100644 index 0000000..92c8f3b --- /dev/null +++ b/powershare/1.0/default/Android.bp @@ -0,0 +1,21 @@ +cc_binary { + name: "vendor.lineage.powershare@1.0-service.default", + defaults: [ + "hidl_defaults", + "powershare_defaults", + ], + init_rc: ["vendor.lineage.powershare@1.0-service.default.rc"], + vintf_fragments: ["vendor.lineage.powershare@1.0-service.default.xml"], + vendor: true, + relative_install_path: "hw", + srcs: [ + "service.cpp", + "PowerShare.cpp", + ], + shared_libs: [ + "libbase", + "libhidlbase", + "libutils", + "vendor.lineage.powershare@1.0", + ], +} diff --git a/powershare/1.0/default/PowerShare.cpp b/powershare/1.0/default/PowerShare.cpp new file mode 100644 index 0000000..e25fbb0 --- /dev/null +++ b/powershare/1.0/default/PowerShare.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "PowerShare.h" + +#include +#include + +using ::android::base::ReadFileToString; +using ::android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace powershare { +namespace V1_0 { +namespace implementation { + +Return PowerShare::isEnabled() { + std::string value; + + if (!ReadFileToString(POWERSHARE_PATH, &value)) { + LOG(ERROR) << "Failed to read current powershare value"; + return false; + } + + value = android::base::Trim(value); + + return value == POWERSHARE_ENABLED; +} + +Return PowerShare::setEnabled(bool enable) { + const auto& value = enable ? POWERSHARE_ENABLED : POWERSHARE_DISABLED; + return WriteStringToFile(value, POWERSHARE_PATH, true); +} + +Return PowerShare::getMinBattery() { + return 0; +} + +Return PowerShare::setMinBattery(uint32_t /*minBattery*/) { + return getMinBattery(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace powershare +} // namespace lineage +} // namespace vendor diff --git a/powershare/1.0/default/PowerShare.h b/powershare/1.0/default/PowerShare.h new file mode 100644 index 0000000..97e24ea --- /dev/null +++ b/powershare/1.0/default/PowerShare.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H +#define VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H + +#define LOG_TAG "vendor.lineage.powershare@1.0-service.default" + +#include + +#include + +namespace vendor { +namespace lineage { +namespace powershare { +namespace V1_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; + +class PowerShare : public IPowerShare { + public: + Return isEnabled() override; + Return setEnabled(bool enable) override; + Return getMinBattery() override; + Return setMinBattery(uint32_t minBattery) override; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace powershare +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H diff --git a/powershare/1.0/default/service.cpp b/powershare/1.0/default/service.cpp new file mode 100644 index 0000000..263b025 --- /dev/null +++ b/powershare/1.0/default/service.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "PowerShare.h" + +#include + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::sp; + +using vendor::lineage::powershare::V1_0::IPowerShare; +using vendor::lineage::powershare::V1_0::implementation::PowerShare; + +int main() { + sp powerShareService = new PowerShare(); + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (powerShareService->registerAsService() != android::OK) { + LOG(ERROR) << "Can't register PowerShare HAL service"; + return 1; + } + + joinRpcThreadpool(); + + return 0; // should never get here +} diff --git a/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.rc b/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.rc new file mode 100644 index 0000000..30e7dd6 --- /dev/null +++ b/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.rc @@ -0,0 +1,4 @@ +service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.default + class hal + user system + group system diff --git a/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.xml b/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.xml new file mode 100644 index 0000000..b4af2cd --- /dev/null +++ b/powershare/1.0/default/vendor.lineage.powershare@1.0-service.default.xml @@ -0,0 +1,11 @@ + + + vendor.lineage.powershare + hwbinder + 1.0 + + IPowerShare + default + + +