sapphire: fastcharge: Make user setting persistent

Change-Id: I4ff051d6f9685e94022eab32035bfe86a65264b8
Signed-off-by: Davide Garberi <dade.garberi@gmail.com>
Signed-off-by: NotZeetaa <rodrigo2005contente@gmail.com>
Signed-off-by: kibria5 <mdkibria687@gmail.com>
This commit is contained in:
Bruno Martins
2021-01-18 22:31:07 +00:00
committed by kibria5
parent c5b608a66d
commit aa1b7fbe84
3 changed files with 17 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES := \
libbase \
libbinder \
libcutils \
libhidlbase \
libutils \
vendor.lineage.fastcharge@1.0

View File

@@ -16,10 +16,13 @@
#define LOG_TAG "fastcharge@1.0-service.xiaomi_sm6225"
#define FASTCHARGE_DEFAULT_SETTING true
#define FASTCHARGE_PATH "/sys/class/qcom-battery/restrict_chg"
#include "FastCharge.h"
#include <android-base/logging.h>
#include <cutils/properties.h>
#include <fstream>
#include <iostream>
@@ -29,6 +32,9 @@ namespace fastcharge {
namespace V1_0 {
namespace implementation {
static constexpr const char *kFastChargingProp =
"persist.vendor.sec.fastchg_enabled";
/*
* Write value to path and close file.
*/
@@ -70,12 +76,19 @@ template <typename T> static T get(const std::string &path, const T &def) {
}
}
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);
return isEnabled();
bool enabled = isEnabled();
property_set(kFastChargingProp, enabled ? "true" : "false");
return enabled;
}
} // namespace implementation

View File

@@ -38,6 +38,8 @@ 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;
};