mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-24 04:45:32 -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.ScheduledThreadPoolExecutor
|
||||||
import java.util.concurrent.TimeUnit
|
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 mLimit: SelectorWithWidgetPreference
|
||||||
private lateinit var mRestart: SelectorWithWidgetPreference
|
private lateinit var mRestart: SelectorWithWidgetPreference
|
||||||
private lateinit var mSharedPreferences: SharedPreferences
|
private lateinit var mSharedPreferences: SharedPreferences
|
||||||
|
|
@ -67,7 +67,7 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
mRestartStat = findPreference(PREF_RESTART_STAT)!!
|
mRestartStat = findPreference(PREF_RESTART_STAT)!!
|
||||||
mApplyBtn = findPreference(PREF_APPLY)!!
|
mApplyBtn = findPreference(PREF_APPLY)!!
|
||||||
|
|
||||||
mApplyBtn.setOnClickListener(this)
|
mApplyBtn.setOnPreferenceClickListener(this)
|
||||||
mApplyBtn.isEnabled = false
|
mApplyBtn.isEnabled = false
|
||||||
mSmartChargeBtn.addOnSwitchChangeListener(this)
|
mSmartChargeBtn.addOnSwitchChangeListener(this)
|
||||||
mSmartChargeBtn.isChecked = mSharedPreferences.getBoolean(PREF_SMARTCHARGE_MAIN, false)
|
mSmartChargeBtn.isChecked = mSharedPreferences.getBoolean(PREF_SMARTCHARGE_MAIN, false)
|
||||||
|
|
@ -137,10 +137,10 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onPreferenceClick(pref : Preference) {
|
||||||
if (v == mApplyBtn) {
|
if (pref == mApplyBtn) {
|
||||||
val limit = mSharedPreferences.getInt(PREF_LIMIT, 20)
|
val limit = mSharedPreferences.getInt(PREF_LIMIT, 80)
|
||||||
val restart = mSharedPreferences.getInt(PREF_RESTART, 80)
|
val restart = mSharedPreferences.getInt(PREF_RESTART, 20)
|
||||||
if (limit > restart) {
|
if (limit > restart) {
|
||||||
mSmartCharge.setConfig(limit, restart)
|
mSmartCharge.setConfig(limit, restart)
|
||||||
mMainHandler.post({ mSmartChargeBtn.isEnabled = true })
|
mMainHandler.post({ mSmartChargeBtn.isEnabled = true })
|
||||||
|
|
|
||||||
|
|
@ -15,30 +15,28 @@
|
||||||
#include "SmartCharge.h"
|
#include "SmartCharge.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
|
||||||
#include <FileIO.h>
|
#include <FileIO.h>
|
||||||
#include "BatteryConstants.h"
|
#include "BatteryConstants.h"
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::parts {
|
namespace aidl::vendor::eureka::hardware::parts {
|
||||||
|
|
||||||
static int limit = 0;
|
void SmartCharge::battery_monitor(void) {
|
||||||
static int restart = 0;
|
while (kShouldRun) {
|
||||||
|
|
||||||
static int limit_stat = 0;
|
|
||||||
static int restart_stat = 0;
|
|
||||||
|
|
||||||
static std::thread *monitor_th = nullptr;
|
|
||||||
|
|
||||||
static void battery_monitor(void) {
|
|
||||||
while (true) {
|
|
||||||
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
||||||
if (batt >= limit) {
|
if (batt >= limit) {
|
||||||
|
if (kTookAction) goto sleep;
|
||||||
FileIO::writeline(BATTERY_CHARGE, 0);
|
FileIO::writeline(BATTERY_CHARGE, 0);
|
||||||
|
kTookAction = true;
|
||||||
limit_stat += 1;
|
limit_stat += 1;
|
||||||
} else if (batt <= restart) {
|
} else if (batt <= restart) {
|
||||||
|
if (kTookAction) goto sleep;
|
||||||
FileIO::writeline(BATTERY_CHARGE, 1);
|
FileIO::writeline(BATTERY_CHARGE, 1);
|
||||||
|
kTookAction = true;
|
||||||
restart_stat += 1;
|
restart_stat += 1;
|
||||||
|
} else {
|
||||||
|
kTookAction = false;
|
||||||
}
|
}
|
||||||
|
sleep:
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,14 +46,17 @@ static void battery_monitor(void) {
|
||||||
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
||||||
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
||||||
|
|
||||||
|
kShouldRun = true;
|
||||||
monitor_th = new std::thread(battery_monitor);
|
monitor_th = new std::thread(battery_monitor);
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
||||||
|
kShouldRun = false;
|
||||||
if (monitor_th != nullptr) {
|
if (monitor_th != nullptr) {
|
||||||
monitor_th = nullptr;
|
monitor_th = nullptr;
|
||||||
}
|
}
|
||||||
|
FileIO::writeline(BATTERY_CHARGE, 1);
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <aidl/vendor/eureka/hardware/parts/BnSmartCharge.h>
|
#include <aidl/vendor/eureka/hardware/parts/BnSmartCharge.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::parts {
|
namespace aidl::vendor::eureka::hardware::parts {
|
||||||
|
|
||||||
struct SmartCharge : public BnSmartCharge {
|
struct SmartCharge : public BnSmartCharge {
|
||||||
|
public:
|
||||||
// Methods from ::aidl::vendor::eureka::hardware::parts::ISmartCharge
|
// Methods from ::aidl::vendor::eureka::hardware::parts::ISmartCharge
|
||||||
// follow.
|
// follow.
|
||||||
::ndk::ScopedAStatus start(void);
|
::ndk::ScopedAStatus start(void);
|
||||||
|
|
@ -26,5 +28,14 @@ struct SmartCharge : public BnSmartCharge {
|
||||||
::ndk::ScopedAStatus setConfig(int32_t limit, int32_t restart);
|
::ndk::ScopedAStatus setConfig(int32_t limit, int32_t restart);
|
||||||
::ndk::ScopedAStatus getLimitCnt(int32_t *_aidl_return);
|
::ndk::ScopedAStatus getLimitCnt(int32_t *_aidl_return);
|
||||||
::ndk::ScopedAStatus getRestartCnt(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
|
} // namespace aidl::vendor::eureka::hardware::parts
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue