mirror of
https://github.com/Evolution-X-Devices/device_xiaomi_sapphire
synced 2026-01-27 18:16:34 +00:00
* Disabling fast charge may be useful for reducing the heat produced by the device while charging, or for extending the lifespan of the battery
* This commit introduces the fastcharge HIDL, which writes in the node
/sys/class/qcom-battery/restrict_chg
0 or 1 depeding on user selection.
0 means that fastcharge is enabled, while 1 means that fastcharge is
disabled
Change-Id: I369ba9c437b3a83a88c2ce74d603b7d7ddd9cfbb
Signed-off-by: Davide Garberi <dade.garberi@gmail.com>
Signed-off-by: althafvly <althafvly@gmail.com>
Signed-off-by: NotZeetaa <rodrigo2005contente@gmail.com>
Signed-off-by: kibria5 <mdkibria687@gmail.com>
86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
/*
|
|
* 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.xiaomi_sm6225"
|
|
|
|
#define FASTCHARGE_PATH "/sys/class/qcom-battery/restrict_chg"
|
|
|
|
#include "FastCharge.h"
|
|
#include <android-base/logging.h>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
namespace vendor {
|
|
namespace lineage {
|
|
namespace fastcharge {
|
|
namespace V1_0 {
|
|
namespace implementation {
|
|
|
|
/*
|
|
* 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;
|
|
}
|
|
}
|
|
|
|
Return<bool> FastCharge::isEnabled() { return get(FASTCHARGE_PATH, 0) < 1; }
|
|
|
|
Return<bool> FastCharge::setEnabled(bool enable) {
|
|
set(FASTCHARGE_PATH, enable ? 0 : 1);
|
|
|
|
return isEnabled();
|
|
}
|
|
|
|
} // namespace implementation
|
|
} // namespace V1_0
|
|
} // namespace fastcharge
|
|
} // namespace lineage
|
|
} // namespace vendor
|