diff options
| author | LibXZR <i@xzr.moe> | 2022-05-13 19:21:08 +0300 |
|---|---|---|
| committer | Semavi Ulusoy <doc.divxm@gmail.com> | 2022-05-13 19:21:40 +0300 |
| commit | bbd01133b06b71eedd3fb910876ca3f1cd9a9ea5 (patch) | |
| tree | bb1be2486a54bf7a9a7e91763481e4e37412339f | |
| parent | 6453a983f544b40e9f1a6a60c3373e9dc7e465a3 (diff) | |
oneplus_common: Import Optimized Charge control HAL
** make it enable for all Op devices
Signed-off-by: LibXZR <i@xzr.moe>
Signed-off-by: Semavi Ulusoy <doc.divxm@gmail.com>
Change-Id: I1129cefdf23ec623c0df9b9dec23c74d9bd0c0f1
| -rw-r--r-- | hidl/chgctrl/Android.bp | 35 | ||||
| -rw-r--r-- | hidl/chgctrl/ChargeControl.cpp | 95 | ||||
| -rw-r--r-- | hidl/chgctrl/ChargeControl.h | 45 | ||||
| -rw-r--r-- | hidl/chgctrl/service.cpp | 44 | ||||
| -rw-r--r-- | hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.rc | 4 | ||||
| -rw-r--r-- | hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.xml | 11 |
6 files changed, 234 insertions, 0 deletions
diff --git a/hidl/chgctrl/Android.bp b/hidl/chgctrl/Android.bp new file mode 100644 index 0000000..81d11da --- /dev/null +++ b/hidl/chgctrl/Android.bp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Project Kaleidoscope + * + * 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 { + name: "vendor.lineage.chgctrl@1.0-service.oneplus", + init_rc: ["vendor.lineage.chgctrl@1.0-service.oneplus.rc"], + vintf_fragments: ["vendor.lineage.chgctrl@1.0-service.oneplus.xml"], + defaults: ["hidl_defaults"], + relative_install_path: "hw", + srcs: [ + "ChargeControl.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libbinder", + "libhidlbase", + "libutils", + "vendor.lineage.chgctrl@1.0", + ], + proprietary: true, +} diff --git a/hidl/chgctrl/ChargeControl.cpp b/hidl/chgctrl/ChargeControl.cpp new file mode 100644 index 0000000..1d1b05f --- /dev/null +++ b/hidl/chgctrl/ChargeControl.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2022 Project Kaleidoscope + * + * 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 "charge-control-hal" + +#include "ChargeControl.h" +#include <android-base/logging.h> +#include <fcntl.h> + +#define CHARGE_CONTROL_NODE "/sys/class/power_supply/battery/op_disable_charge" +#define CHARGE_ENABLED '0' +#define CHARGE_DISABLED '1' + +namespace vendor::lineage::chgctrl::implementation { + +static int readNode(char& ret) { + int fd; + int err = 0; + + fd = open(CHARGE_CONTROL_NODE, O_RDONLY); + if (fd < 0) + return 1; + + err = read(fd, &ret, sizeof(char)); + close(fd); + + if (err < 0) + return 1; + + return 0; +} + +static int writeNode(char value) { + int fd; + int err = 0; + + fd = open(CHARGE_CONTROL_NODE, O_WRONLY); + if (fd < 0) + return 1; + + err = write(fd, &value, sizeof(char)); + close(fd); + + if (err < 0) + return 1; + + return 0; +} + +// Methods from ::vendor::lineage::chgctrl::V1_0::IChargeControl follow. +Return<bool> ChargeControl::getChargeEnabled() { + char status = 0; + + if (readNode(status)) + LOG(ERROR) << "Unable to get status"; + + if (status == CHARGE_DISABLED) + return false; + + return true; +} + +// Return true on failure +Return<bool> ChargeControl::setChargeEnabled(bool enabled) { + char value; + + if (enabled) + value = CHARGE_ENABLED; + else + value = CHARGE_DISABLED; + + return writeNode(value); +} + + +// Methods from ::android::hidl::base::V1_0::IBase follow. + +//IChargeControl* HIDL_FETCH_IChargeControl(const char* /* name */) { + //return new ChargeControl(); +//} +// +} // namespace vendor::lineage::chgctrl::implementation diff --git a/hidl/chgctrl/ChargeControl.h b/hidl/chgctrl/ChargeControl.h new file mode 100644 index 0000000..3b7f07b --- /dev/null +++ b/hidl/chgctrl/ChargeControl.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 Project Kaleidoscope + * + * 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 <vendor/lineage/chgctrl/1.0/IChargeControl.h> +#include <hidl/MQDescriptor.h> +#include <hidl/Status.h> + +namespace vendor::lineage::chgctrl::implementation { + +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 ::android::sp; + +struct ChargeControl : public V1_0::IChargeControl { + // Methods from ::vendor::lineage::chgctrl::V1_0::IChargeControl follow. + Return<bool> getChargeEnabled() override; + Return<bool> setChargeEnabled(bool enabled) override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. + +}; + +// FIXME: most likely delete, this is only for passthrough implementations +// extern "C" IChargeControl* HIDL_FETCH_IChargeControl(const char* name); + +} // namespace vendor::lineage::chgctrl::implementation diff --git a/hidl/chgctrl/service.cpp b/hidl/chgctrl/service.cpp new file mode 100644 index 0000000..c81e6b4 --- /dev/null +++ b/hidl/chgctrl/service.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 Project Kaleidoscope + * + * 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 "charge-control-hal" + +#include <android-base/logging.h> +#include <android-base/properties.h> +#include <binder/ProcessState.h> +#include <hidl/HidlTransportSupport.h> +#include "ChargeControl.h" + +using vendor::lineage::chgctrl::V1_0::IChargeControl; +using vendor::lineage::chgctrl::implementation::ChargeControl; + +int main() { + android::sp<IChargeControl> service = new ChargeControl(); + + android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service->registerAsService() != android::OK) { + LOG(ERROR) << "Cannot register chgctrl HAL service."; + return 1; + } + + LOG(INFO) << "chgctrl HAL service ready."; + + android::hardware::joinRpcThreadpool(); + + LOG(ERROR) << "chgctrl HAL service failed to join thread pool."; + return 1; +} diff --git a/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.rc b/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.rc new file mode 100644 index 0000000..32119bc --- /dev/null +++ b/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.rc @@ -0,0 +1,4 @@ +service vendor.chgctrl-hal-1-0 /vendor/bin/hw/vendor.lineage.chgctrl@1.0-service.oneplus + class hal + user system + group system diff --git a/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.xml b/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.xml new file mode 100644 index 0000000..354b966 --- /dev/null +++ b/hidl/chgctrl/vendor.lineage.chgctrl@1.0-service.oneplus.xml @@ -0,0 +1,11 @@ +<manifest version="1.0" type="device"> + <hal format="hidl"> + <name>vendor.lineage.chgctrl</name> + <transport>hwbinder</transport> + <version>1.0</version> + <interface> + <name>IChargeControl</name> + <instance>default</instance> + </interface> + </hal> +</manifest> |
