From 02138ed10ca5ffc708c5981e802a90b46460a9ce Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Mon, 18 Jan 2021 22:31:07 +0000 Subject: [PATCH] fastcharge: Make user setting persistent Change-Id: I4ff051d6f9685e94022eab32035bfe86a65264b8 --- hidl/fastcharge/Android.mk | 3 ++- hidl/fastcharge/FastCharge.cpp | 15 +++++++++++++-- hidl/fastcharge/FastCharge.h | 4 +++- hidl/fastcharge/include/samsung_fastcharge.h | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/hidl/fastcharge/Android.mk b/hidl/fastcharge/Android.mk index 6401fabb..ba8b2680 100644 --- a/hidl/fastcharge/Android.mk +++ b/hidl/fastcharge/Android.mk @@ -1,5 +1,5 @@ # -# Copyright (C) 2020 The LineageOS Project +# Copyright (C) 2020-2021 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. @@ -28,6 +28,7 @@ LOCAL_C_INCLUDES := \ LOCAL_SHARED_LIBRARIES := \ libbase \ libbinder \ + libcutils \ libhidlbase \ libutils \ vendor.lineage.fastcharge@1.0 diff --git a/hidl/fastcharge/FastCharge.cpp b/hidl/fastcharge/FastCharge.cpp index f0402163..283b85b3 100644 --- a/hidl/fastcharge/FastCharge.cpp +++ b/hidl/fastcharge/FastCharge.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The LineageOS Project + * Copyright (C) 2020-2021 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. @@ -18,6 +18,8 @@ #include "FastCharge.h" #include +#include + #include #include #include "samsung_fastcharge.h" @@ -28,6 +30,8 @@ namespace fastcharge { namespace V1_0 { namespace implementation { +static constexpr const char* kFastChargingProp = "persist.vendor.sec.fastchg_enabled"; + /* * Write value to path and close file. */ @@ -71,6 +75,10 @@ static T get(const std::string& path, const T& def) { } } +FastCharge::FastCharge() { + setEnabled(property_get_bool(kFastChargingProp, FASTCHARGE_DEFAULT_SETTING)); +} + Return FastCharge::isEnabled() { return get(FASTCHARGE_PATH, 0) < 1; } @@ -78,7 +86,10 @@ Return FastCharge::isEnabled() { Return 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 diff --git a/hidl/fastcharge/FastCharge.h b/hidl/fastcharge/FastCharge.h index ae4d0495..2d5a6536 100644 --- a/hidl/fastcharge/FastCharge.h +++ b/hidl/fastcharge/FastCharge.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The LineageOS Project + * Copyright (C) 2020-2021 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. @@ -39,6 +39,8 @@ using ::vendor::lineage::fastcharge::V1_0::IFastCharge; struct FastCharge : public IFastCharge { + FastCharge(); + Return isEnabled() override; Return setEnabled(bool enable) override; }; diff --git a/hidl/fastcharge/include/samsung_fastcharge.h b/hidl/fastcharge/include/samsung_fastcharge.h index e38c190f..1eec1296 100644 --- a/hidl/fastcharge/include/samsung_fastcharge.h +++ b/hidl/fastcharge/include/samsung_fastcharge.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The LineageOS Project + * Copyright (C) 2020-2021 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. @@ -17,6 +17,7 @@ #ifndef SAMSUNG_FASTCHARGE_H #define SAMSUNG_FASTCHARGE_H +#define FASTCHARGE_DEFAULT_SETTING true #define FASTCHARGE_PATH "/sys/class/sec/switch/afc_disable" #endif // SAMSUNG_FASTCHARGE_H