mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 11:55:31 -04:00
universal7885: parts-aidl: Move smartcharge code to one file
This commit is contained in:
parent
c08e8f7fdc
commit
d9adb63d29
5 changed files with 22 additions and 87 deletions
|
|
@ -164,7 +164,6 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
|||
mPoolExecutor.scheduleWithFixedDelay(mScheduler, 0, 5, TimeUnit.MINUTES)
|
||||
} else {
|
||||
mSmartCharge.stop()
|
||||
mPoolExecutor.shutdown()
|
||||
}
|
||||
mSharedPreferences.edit().putBoolean(PREF_SMARTCHARGE_MAIN, isChecked).apply()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ cc_binary {
|
|||
"Display.cpp",
|
||||
"Swap.cpp",
|
||||
"SwapHelpers.cpp",
|
||||
"SmartChargingImpl.cpp",
|
||||
"SmartCharge.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -13,37 +13,46 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "SmartCharge.h"
|
||||
#include "SmartChargingImpl.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static SmartChargeImpl *kInst;
|
||||
|
||||
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) {
|
||||
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
||||
if (batt >= limit) {
|
||||
FileIO::writeline(BATTERY_CHARGE, 0);
|
||||
limit_stat += 1;
|
||||
} else if (batt <= restart) {
|
||||
FileIO::writeline(BATTERY_CHARGE, 1);
|
||||
restart_stat += 1;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::start(void) {
|
||||
if (limit == 0 || restart == 0)
|
||||
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
||||
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
||||
kInst = new SmartChargeImpl(limit, restart);
|
||||
kInst->start();
|
||||
|
||||
monitor_th = std::thread(battery_monitor);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
||||
if (kInst != nullptr) {
|
||||
kInst->stop();
|
||||
limit_stat += kInst->charge_limit_cnt;
|
||||
restart_stat += kInst->restart_cnt;
|
||||
delete kInst;
|
||||
kInst = nullptr;
|
||||
if (monitor_th != nullptr) {
|
||||
monitor_th = nullptr;
|
||||
}
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
#include "SmartChargingImpl.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static std::thread *monitor;
|
||||
static bool shouldRun = false;
|
||||
|
||||
SmartChargeImpl::SmartChargeImpl(int limit, int restart)
|
||||
: limit_percent(limit), restart_percent(restart) {
|
||||
charge_limit_cnt = 0;
|
||||
restart_cnt = 0;
|
||||
}
|
||||
|
||||
static void battery_monitor(const int limit_percent, const int restart_percent,
|
||||
int *charge_limit_cnt, int *restart_cnt) {
|
||||
while (shouldRun) {
|
||||
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
||||
if (batt >= limit_percent) {
|
||||
disableSysfs(BATTERY_CHARGE);
|
||||
*charge_limit_cnt += 1;
|
||||
} else if (batt <= restart_percent) {
|
||||
enableSysfs(BATTERY_CHARGE);
|
||||
*restart_cnt += 1;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
void SmartChargeImpl::start(void) {
|
||||
shouldRun = true;
|
||||
monitor = new std::thread(battery_monitor, limit_percent, restart_percent,
|
||||
&charge_limit_cnt, &restart_cnt);
|
||||
}
|
||||
|
||||
void SmartChargeImpl::stop(void) {
|
||||
shouldRun = false;
|
||||
monitor = nullptr;
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#include "BatteryConstants.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
class SmartChargeImpl {
|
||||
public:
|
||||
SmartChargeImpl(int limit, int restart);
|
||||
void start(void);
|
||||
void stop(void);
|
||||
|
||||
int charge_limit_cnt;
|
||||
int restart_cnt;
|
||||
|
||||
private:
|
||||
const int limit_percent;
|
||||
const int restart_percent;
|
||||
};
|
||||
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
||||
static inline void disableSysfs(const char *path) {
|
||||
FileIO::writeline(path, 0);
|
||||
}
|
||||
|
||||
static inline void enableSysfs(const char *path) { FileIO::writeline(path, 1); }
|
||||
Loading…
Reference in a new issue