tulip: Implement FastCharge HAL
This HAL makes use of the sysfs attribute /sys/class/qcom-battery/restricted_charging to control whether fast charging is allowed or not. When fast charging is disabled (i.e. 1 is written to the sysfs attribute), current is restricted to 1 A (the value at /sys/class/qcom-battery/restricted_current, in uA). This has been tested on the Nokia 6.1 (PL2); however, it should work on other Nokia SDM660 devices as well since they share the same kernel source. Adapted from the work at android_hardware_samsung: https://github.com/LineageOS/android_hardware_samsung/tree/lineage-20/hidl/fastcharge FastCharge interface definition: https://github.com/LineageOS/android_hardware_lineage_interfaces/tree/lineage-20.0/fastcharge/1.0 Change-Id: I78ce842ef6263c19088f29a40abfa1ef6534cc99 Signed-off-by: Le Hong Duc <hongducthbk123@gmail.com>
This commit is contained in:
committed by
Le Hong Duc
parent
659cd6cc5d
commit
ba258af5cf
@@ -205,6 +205,10 @@ PRODUCT_COPY_FILES += \
|
||||
PRODUCT_PACKAGES += \
|
||||
fastbootd
|
||||
|
||||
# Fast Charge HAL
|
||||
PRODUCT_PACKAGES += \
|
||||
vendor.lineage.fastcharge@1.0-service.qcom
|
||||
|
||||
# FM
|
||||
PRODUCT_PACKAGES += \
|
||||
FM2 \
|
||||
|
||||
34
fastcharge/1.0/Android.bp
Normal file
34
fastcharge/1.0/Android.bp
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// 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.
|
||||
|
||||
cc_binary {
|
||||
name: "vendor.lineage.fastcharge@1.0-service.qcom",
|
||||
relative_install_path: "hw",
|
||||
proprietary: true,
|
||||
srcs: [
|
||||
"FastCharge.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
init_rc: [ "vendor.lineage.fastcharge@1.0-service.qcom.rc" ],
|
||||
vintf_fragments: [ "vendor.lineage.fastcharge@1.0-service.qcom.xml" ],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"libutils",
|
||||
"vendor.lineage.fastcharge@1.0",
|
||||
],
|
||||
}
|
||||
100
fastcharge/1.0/FastCharge.cpp
Normal file
100
fastcharge/1.0/FastCharge.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2020-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"
|
||||
#define FASTCHARGE_PATH "/sys/class/qcom-battery/restricted_charging"
|
||||
#define FASTCHARGE_DEFAULT_SETTING true
|
||||
|
||||
#include "FastCharge.h"
|
||||
#include <android-base/logging.h>
|
||||
#include <cutils/properties.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace vendor {
|
||||
namespace lineage {
|
||||
namespace fastcharge {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
static constexpr const char* kFastChargingProp = "persist.vendor.fastchg_enabled";
|
||||
|
||||
/*
|
||||
* Write value to path and close file.
|
||||
*/
|
||||
template <typename T>
|
||||
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 <typename T>
|
||||
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<bool> FastCharge::isEnabled() {
|
||||
return get(FASTCHARGE_PATH, 0) < 1;
|
||||
}
|
||||
|
||||
Return<bool> 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
|
||||
51
fastcharge/1.0/FastCharge.h
Normal file
51
fastcharge/1.0/FastCharge.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020-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 <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <vendor/lineage/fastcharge/1.0/IFastCharge.h>
|
||||
|
||||
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<bool> isEnabled() override;
|
||||
Return<bool> setEnabled(bool enable) override;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace fastcharge
|
||||
} // namespace lineage
|
||||
} // namespace vendor
|
||||
50
fastcharge/1.0/service.cpp
Normal file
50
fastcharge/1.0/service.cpp
Normal file
@@ -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"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#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<FastCharge> 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;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
service vendor.fastcharge-hal-1-0 /vendor/bin/hw/vendor.lineage.fastcharge@1.0-service.qcom
|
||||
class hal
|
||||
@@ -0,0 +1,11 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<name>vendor.lineage.fastcharge</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.0</version>
|
||||
<interface>
|
||||
<name>IFastCharge</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
||||
3
sepolicy/vendor/file_contexts
vendored
3
sepolicy/vendor/file_contexts
vendored
@@ -53,3 +53,6 @@
|
||||
|
||||
# Thermal
|
||||
/(vendor|system/vendor)/bin/hw/android\.hardware\.thermal@2\.0-service\.mock u:object_r:hal_thermal_default_exec:s0
|
||||
|
||||
# Fast Charge HAL
|
||||
/vendor/bin/hw/vendor\.lineage\.fastcharge@1\.0-service\.qcom u:object_r:hal_lineage_fastcharge_default_exec:s0
|
||||
|
||||
6
sepolicy/vendor/hal_fastcharge_default.te
vendored
Normal file
6
sepolicy/vendor/hal_fastcharge_default.te
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Allow read/write access to /sys/class/qcom-battery/.*
|
||||
allow hal_lineage_fastcharge_default sysfs_battery_supply:file rw_file_perms;
|
||||
allow hal_lineage_fastcharge_default sysfs_battery_supply:dir search;
|
||||
|
||||
# Allow control of sysprop persist.vendor.fastchg_enabled
|
||||
set_prop(hal_lineage_fastcharge_default, vendor_fastcharge_prop)
|
||||
3
sepolicy/vendor/property.te
vendored
3
sepolicy/vendor/property.te
vendored
@@ -2,3 +2,6 @@ vendor_public_prop(hal_fingerprint_prop);
|
||||
vendor_public_prop(mlipay_prop);
|
||||
vendor_internal_prop(thermal_engine_prop);
|
||||
vendor_internal_prop(vendor_power_prop);
|
||||
|
||||
# For Fast Charge HAL
|
||||
vendor_internal_prop(vendor_fastcharge_prop)
|
||||
|
||||
3
sepolicy/vendor/property_contexts
vendored
3
sepolicy/vendor/property_contexts
vendored
@@ -66,3 +66,6 @@ persist.vendor.wigig.npt.enable u:object_r:vendor_default_prop:s0
|
||||
|
||||
# Fastbootd
|
||||
ro.fastbootd.available u:object_r:exported_default_prop:s0
|
||||
|
||||
# Fast Charge
|
||||
persist.vendor.fastchg_enabled u:object_r:vendor_fastcharge_prop:s0
|
||||
|
||||
Reference in New Issue
Block a user