mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 11:55:31 -04:00
universal7885: parts: smartcharge: Fix derps
* Turn on charging back after smartcharge off. * Correct onclick listener on smartcharge settings * Only write to charge sysfs once
This commit is contained in:
parent
e92f502522
commit
5b75120653
3 changed files with 29 additions and 17 deletions
|
|
@ -36,7 +36,7 @@ import com.eurekateam.samsungextras.interfaces.SmartCharge
|
|||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener, View.OnClickListener, Preference.OnPreferenceChangeListener, SelectorWithWidgetPreference.OnClickListener {
|
||||
class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener, Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener, SelectorWithWidgetPreference.OnClickListener {
|
||||
private lateinit var mLimit: SelectorWithWidgetPreference
|
||||
private lateinit var mRestart: SelectorWithWidgetPreference
|
||||
private lateinit var mSharedPreferences: SharedPreferences
|
||||
|
|
@ -67,7 +67,7 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
|||
mRestartStat = findPreference(PREF_RESTART_STAT)!!
|
||||
mApplyBtn = findPreference(PREF_APPLY)!!
|
||||
|
||||
mApplyBtn.setOnClickListener(this)
|
||||
mApplyBtn.setOnPreferenceClickListener(this)
|
||||
mApplyBtn.isEnabled = false
|
||||
mSmartChargeBtn.addOnSwitchChangeListener(this)
|
||||
mSmartChargeBtn.isChecked = mSharedPreferences.getBoolean(PREF_SMARTCHARGE_MAIN, false)
|
||||
|
|
@ -137,10 +137,10 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
|||
return false
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v == mApplyBtn) {
|
||||
val limit = mSharedPreferences.getInt(PREF_LIMIT, 20)
|
||||
val restart = mSharedPreferences.getInt(PREF_RESTART, 80)
|
||||
override fun onPreferenceClick(pref : Preference) {
|
||||
if (pref == mApplyBtn) {
|
||||
val limit = mSharedPreferences.getInt(PREF_LIMIT, 80)
|
||||
val restart = mSharedPreferences.getInt(PREF_RESTART, 20)
|
||||
if (limit > restart) {
|
||||
mSmartCharge.setConfig(limit, restart)
|
||||
mMainHandler.post({ mSmartChargeBtn.isEnabled = true })
|
||||
|
|
|
|||
|
|
@ -15,30 +15,28 @@
|
|||
#include "SmartCharge.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <FileIO.h>
|
||||
#include "BatteryConstants.h"
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static int limit = 0;
|
||||
static int restart = 0;
|
||||
|
||||
static int limit_stat = 0;
|
||||
static int restart_stat = 0;
|
||||
|
||||
static std::thread *monitor_th = nullptr;
|
||||
|
||||
static void battery_monitor(void) {
|
||||
while (true) {
|
||||
void SmartCharge::battery_monitor(void) {
|
||||
while (kShouldRun) {
|
||||
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
||||
if (batt >= limit) {
|
||||
if (kTookAction) goto sleep;
|
||||
FileIO::writeline(BATTERY_CHARGE, 0);
|
||||
kTookAction = true;
|
||||
limit_stat += 1;
|
||||
} else if (batt <= restart) {
|
||||
if (kTookAction) goto sleep;
|
||||
FileIO::writeline(BATTERY_CHARGE, 1);
|
||||
kTookAction = true;
|
||||
restart_stat += 1;
|
||||
} else {
|
||||
kTookAction = false;
|
||||
}
|
||||
sleep:
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
|
@ -48,14 +46,17 @@ static void battery_monitor(void) {
|
|||
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
||||
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
||||
|
||||
kShouldRun = true;
|
||||
monitor_th = new std::thread(battery_monitor);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
||||
kShouldRun = false;
|
||||
if (monitor_th != nullptr) {
|
||||
monitor_th = nullptr;
|
||||
}
|
||||
FileIO::writeline(BATTERY_CHARGE, 1);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <aidl/vendor/eureka/hardware/parts/BnSmartCharge.h>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct SmartCharge : public BnSmartCharge {
|
||||
public:
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::ISmartCharge
|
||||
// follow.
|
||||
::ndk::ScopedAStatus start(void);
|
||||
|
|
@ -26,5 +28,14 @@ struct SmartCharge : public BnSmartCharge {
|
|||
::ndk::ScopedAStatus setConfig(int32_t limit, int32_t restart);
|
||||
::ndk::ScopedAStatus getLimitCnt(int32_t *_aidl_return);
|
||||
::ndk::ScopedAStatus getRestartCnt(int32_t *_aidl_return);
|
||||
private:
|
||||
int limit;
|
||||
int restart;
|
||||
int limit_stat;
|
||||
int restart_stat;
|
||||
bool kShouldRun;
|
||||
bool kTookAction;
|
||||
std::thread *monitor_th;
|
||||
void battery_monitor(void);
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
|
|||
Loading…
Reference in a new issue