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 <sahaarijit2007@gmail.com>
This commit is contained in:
kamikaonashi
2024-05-12 14:10:48 +02:00
committed by Arijit78
parent 60e7152649
commit 2d0db29629

View File

@@ -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 <android-base/logging.h>
#include <cutils/properties.h>
#include <fstream>
#include <iostream>
#include <android-base/properties.h>
#include <cstdlib>
#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 <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;
}
}
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<bool> FastCharge::isEnabled() { return get(FASTCHARGE_PATH, 0) < 1; }
android::hardware::Return<bool> FastCharge::isEnabled() {
return android::hardware::Return<bool>(android::base::GetBoolProperty(kFastChargingProp, false));
}
Return<bool> FastCharge::setEnabled(bool enable) {
set(FASTCHARGE_PATH, enable ? 0 : 1);
android::hardware::Return<bool> 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<bool>(enable);
}
} // namespace implementation