fastcharge: Make user setting persistent

Change-Id: I4ff051d6f9685e94022eab32035bfe86a65264b8
tirimbino
Bruno Martins 4 years ago
parent 6d4c3dc374
commit 02138ed10c
  1. 3
      hidl/fastcharge/Android.mk
  2. 15
      hidl/fastcharge/FastCharge.cpp
  3. 4
      hidl/fastcharge/FastCharge.h
  4. 3
      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"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ LOCAL_C_INCLUDES := \
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libbase \ libbase \
libbinder \ libbinder \
libcutils \
libhidlbase \ libhidlbase \
libutils \ libutils \
vendor.lineage.fastcharge@1.0 vendor.lineage.fastcharge@1.0

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
#include "FastCharge.h" #include "FastCharge.h"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <cutils/properties.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include "samsung_fastcharge.h" #include "samsung_fastcharge.h"
@ -28,6 +30,8 @@ namespace fastcharge {
namespace V1_0 { namespace V1_0 {
namespace implementation { namespace implementation {
static constexpr const char* kFastChargingProp = "persist.vendor.sec.fastchg_enabled";
/* /*
* Write value to path and close file. * 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<bool> FastCharge::isEnabled() { Return<bool> FastCharge::isEnabled() {
return get(FASTCHARGE_PATH, 0) < 1; return get(FASTCHARGE_PATH, 0) < 1;
} }
@ -78,7 +86,10 @@ Return<bool> FastCharge::isEnabled() {
Return<bool> FastCharge::setEnabled(bool enable) { Return<bool> FastCharge::setEnabled(bool enable) {
set(FASTCHARGE_PATH, enable ? 0 : 1); set(FASTCHARGE_PATH, enable ? 0 : 1);
return isEnabled(); bool enabled = isEnabled();
property_set(kFastChargingProp, enabled ? "true" : "false");
return enabled;
} }
} // namespace implementation } // namespace implementation

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { struct FastCharge : public IFastCharge {
FastCharge();
Return<bool> isEnabled() override; Return<bool> isEnabled() override;
Return<bool> setEnabled(bool enable) override; Return<bool> setEnabled(bool enable) override;
}; };

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
#ifndef SAMSUNG_FASTCHARGE_H #ifndef SAMSUNG_FASTCHARGE_H
#define SAMSUNG_FASTCHARGE_H #define SAMSUNG_FASTCHARGE_H
#define FASTCHARGE_DEFAULT_SETTING true
#define FASTCHARGE_PATH "/sys/class/sec/switch/afc_disable" #define FASTCHARGE_PATH "/sys/class/sec/switch/afc_disable"
#endif // SAMSUNG_FASTCHARGE_H #endif // SAMSUNG_FASTCHARGE_H

Loading…
Cancel
Save