mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -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)
|
mPoolExecutor.scheduleWithFixedDelay(mScheduler, 0, 5, TimeUnit.MINUTES)
|
||||||
} else {
|
} else {
|
||||||
mSmartCharge.stop()
|
mSmartCharge.stop()
|
||||||
mPoolExecutor.shutdown()
|
|
||||||
}
|
}
|
||||||
mSharedPreferences.edit().putBoolean(PREF_SMARTCHARGE_MAIN, isChecked).apply()
|
mSharedPreferences.edit().putBoolean(PREF_SMARTCHARGE_MAIN, isChecked).apply()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ cc_binary {
|
||||||
"Display.cpp",
|
"Display.cpp",
|
||||||
"Swap.cpp",
|
"Swap.cpp",
|
||||||
"SwapHelpers.cpp",
|
"SwapHelpers.cpp",
|
||||||
"SmartChargingImpl.cpp",
|
|
||||||
"SmartCharge.cpp",
|
"SmartCharge.cpp",
|
||||||
"service.cpp",
|
"service.cpp",
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -13,37 +13,46 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "SmartCharge.h"
|
#include "SmartCharge.h"
|
||||||
#include "SmartChargingImpl.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <thread>
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::parts {
|
namespace aidl::vendor::eureka::hardware::parts {
|
||||||
|
|
||||||
static SmartChargeImpl *kInst;
|
|
||||||
|
|
||||||
static int limit = 0;
|
static int limit = 0;
|
||||||
static int restart = 0;
|
static int restart = 0;
|
||||||
|
|
||||||
static int limit_stat = 0;
|
static int limit_stat = 0;
|
||||||
static int restart_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) {
|
::ndk::ScopedAStatus SmartCharge::start(void) {
|
||||||
if (limit == 0 || restart == 0)
|
if (limit == 0 || restart == 0)
|
||||||
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
||||||
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
||||||
kInst = new SmartChargeImpl(limit, restart);
|
|
||||||
kInst->start();
|
monitor_th = std::thread(battery_monitor);
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
||||||
if (kInst != nullptr) {
|
if (monitor_th != nullptr) {
|
||||||
kInst->stop();
|
monitor_th = nullptr;
|
||||||
limit_stat += kInst->charge_limit_cnt;
|
|
||||||
restart_stat += kInst->restart_cnt;
|
|
||||||
delete kInst;
|
|
||||||
kInst = nullptr;
|
|
||||||
}
|
}
|
||||||
return ::ndk::ScopedAStatus::ok();
|
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