From 2d0db296299c882ec1a9bd8dff37890bd2b34900 Mon Sep 17 00:00:00 2001 From: kamikaonashi Date: Sun, 12 May 2024 14:10:48 +0200 Subject: [PATCH] stone: fastcharge: adapt for stone since our device doesnt have a fastcharge path (due to broken kernel source), we just adapt and stop and start batteryservice. rewritten to do exactly that Signed-off-by: Arijit78 --- fastcharge/FastCharge.cpp | 80 ++++++++++----------------------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/fastcharge/FastCharge.cpp b/fastcharge/FastCharge.cpp index 1b494d3..637935e 100644 --- a/fastcharge/FastCharge.cpp +++ b/fastcharge/FastCharge.cpp @@ -16,18 +16,10 @@ #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 +#include +#include +#include "FastCharge.h" namespace vendor { namespace lineage { @@ -35,63 +27,29 @@ 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; - } -} +static constexpr const char *kFastChargingProp = "persist.vendor.sec.fastchg_enabled"; +static constexpr bool FASTCHARGE_DEFAULT_SETTING = true; FastCharge::FastCharge() { - setEnabled(property_get_bool(kFastChargingProp, FASTCHARGE_DEFAULT_SETTING)); + android::base::SetProperty(kFastChargingProp, "true"); + + system("start batterysecret"); } -Return FastCharge::isEnabled() { return get(FASTCHARGE_PATH, 0) < 1; } +android::hardware::Return FastCharge::isEnabled() { + return android::hardware::Return(android::base::GetBoolProperty(kFastChargingProp, false)); +} -Return FastCharge::setEnabled(bool enable) { - set(FASTCHARGE_PATH, enable ? 0 : 1); +android::hardware::Return FastCharge::setEnabled(bool enable) { + android::base::SetProperty(kFastChargingProp, enable ? "true" : "false"); - bool enabled = isEnabled(); - property_set(kFastChargingProp, enabled ? "true" : "false"); + if (enable) { + system("start batterysecret"); + } else { + system("stop batterysecret"); + } - return enabled; + return android::hardware::Return(enable); } } // namespace implementation