From: Bruno Martins Date: Mon, 18 Jan 2021 22:31:07 +0000 (+0000) Subject: fastcharge: Make user setting persistent X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=02138ed10ca5ffc708c5981e802a90b46460a9ce;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung.git fastcharge: Make user setting persistent Change-Id: I4ff051d6f9685e94022eab32035bfe86a65264b8 --- diff --git a/hidl/fastcharge/Android.mk b/hidl/fastcharge/Android.mk index 6401fab..ba8b268 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 f040216..283b85b 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 ae4d049..2d5a653 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 e38c190..1eec129 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