From 0a612ac913cd87833c1f152948f71beb0d67fdc8 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Wed, 20 Apr 2022 11:31:13 +0900 Subject: [PATCH] universal7885: parts: Show free space and swapfile size --- .../apps/SamsungParts/jni/Storage.cpp | 21 ++++++++++++++ .../apps/SamsungParts/res/values/strings.xml | 3 ++ .../SamsungParts/res/xml/swap_settings.xml | 2 ++ .../eurekateam/samsungextras/BootReceiver.kt | 8 +++--- .../samsungextras/battery/BatteryFragment.kt | 3 +- .../samsungextras/interfaces/Flashlight.kt | 3 +- .../samsungextras/interfaces/Swap.kt | 8 ++++-- .../samsungextras/swap/SwapFragment.kt | 28 ++++++++++++++----- 8 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 universal7885-common/apps/SamsungParts/jni/Storage.cpp diff --git a/universal7885-common/apps/SamsungParts/jni/Storage.cpp b/universal7885-common/apps/SamsungParts/jni/Storage.cpp new file mode 100644 index 0000000..9c8766b --- /dev/null +++ b/universal7885-common/apps/SamsungParts/jni/Storage.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +namespace fs = std::filesystem; + +extern "C" JNIEXPORT jdouble JNICALL +Java_com_eurekateam_samsungextras_interfaces_Swap_getFreeSpace( + JNIEnv *env, jclass clazz) { + fs::space_info data = fs::space("/data"); + auto freespace = data.free / 1024 / 1024; + return static_cast(freespace) / 1024; +} + +extern "C" JNIEXPORT jlong JNICALL +Java_com_eurekateam_samsungextras_interfaces_Swap_getSwapSize( + JNIEnv *env, jclass clazz){ + struct stat stat_buf; + int rc = stat("/data/swap/swapfile", &stat_buf); + return rc == 0 ? stat_buf.st_size / 1024 / 1024 : -1; +} diff --git a/universal7885-common/apps/SamsungParts/res/values/strings.xml b/universal7885-common/apps/SamsungParts/res/values/strings.xml index 6c95597..98f45d8 100644 --- a/universal7885-common/apps/SamsungParts/res/values/strings.xml +++ b/universal7885-common/apps/SamsungParts/res/values/strings.xml @@ -61,6 +61,9 @@ Swap size Adjust the size of swap Creates the swap (not zram) on /data partiton. Useful for low memory devices. + Free space on /data + Swap file size + Misc Toggle for double tap to wake diff --git a/universal7885-common/apps/SamsungParts/res/xml/swap_settings.xml b/universal7885-common/apps/SamsungParts/res/xml/swap_settings.xml index 01ba27f..ffa3b21 100644 --- a/universal7885-common/apps/SamsungParts/res/xml/swap_settings.xml +++ b/universal7885-common/apps/SamsungParts/res/xml/swap_settings.xml @@ -2,5 +2,7 @@ + + diff --git a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/BootReceiver.kt b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/BootReceiver.kt index 1aeb84c..c331dd6 100644 --- a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/BootReceiver.kt +++ b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/BootReceiver.kt @@ -9,11 +9,11 @@ import com.eurekateam.samsungextras.battery.BatteryFragment import com.eurekateam.samsungextras.dolby.DolbyCore import com.eurekateam.samsungextras.dolby.DolbyFragment import com.eurekateam.samsungextras.flashlight.FlashLightFragment -import com.eurekateam.samsungextras.swap.SwapFragment import com.eurekateam.samsungextras.interfaces.Battery import com.eurekateam.samsungextras.interfaces.Display import com.eurekateam.samsungextras.interfaces.Flashlight import com.eurekateam.samsungextras.interfaces.Swap +import com.eurekateam.samsungextras.swap.SwapFragment class BootReceiver : BroadcastReceiver() { override fun onReceive(p0: Context?, p1: Intent?) { @@ -42,9 +42,9 @@ class BootReceiver : BroadcastReceiver() { // FlashLight Flashlight.setFlash(mSharedPreferences.getInt(FlashLightFragment.PREF_FLASHLIGHT, 5)) - // ZRAM - Swap.setSize(mSharedPreferences.getInt(SwapFragment.PREF_SWAP_SIZE, 50)) - Swap.setSwapOn(mSharedPreferences.getBoolean(SwapFragment.PREF_SWAP_ENABLE, false)) + // ZRAM + Swap.setSize(mSharedPreferences.getInt(SwapFragment.PREF_SWAP_SIZE, 50)) + Swap.setSwapOn(mSharedPreferences.getBoolean(SwapFragment.PREF_SWAP_ENABLE, false)) // Display Display.DT2W = mSharedPreferences.getBoolean(DeviceSettings.PREF_DOUBLE_TAP, true) diff --git a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/battery/BatteryFragment.kt b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/battery/BatteryFragment.kt index cc53126..a047411 100644 --- a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/battery/BatteryFragment.kt +++ b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/battery/BatteryFragment.kt @@ -61,8 +61,7 @@ class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChang mSharedPreferences.edit().putBoolean(PREF_CHARGE, Battery.chargeSysfs == 0).apply() return true } else if (preference == mFastChargePref) { - Battery.setFastCharge(if (newValue as Boolean) 0 else 1) - mFastChargePref.isChecked = Battery.fastChargeSysfs == 0 + Battery.setFastCharge(if (newValue as Boolean) 0 else 1) mFastChargePref.isChecked = Battery.fastChargeSysfs == 0 mSharedPreferences.edit().putBoolean(PREF_FASTCHARGE, Battery.fastChargeSysfs == 0).apply() } return false diff --git a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Flashlight.kt b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Flashlight.kt index b373978..2f7554e 100644 --- a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Flashlight.kt +++ b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Flashlight.kt @@ -19,4 +19,5 @@ package com.eurekateam.samsungextras.interfaces object Flashlight { external fun setFlash(value: Int) external fun getFlash(isA10: Int): Int - external fun setEnabled(enable: Boolean) } + external fun setEnabled(enable: Boolean) +} diff --git a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Swap.kt b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Swap.kt index 61007d1..202d41e 100644 --- a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Swap.kt +++ b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/interfaces/Swap.kt @@ -16,7 +16,9 @@ package com.eurekateam.samsungextras.interfaces -object Swap{ - external fun setSwapOn(mEnabled: Boolean) - external fun setSize(mSize : Int) +object Swap { + external fun setSwapOn(mEnabled: Boolean) + external fun setSize(mSize: Int) + external fun getFreeSize(): Double + external fun getSwapSize(): Long } diff --git a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/swap/SwapFragment.kt b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/swap/SwapFragment.kt index 39acd58..8c5de58 100644 --- a/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/swap/SwapFragment.kt +++ b/universal7885-common/apps/SamsungParts/src/com/eurekateam/samsungextras/swap/SwapFragment.kt @@ -16,7 +16,6 @@ package com.eurekateam.samsungextras.swap import android.content.SharedPreferences -import android.os.Build import android.os.Bundle import android.widget.Switch import androidx.preference.Preference @@ -27,11 +26,14 @@ import com.android.settingslib.widget.MainSwitchPreference import com.android.settingslib.widget.OnMainSwitchChangeListener import com.eurekateam.samsungextras.R import com.eurekateam.samsungextras.interfaces.Swap +import java.lang.Thread class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener { private lateinit var mSwapSizePref: SeekBarPreference private lateinit var mSharedPreferences: SharedPreferences private lateinit var mSwapEnable: MainSwitchPreference + private lateinit var mFreeSpace: Preference + private lateinit var mSwapFileSize: Preference override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.swap_settings) mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) @@ -44,6 +46,10 @@ class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeLi mSwapEnable.isChecked = mSharedPreferences.getBoolean(PREF_SWAP_ENABLE, false) mSwapEnable.addOnSwitchChangeListener(this) mSwapSizePref.isEnabled = !mSwapEnable.isChecked + mFreeSpace = findPreference(INFO_FREE_SPACE)!! + mFreeSpace.summary = "${Swap.getFreeSpace()} GB" + mSwapFileSize = findPreference(INFO_SWAP_FILE_SIZE)!! + mSwapFileSize.summary = "${Swap.getSwapSize()} MB" } override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { @@ -51,19 +57,27 @@ class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeLi val value = newValue as Int Swap.setSize(value) mSharedPreferences.edit().putInt(PREF_SWAP_SIZE, value).apply() + mFreeSpace.summary = "${Swap.getFreeSpace()} GB" + mSwapFileSize.summary = "${Swap.getSwapSize()} MB" return true } return false } override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) { - Swap.setSwapOn(isChecked) - mSharedPreferences.edit().putBoolean(PREF_SWAP_ENABLE, isChecked).apply() - mSwapSizePref.isEnabled = !isChecked - } - - companion object { + mSwapEnable.isEnabled = false + Thread { + Swap.setSwapOn(isChecked) + requireActivity().runOnUiThread { + mSwapEnable.isEnabled = true + mSharedPreferences.edit().putBoolean(PREF_SWAP_ENABLE, isChecked).apply() + mSwapSizePref.isEnabled = !isChecked + } + }.start() + } companion object { const val PREF_SWAP_SIZE = "swap_size" const val PREF_SWAP_ENABLE = "swap_enable" + const val INFO_FREE_SPACE = "free_space" + const val INFO_SWAP_FILE_SIZE = "swap_file_size" } }