From 28e667380b264f94f6e4d3b8a6abc2c5a3fc6a93 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 7 Jul 2020 12:47:29 +0200 Subject: [PATCH] sm8250-common: Implement vendor.lineage.powershare@1.0 HAL --- common.mk | 4 ++ framework_manifest.xml | 9 +++ powershare/Android.bp | 32 +++++++++ powershare/PowerShare.cpp | 71 +++++++++++++++++++ powershare/PowerShare.h | 45 ++++++++++++ ...age.powershare@1.0-service.oneplus_kona.rc | 4 ++ powershare/service.cpp | 50 +++++++++++++ sepolicy/private/file.te | 1 + sepolicy/private/file_contexts | 1 + sepolicy/private/hal_powershare_kona.te | 9 +++ 10 files changed, 226 insertions(+) create mode 100644 powershare/Android.bp create mode 100644 powershare/PowerShare.cpp create mode 100644 powershare/PowerShare.h create mode 100644 powershare/lineage.powershare@1.0-service.oneplus_kona.rc create mode 100644 powershare/service.cpp create mode 100644 sepolicy/private/hal_powershare_kona.te diff --git a/common.mk b/common.mk index 23775dc..c916620 100644 --- a/common.mk +++ b/common.mk @@ -168,6 +168,10 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ android.hardware.power@1.2-service.oneplus_kona +# PowerShare +PRODUCT_PACKAGES += \ + lineage.powershare@1.0-service.oneplus_kona + # Ramdisk PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/rootdir/etc/fstab.qcom:$(TARGET_COPY_OUT_RAMDISK)/fstab.qcom diff --git a/framework_manifest.xml b/framework_manifest.xml index a7b965a..02a5d24 100644 --- a/framework_manifest.xml +++ b/framework_manifest.xml @@ -34,6 +34,15 @@ default + + vendor.lineage.powershare + hwbinder + 1.0 + + IPowerShare + default + + vendor.lineage.trust hwbinder diff --git a/powershare/Android.bp b/powershare/Android.bp new file mode 100644 index 0000000..b7f4f18 --- /dev/null +++ b/powershare/Android.bp @@ -0,0 +1,32 @@ +// +// Copyright (C) 2020 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. + +cc_binary { + relative_install_path: "hw", + defaults: ["hidl_defaults"], + name: "lineage.powershare@1.0-service.oneplus_kona", + init_rc: ["lineage.powershare@1.0-service.oneplus_kona.rc"], + srcs: ["service.cpp", "PowerShare.cpp"], + shared_libs: [ + "libbase", + "libhardware", + "libhidlbase", + "libhidltransport", + "liblog", + "libhwbinder", + "libutils", + "vendor.lineage.powershare@1.0", + ], +} diff --git a/powershare/PowerShare.cpp b/powershare/PowerShare.cpp new file mode 100644 index 0000000..271a900 --- /dev/null +++ b/powershare/PowerShare.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2020 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 "PowerShareService" + +#include "PowerShare.h" +#include +#include + +namespace vendor { +namespace lineage { +namespace powershare { +namespace V1_0 { +namespace implementation { + +#define WIRELESS_TX_ENABLE_PATH "/proc/wireless/enable_tx" + +/* + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value; +} + +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + + file >> result; + return file.fail() ? def : result; +} + +Return PowerShare::isEnabled() { + return get(WIRELESS_TX_ENABLE_PATH, "disable") != "disable"; +} + +Return PowerShare::setEnabled(bool enable) { + set(WIRELESS_TX_ENABLE_PATH, enable ? 1 : 0); + + return isEnabled(); +} + +Return PowerShare::getMinBattery() { + return 0; +} + +Return PowerShare::setMinBattery(uint32_t) { + 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..f1ab807 --- /dev/null +++ b/powershare/PowerShare.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 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/lineage.powershare@1.0-service.oneplus_kona.rc b/powershare/lineage.powershare@1.0-service.oneplus_kona.rc new file mode 100644 index 0000000..b5f8808 --- /dev/null +++ b/powershare/lineage.powershare@1.0-service.oneplus_kona.rc @@ -0,0 +1,4 @@ +service powershare-hal-1-0 /system/bin/hw/lineage.powershare@1.0-service.oneplus_kona + class hal + user system + group system diff --git a/powershare/service.cpp b/powershare/service.cpp new file mode 100644 index 0000000..8220127 --- /dev/null +++ b/powershare/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 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 "lineage.powershare@1.0-service.oneplus_kona" + +#include +#include + +#include "PowerShare.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +using vendor::lineage::powershare::V1_0::IPowerShare; +using vendor::lineage::powershare::V1_0::implementation::PowerShare; + +using android::OK; +using android::status_t; + +int main() { + android::sp service = new PowerShare(); + + configureRpcThreadpool(1, true); + + status_t status = service->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Cannot register PowerShare HAL service."; + return 1; + } + + LOG(INFO) << "PowerShare HAL service ready."; + + joinRpcThreadpool(); + + LOG(ERROR) << "PowerShare HAL service failed to join thread pool."; + return 1; +} diff --git a/sepolicy/private/file.te b/sepolicy/private/file.te index 10f4d41..905d8ea 100644 --- a/sepolicy/private/file.te +++ b/sepolicy/private/file.te @@ -4,6 +4,7 @@ type op2_file, file_type; # proc type proc_touchpanel, fs_type, proc_type; +type procfs_oem_wireless, fs_type, proc_type; # sysfs type sysfs_battery_supply, sysfs_type, fs_type; diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts index a279d06..805fa2e 100644 --- a/sepolicy/private/file_contexts +++ b/sepolicy/private/file_contexts @@ -13,6 +13,7 @@ /(product|system/product)/vendor_overlay/[0-9]+/bin/hw/android\.hardware\.power@1\.2-service u:object_r:hal_power_default_exec:s0 /system/bin/hw/lineage\.biometrics\.fingerprint\.inscreen@1.0-service\.oneplus_kona u:object_r:hal_fod_kona_exec:s0 /system/bin/hw/lineage\.livedisplay@2\.0-service\.oneplus_kona u:object_r:hal_livedisplay_kona_exec:s0 +/system/bin/hw/lineage\.powershare@1\.0-service\.oneplus_kona u:object_r:hal_powershare_kona_exec:s0 /system/bin/hw/lineage\.touch@1\.0-service\.oneplus_kona u:object_r:hal_touch_kona_exec:s0 # DASH diff --git a/sepolicy/private/hal_powershare_kona.te b/sepolicy/private/hal_powershare_kona.te new file mode 100644 index 0000000..ee87ee1 --- /dev/null +++ b/sepolicy/private/hal_powershare_kona.te @@ -0,0 +1,9 @@ +type hal_powershare_kona, coredomain, domain; +hal_server_domain(hal_powershare_kona, hal_lineage_powershare) + +type hal_powershare_kona_exec, system_file_type, exec_type, file_type; +init_daemon_domain(hal_powershare_kona) + +# Allow access to wireless rx enable nodes +allow hal_powershare_kona procfs_oem_wireless:dir search; +allow hal_powershare_kona procfs_oem_wireless:file rw_file_perms;