diff --git a/device.mk b/device.mk index 7ee84f1..d815cca 100644 --- a/device.mk +++ b/device.mk @@ -86,6 +86,10 @@ PRODUCT_PACKAGES += \ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.nfc.hcef.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.nfc.hcef.xml +# PowerShare +PRODUCT_PACKAGES += \ + vendor.lineage.powershare@1.0-service.eqs + # Sensors PRODUCT_PACKAGES += \ sensors.eqs diff --git a/powershare/Android.bp b/powershare/Android.bp new file mode 100644 index 0000000..b9241b2 --- /dev/null +++ b/powershare/Android.bp @@ -0,0 +1,18 @@ +cc_binary { + name: "vendor.lineage.powershare@1.0-service.eqs", + defaults: ["hidl_defaults"], + init_rc: ["vendor.lineage.powershare@1.0-service.eqs.rc"], + vintf_fragments: ["vendor.lineage.powershare@1.0-service.eqs.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/PowerShare.cpp b/powershare/PowerShare.cpp new file mode 100644 index 0000000..6b6efdf --- /dev/null +++ b/powershare/PowerShare.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 The LineageOS 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 "vendor.lineage.powershare@1.0-service.eqs" + +#include "PowerShare.h" + +#include + +using ::android::base::ReadFileToString; +using ::android::base::WriteStringToFile; + +namespace { + +constexpr const char* kWirelessTxEnablePath = "/sys/class/power_supply/wireless/device/tx_mode"; + +} // anonymous namespace + +namespace vendor { +namespace lineage { +namespace powershare { +namespace V1_0 { +namespace implementation { + +Return PowerShare::isEnabled() { + std::string value; + return ReadFileToString(kWirelessTxEnablePath, &value) && value != "0\n"; +} + +Return PowerShare::setEnabled(bool enable) { + return WriteStringToFile(enable ? "1" : "0", kWirelessTxEnablePath, 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/PowerShare.h b/powershare/PowerShare.h new file mode 100644 index 0000000..3fe9b8c --- /dev/null +++ b/powershare/PowerShare.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 The LineageOS 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 VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H +#define VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H + +#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/service.cpp b/powershare/service.cpp new file mode 100644 index 0000000..01e420a --- /dev/null +++ b/powershare/service.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 The LineageOS 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 "vendor.lineage.powershare@1.0-service.eqs" + +#include +#include + +#include "PowerShare.h" + +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/vendor.lineage.powershare@1.0-service.eqs.rc b/powershare/vendor.lineage.powershare@1.0-service.eqs.rc new file mode 100644 index 0000000..3b1e76e --- /dev/null +++ b/powershare/vendor.lineage.powershare@1.0-service.eqs.rc @@ -0,0 +1,4 @@ +service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.eqs + class hal + user system + group system diff --git a/powershare/vendor.lineage.powershare@1.0-service.eqs.xml b/powershare/vendor.lineage.powershare@1.0-service.eqs.xml new file mode 100644 index 0000000..b4af2cd --- /dev/null +++ b/powershare/vendor.lineage.powershare@1.0-service.eqs.xml @@ -0,0 +1,11 @@ + + + vendor.lineage.powershare + hwbinder + 1.0 + + IPowerShare + default + + +