mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 19:55:33 -04:00
universal7885: parts: Use isMutexLocked() to disable switch if needed
This commit is contained in:
parent
b226436fc7
commit
c12209095a
4 changed files with 9 additions and 2 deletions
|
|
@ -29,6 +29,7 @@ class Swap {
|
|||
fun setSwapOn(mEnabled: Boolean) = if (mEnabled) mSwap.setSwapOn() else mSwap.setSwapOff()
|
||||
fun mkFile(mSize: Int) = mSwap.makeSwapFile(mSize)
|
||||
fun delFile() = mSwap.removeSwapFile()
|
||||
fun isLocked() : Boolean = mSwap.isMutexLocked()
|
||||
external fun getFreeSpace(): Double
|
||||
external fun getSwapSize(): Long
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import com.android.settingslib.widget.OnMainSwitchChangeListener
|
|||
import com.eurekateam.samsungextras.R
|
||||
import com.eurekateam.samsungextras.interfaces.Swap
|
||||
import java.lang.Thread
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
|
||||
private lateinit var mSwapSizePref: SeekBarPreference
|
||||
|
|
@ -36,6 +38,7 @@ class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeLi
|
|||
private lateinit var mSwapEnable: MainSwitchPreference
|
||||
private lateinit var mFreeSpace: Preference
|
||||
private lateinit var mSwapFileSize: Preference
|
||||
private var mPoolExecutor = ScheduledThreadPoolExecutor(3)
|
||||
private var mSwapSize = 0
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
|
@ -55,8 +58,11 @@ class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeLi
|
|||
mFreeSpace.summary = "${mSwap.getFreeSpace()} GB"
|
||||
mSwapFileSize = findPreference(INFO_SWAP_FILE_SIZE)!!
|
||||
mSwapFileSize.summary = "${mSwap.getSwapSize()} MB"
|
||||
mPoolExecutor.scheduleWithFixedDelay(mScheduler, 0, 2, TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
private val mScheduler = Runnable { requireActivity().runOnUiThread { mSwapEnable.isEnabled = !mSwap.isLocked() } }
|
||||
|
||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
||||
val mSwap = Swap()
|
||||
if (preference == mSwapSizePref) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ void SmartChargeImpl::start(void) {
|
|||
shouldRun = true;
|
||||
monitor = new std::thread(battery_monitor, limit_percent, restart_percent,
|
||||
&charge_limit_cnt, &restart_cnt);
|
||||
monitor->join();
|
||||
monitor->detach();
|
||||
}
|
||||
|
||||
void SmartChargeImpl::stop(void) {
|
||||
|
|
|
|||
|
|
@ -75,12 +75,12 @@ static void swapon_func(void) {
|
|||
}
|
||||
|
||||
static void swapoff_func(void) {
|
||||
if (!swapfile_exist()) return;
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
swapoff(SWAP_PATH);
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapOff() {
|
||||
if (!swapfile_exist()) return ::ndk::ScopedAStatus::ok();
|
||||
std::thread swapoff_thread(swapoff_func);
|
||||
swapoff_thread.detach();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
|
|
|
|||
Loading…
Reference in a new issue