diff --git a/device.mk b/device.mk index 1501233..c13b608 100644 --- a/device.mk +++ b/device.mk @@ -188,6 +188,10 @@ PRODUCT_PACKAGES += \ android.hardware.fastboot@1.1-impl-mock \ fastbootd +# Fastcharge +PRODUCT_PACKAGES += \ + vendor.lineage.fastcharge@1.0-service.stone + # Filesystem PRODUCT_PACKAGES += \ fs_config_files diff --git a/fastcharge/Android.bp b/fastcharge/Android.bp new file mode 100644 index 0000000..e1580c9 --- /dev/null +++ b/fastcharge/Android.bp @@ -0,0 +1,19 @@ +cc_binary { + name: "vendor.lineage.fastcharge@1.0-service.stone", + relative_install_path: "hw", + init_rc: ["vendor.lineage.fastcharge@1.0-service.stone.rc"], + vintf_fragments: ["vendor.lineage.fastcharge@1.0-service.stone.xml"], + vendor: true, + shared_libs: [ + "libbase", + "libbinder", + "libcutils", + "libhidlbase", + "libutils", + "vendor.lineage.fastcharge@1.0", + ], + srcs: [ + "FastCharge.cpp", + "service.cpp", + ], +} diff --git a/fastcharge/FastCharge.cpp b/fastcharge/FastCharge.cpp new file mode 100644 index 0000000..1b494d3 --- /dev/null +++ b/fastcharge/FastCharge.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2023 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 "fastcharge@1.0-service.stone" + +#define FASTCHARGE_DEFAULT_SETTING true +/* + * This is a dummy path + */ +#define FASTCHARGE_PATH "" + +#include "FastCharge.h" +#include +#include + +#include +#include + +namespace vendor { +namespace lineage { +namespace fastcharge { +namespace V1_0 { +namespace implementation { + +static constexpr const char *kFastChargingProp = + "persist.vendor.sec.fastchg_enabled"; + +/* + * Write value to path and close file. + */ +template static void set(const std::string &path, const T &value) { + std::ofstream file(path); + + if (!file) { + PLOG(ERROR) << "Failed to open: " << path; + return; + } + + LOG(DEBUG) << "write: " << path << " value: " << value; + + file << value << std::endl; + + if (!file) { + PLOG(ERROR) << "Failed to write: " << path << " value: " << value; + } +} + +template static T get(const std::string &path, const T &def) { + std::ifstream file(path); + + if (!file) { + PLOG(ERROR) << "Failed to open: " << path; + return def; + } + + T result; + + file >> result; + + if (file.fail()) { + PLOG(ERROR) << "Failed to read: " << path; + return def; + } else { + LOG(DEBUG) << "read: " << path << " value: " << result; + return result; + } +} + +FastCharge::FastCharge() { + setEnabled(property_get_bool(kFastChargingProp, FASTCHARGE_DEFAULT_SETTING)); +} + +Return FastCharge::isEnabled() { return get(FASTCHARGE_PATH, 0) < 1; } + +Return FastCharge::setEnabled(bool enable) { + set(FASTCHARGE_PATH, enable ? 0 : 1); + + bool enabled = isEnabled(); + property_set(kFastChargingProp, enabled ? "true" : "false"); + + return enabled; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace fastcharge +} // namespace lineage +} // namespace vendor diff --git a/fastcharge/FastCharge.h b/fastcharge/FastCharge.h new file mode 100644 index 0000000..a96f439 --- /dev/null +++ b/fastcharge/FastCharge.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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. + */ + +#pragma once + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace fastcharge { +namespace V1_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; + +using ::vendor::lineage::fastcharge::V1_0::IFastCharge; + +struct FastCharge : public IFastCharge { + FastCharge(); + + Return isEnabled() override; + Return setEnabled(bool enable) override; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace fastcharge +} // namespace lineage +} // namespace vendor diff --git a/fastcharge/service.cpp b/fastcharge/service.cpp new file mode 100644 index 0000000..e60ac07 --- /dev/null +++ b/fastcharge/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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 "fastcharge@1.0-service.stone" + +#include +#include + +#include "FastCharge.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +using vendor::lineage::fastcharge::V1_0::IFastCharge; +using vendor::lineage::fastcharge::V1_0::implementation::FastCharge; + +using android::OK; +using android::status_t; + +int main() { + android::sp service = new FastCharge(); + + configureRpcThreadpool(1, true); + + status_t status = service->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Cannot register FastCharge HAL service."; + return 1; + } + + LOG(INFO) << "FastCharge HAL service ready."; + + joinRpcThreadpool(); + + LOG(ERROR) << "FastCharge HAL service failed to join thread pool."; + return 1; +} diff --git a/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.rc b/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.rc new file mode 100644 index 0000000..f1fd6cb --- /dev/null +++ b/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.rc @@ -0,0 +1,10 @@ +service vendor.fastcharge-hal-1-0 /vendor/bin/hw/vendor.lineage.fastcharge@1.0-service.stone + class hal + user system + group system + +on property:persist.vendor.sec.fastchg_enabled=true + start batterysecret + +on property:persist.vendor.sec.fastchg_enabled=false + stop batterysecret diff --git a/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.xml b/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.xml new file mode 100644 index 0000000..0c55ea5 --- /dev/null +++ b/fastcharge/vendor.lineage.fastcharge@1.0-service.stone.xml @@ -0,0 +1,11 @@ + + + vendor.lineage.fastcharge + hwbinder + 1.0 + + IFastCharge + default + + + diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 56e37cf..780d94b 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -110,6 +110,9 @@ /sys/devices/platform/soc/soc:simtray/status u:object_r:sysfs_simtray_status:s0 /sys/devices/platform/soc/4c88000.i2c/i2c-2/2-0038/fts_edge_mode u:object_r:vendor_sysfs_sensors:s0 +# Fastcharge HAL +/(vendor|system/vendor)/bin/hw/vendor\.lineage\.fastcharge@[0-9]\.[0-9]-service\.stone u:object_r:hal_lineage_fastcharge_default_exec:s0 + # Fingerprint /dev/goodix_fp u:object_r:fingerprint_device:s0 /dev/silead_fp u:object_r:fingerprint_device:s0 diff --git a/sepolicy/vendor/hal_lineage_fastcharge_default.te b/sepolicy/vendor/hal_lineage_fastcharge_default.te new file mode 100644 index 0000000..7967ede --- /dev/null +++ b/sepolicy/vendor/hal_lineage_fastcharge_default.te @@ -0,0 +1,9 @@ +get_prop(hal_lineage_fastcharge, vendor_fastcharge_prop) +set_prop(hal_lineage_fastcharge, vendor_fastcharge_prop) + +# Fast Charge Node Service Permissions +allow hal_lineage_fastcharge_default sysfs_battery_supply:dir search; +allow hal_lineage_fastcharge_default sysfs_battery_supply:file rw_file_perms; + +allow hal_lineage_fastcharge_default vendor_sysfs_battery_supply:dir search; +allow hal_lineage_fastcharge_default vendor_sysfs_battery_supply:file rw_file_perms; diff --git a/sepolicy/vendor/property.te b/sepolicy/vendor/property.te index 63d6625..b1d5e1e 100644 --- a/sepolicy/vendor/property.te +++ b/sepolicy/vendor/property.te @@ -1,6 +1,9 @@ # Aware vendor_restricted_prop(vendor_aware_available_prop); +# Fastcharge +vendor_internal_prop(vendor_fastcharge_prop); + # Fingerprint vendor_restricted_prop(vendor_fingerprint_prop) diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts index 2459b3e..dec396f 100644 --- a/sepolicy/vendor/property_contexts +++ b/sepolicy/vendor/property_contexts @@ -13,6 +13,9 @@ vendor.camera.aux.packageblacklist u:object_r:vendor_camera_prop:s0 vendor.camera.config. u:object_r:vendor_camera_prop:s0 vendor.camera.sensor. u:object_r:vendor_camera_prop:s0 +# Fastcharge HAL +persist.vendor.sec.fastchg_enabled u:object_r:vendor_fastcharge_prop:s0 + # Fingerprint persist.vendor.sys.fp. u:object_r:vendor_fingerprint_prop:s0 ro.hardware.fp. u:object_r:vendor_fingerprint_prop:s0 diff --git a/vintf/framework_compatibility_matrix.xml b/vintf/framework_compatibility_matrix.xml index 891bcff..a3501c4 100644 --- a/vintf/framework_compatibility_matrix.xml +++ b/vintf/framework_compatibility_matrix.xml @@ -15,6 +15,15 @@ default + + vendor.lineage.fastcharge + hwbinder + 1.0 + + IFastCharge + default + + android.hardware.gnss 1.0-1