Skip to content

Commit 5625b09

Browse files
committed
修复swap开机自启动失败
1 parent e995624 commit 5625b09

8 files changed

Lines changed: 47 additions & 60 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
minSdkVersion 23
2323
targetSdkVersion 30
2424
versionCode 202107051
25-
versionName "4.4.13"
25+
versionName "4.4.13 Beta"
2626
externalNativeBuild {
2727
cmake {
2828
cppFlags ""

app/src/main/assets/addin/swap_control.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/system/bin/sh
2-
31
swapfile=/data/swapfile
42
action="$1" # 操作(脚本中的函数名)
53
loop="$2" # 是否挂载为loop设备
@@ -8,8 +6,9 @@ swapsize="$4" # SWAP大小MB
86

97
loop_save="vtools.swap.loop"
108
next_loop_path=""
9+
1110
# 获取下一个loop设备的索引
12-
function get_next_loop() {
11+
get_next_loop() {
1312
local current_loop=`getprop $loop_save`
1413

1514
if [[ "$current_loop" != "" ]]
@@ -52,7 +51,7 @@ else
5251
fi
5352

5453
# 关闭swap(如果正在使用,那可不是一般的慢)
55-
diable_swap() {
54+
disable_swap() {
5655
swapoff $swap_mount >/dev/null 2>&1
5756

5857
if [[ $loop == "1" ]]; then
@@ -64,8 +63,7 @@ diable_swap() {
6463

6564
# 开启SWAP
6665
enable_swap() {
67-
if [[ ! -f $swapfile ]]
68-
then
66+
if [[ ! -f $swapfile ]]; then
6967
if [[ "$swapsize" = "" ]]; then
7068
swapsize=256
7169
fi
@@ -82,8 +80,8 @@ enable_swap() {
8280
setprop $loop_save $next_loop_path
8381
fi
8482

85-
mkswap $swap_mount >/dev/null 2>&1 # 初始化
86-
if [[ "$priority" != "" ]]; then
83+
mkswap $swap_mount >/dev/null 2>&1 # 初始化
84+
if [[ "$priority" != "" ]]; then
8785

8886
# zram_priority=`cat /proc/swaps | grep /zram0 | sed 's/[ \t][ ]*/,/g' | cut -f5 -d ','`
8987
zram_info=`cat /proc/swaps | grep /zram0`
@@ -104,14 +102,18 @@ enable_swap() {
104102
fi
105103
fi
106104

107-
swapon $swap_mount -p "$priority" >/dev/null 2>&1 # 开启
105+
if [[ "$priority" -lt 0 ]]; then
106+
swapon $swap_mount >/dev/null 2>&1 # 开启
107+
else
108+
swapon $swap_mount -p "$priority" >/dev/null 2>&1 # 开启
109+
fi
108110
else
109111
swapon $swap_mount >/dev/null 2>&1 # 开启
110-
fi
112+
fi
111113

112-
echo 100 > /proc/sys/vm/overcommit_ratio
113-
echo 100 > /proc/sys/vm/swap_ratio
114-
echo 0 > /proc/sys/panic_on_oom
114+
echo 100 > /proc/sys/vm/overcommit_ratio
115+
echo 100 > /proc/sys/vm/swap_ratio
116+
echo 0 > /proc/sys/panic_on_oom
115117
}
116118

117119
"$action"

app/src/main/assets/powercfg/lahaina/active.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ if [[ "$action" = "powersave" ]]; then
4444
cpuset '0-2' '0-3' '0-3' '0-7'
4545
stune_top_app 0 0
4646
cpuctl top-app 0 1 0 max
47-
echo 75000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
4847

4948

5049
elif [[ "$action" = "balance" ]]; then
@@ -61,7 +60,6 @@ elif [[ "$action" = "balance" ]]; then
6160
cpuset '0-2' '0-3' '0-6' '0-7'
6261
stune_top_app 0 0
6362
cpuctl top-app 0 1 0.1 max
64-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
6563

6664

6765
elif [[ "$action" = "performance" ]]; then
@@ -76,7 +74,6 @@ elif [[ "$action" = "performance" ]]; then
7674
cpuset '0-1' '0-3' '0-6' '0-7'
7775
stune_top_app 1 0
7876
cpuctl top-app 0 1 0.5 max
79-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
8077

8178

8279
elif [[ "$action" = "fast" ]]; then
@@ -91,7 +88,6 @@ elif [[ "$action" = "fast" ]]; then
9188
cpuset '0' '0-3' '0-6' '0-7'
9289
stune_top_app 1 50
9390
cpuctl top-app 0 1 max max
94-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
9591

9692

9793
fi

app/src/main/assets/powercfg/lahaina/conservative.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ if [[ "$action" = "powersave" ]]; then
4444
cpuset '0-2' '0-3' '0-3' '0-7'
4545
stune_top_app 0 0
4646
cpuctl top-app 0 0 0 max
47-
echo 75000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
4847

4948

5049
elif [[ "$action" = "balance" ]]; then
@@ -62,7 +61,6 @@ elif [[ "$action" = "balance" ]]; then
6261
stune_top_app 0 0
6362
# cpuctl top-app 0 1 0.1 max
6463
cpuctl top-app 0 1 0 max
65-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
6664

6765

6866
elif [[ "$action" = "performance" ]]; then
@@ -77,7 +75,6 @@ elif [[ "$action" = "performance" ]]; then
7775
cpuset '0-1' '0-3' '0-6' '0-7'
7876
stune_top_app 0 0
7977
cpuctl top-app 0 1 0.25 max
80-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
8178

8279

8380
elif [[ "$action" = "fast" ]]; then
@@ -92,7 +89,6 @@ elif [[ "$action" = "fast" ]]; then
9289
cpuset '0' '0-3' '0-6' '0-7'
9390
stune_top_app 1 0
9491
cpuctl top-app 0 1 max max
95-
echo 300000000 > /sys/class/devfreq/1d84000.ufshc/max_freq
9692

9793

9894
fi

app/src/main/java/com/omarea/library/shell/SwapUtils.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SwapUtils(private val context: Context) {
7575
}
7676

7777
// 启动swap
78-
fun swapOn(priority: Int, useLoop: Boolean = false): String {
78+
fun swapOn(priority: Int, useLoop: Boolean = false, keepShell: KeepShell): String {
7979
val sb = StringBuilder()
8080

8181
sb.append("sh ")
@@ -91,8 +91,15 @@ class SwapUtils(private val context: Context) {
9191
sb.append(priority)
9292
}
9393

94+
return keepShell.doCmdSync(sb.toString())
95+
}
96+
97+
// 启动swap
98+
fun swapOn(priority: Int, useLoop: Boolean = false): String {
9499
val keepShell = KeepShell()
95-
val result = keepShell.doCmdSync(sb.toString())
100+
101+
val result = swapOn(priority, useLoop, keepShell)
102+
96103
keepShell.tryExit()
97104
return result
98105
}
@@ -103,7 +110,7 @@ class SwapUtils(private val context: Context) {
103110

104111
sb.append("sh ")
105112
sb.append(swapControlScript)
106-
sb.append(" diable_swap ")
113+
sb.append(" disable_swap ")
107114
if (sceneSwaps.contains("loop")) {
108115
sb.append("1")
109116
} else {
@@ -121,7 +128,7 @@ class SwapUtils(private val context: Context) {
121128

122129
sb.append("sh ")
123130
sb.append(swapControlScript)
124-
sb.append(" diable_swap ")
131+
sb.append(" disable_swap ")
125132
if (sceneSwaps.contains("loop")) {
126133
sb.append("1")
127134
} else {

app/src/main/java/com/omarea/vtools/popup/FloatMonitor.kt

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ class FloatMonitor(private val mContext: Context) {
196196

197197
private var activityManager: ActivityManager? = null
198198
private var myHandler = Handler(Looper.getMainLooper())
199-
private var batteryUnit = BatteryUtils()
200199
private val info = ActivityManager.MemoryInfo()
201200

202-
private var sum = -1
203201
private var totalMem = 0
204202
private var availMem = 0
205203
private var coreCount = -1;
@@ -213,6 +211,13 @@ class FloatMonitor(private val mContext: Context) {
213211
private val boldStyleSpan = StyleSpan(Typeface.BOLD)
214212
private val whiteSpan = ForegroundColorSpan(Color.WHITE)
215213

214+
private fun whiteBoldSpan(text: String): SpannableString {
215+
return SpannableString(text).apply {
216+
setSpan(whiteSpan, 0, text.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
217+
setSpan(boldStyleSpan, 0, text.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
218+
}
219+
}
220+
216221
private fun updateInfo() {
217222
if (coreCount < 1) {
218223
coreCount = CpuFrequencyUtil.getCoreCount()
@@ -265,33 +270,22 @@ class FloatMonitor(private val mContext: Context) {
265270
availMem = (info.availMem / 1024 / 1024f).toInt()
266271
val ramInfoText = "#RAM " + ((totalMem - availMem) * 100 / totalMem).toString() + "%"
267272

268-
otherInfoBuilder.append(SpannableString(ramInfoText).apply {
269-
setSpan(whiteSpan, 0, ramInfoText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
270-
setSpan(boldStyleSpan, 0, ramInfoText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
271-
})
273+
otherInfoBuilder.append(whiteBoldSpan(ramInfoText))
272274
otherInfoBuilder.append("\n")
273275

274276
if (gpuMemoryUsage != null) {
275-
gpuMemoryUsage = "#GMEM " + gpuMemoryUsage
276-
otherInfoBuilder.append(SpannableString(gpuMemoryUsage).apply {
277-
setSpan(whiteSpan, 0, gpuMemoryUsage.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
278-
setSpan(boldStyleSpan, 0, gpuMemoryUsage.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
279-
})
277+
otherInfoBuilder.append(whiteBoldSpan("#GMEM " + gpuMemoryUsage))
280278
otherInfoBuilder.append("\n")
281279
}
282280

283-
var clusterIndex = 0
284-
for (cluster in clusters) {
281+
for ((clusterIndex, cluster) in clusters.withIndex()) {
285282
if (clusterIndex != 0) {
286283
otherInfoBuilder.append("\n")
287284
}
288-
if (cluster.size > 0) {
285+
if (cluster.isNotEmpty()) {
289286
try {
290287
val title = "#" + cluster[0] + "~" + cluster[cluster.size - 1] + " " + subFreqStr(clustersFreq.get(clusterIndex)) + "Mhz";
291-
otherInfoBuilder.append(SpannableString(title).apply {
292-
setSpan(whiteSpan, 0, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
293-
setSpan(boldStyleSpan, 0, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
294-
})
288+
otherInfoBuilder.append(whiteBoldSpan(title))
295289

296290
val otherInfos = StringBuilder("")
297291
for (core in cluster) {
@@ -310,28 +304,21 @@ class FloatMonitor(private val mContext: Context) {
310304
} catch (ex: Exception) {
311305
}
312306
}
313-
clusterIndex++
314307
}
315308

316309
fpsUtils.currentFps?.run {
317310
otherInfoBuilder.append("\n")
318311

319312
val fpsInfo = "#FPS $this"
320-
otherInfoBuilder.append(SpannableString(fpsInfo).apply {
321-
setSpan(whiteSpan, 0, fpsInfo.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
322-
setSpan(boldStyleSpan, 0, fpsInfo.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
323-
})
313+
otherInfoBuilder.append(SpannableString(fpsInfo))
324314
}
325315

326316
batteryCurrentNowMa?.run {
327317
if (this > -20000 && this < 20000) {
328318
otherInfoBuilder.append("\n")
329319

330320
val batteryInfo = "#BAT " + (if (this > 0) ("+" + this) else this) + "mA"
331-
otherInfoBuilder.append(SpannableString(batteryInfo).apply {
332-
setSpan(whiteSpan, 0, batteryInfo.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
333-
setSpan(boldStyleSpan, 0, batteryInfo.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
334-
})
321+
otherInfoBuilder.append(SpannableString(batteryInfo))
335322
}
336323
}
337324
}

app/src/main/java/com/omarea/vtools/services/BootService.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.SharedPreferences
1010
import android.os.Build
1111
import android.os.PowerManager
1212
import androidx.core.app.NotificationCompat
13-
import com.omarea.common.shared.FileWrite
1413
import com.omarea.common.shared.RawText
1514
import com.omarea.common.shell.KeepShell
1615
import com.omarea.common.shell.KernelProrp
@@ -19,6 +18,7 @@ import com.omarea.data.EventType
1918
import com.omarea.library.shell.BatteryUtils
2019
import com.omarea.library.shell.LMKUtils
2120
import com.omarea.library.shell.PropsUtils
21+
import com.omarea.library.shell.SwapUtils
2222
import com.omarea.scene_mode.ModeSwitcher
2323
import com.omarea.scene_mode.SceneMode
2424
import com.omarea.store.CpuConfigStorage
@@ -192,18 +192,17 @@ class BootService : IntentService("vtools-boot") {
192192
KernelProrp.setProp("/sys/block/zram0/comp_algorithm", value)
193193
}
194194

195-
fun enableSwap(keepShell: KeepShell, context: Context) {
195+
private fun enableSwap(keepShell: KeepShell, context: Context) {
196196
updateNotification(getString(R.string.boot_swapon))
197-
val swapControlScript = FileWrite.writePrivateShellFile("addin/swap_control.sh", "addin/swap_control.sh", context)
198197
val swapPriority = swapConfig.getInt(SpfConfig.SWAP_SPF_SWAP_PRIORITY, -2)
199-
val useLoop = if (swapConfig.getBoolean(SpfConfig.SWAP_SPF_SWAP_USE_LOOP, false)) "1" else "0"
200-
keepShell.doCmdSync("sh $swapControlScript enable_swap $useLoop $swapPriority\n")
198+
val useLoop = swapConfig.getBoolean(SpfConfig.SWAP_SPF_SWAP_USE_LOOP, false)
199+
SwapUtils(context).swapOn(swapPriority, useLoop, keepShell)
201200
}
202201

203202
/**
204203
* swapFirst:是否已开启可优先使用的swap,如果未开启,则在调整zram前,先将swappiness调为0,避免在回收时还在写入zram,导致回收时间变长!
205204
*/
206-
fun resizeZram(sizeVal: Int, algorithm: String = "", keepShell: KeepShell, swapFirst: Boolean = false) {
205+
private fun resizeZram(sizeVal: Int, algorithm: String = "", keepShell: KeepShell, swapFirst: Boolean = false) {
207206
val currentSize = keepShell.doCmdSync("cat /sys/block/zram0/disksize")
208207
if (currentSize != "" + (sizeVal * 1024 * 1024L) || (algorithm.isNotEmpty() && algorithm != compAlgorithm)) {
209208
val sb = StringBuilder()

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<string name="share_link">你也来试试Scene吧,我觉得还不错,下载地址:\n http://vtools.omarea.com/</string>
3434
<!--<string name="feedback_link">mqqwpa://im/chat?chat_type=wpa&amp;uin=1191634433</string>-->
3535

36-
<string name="app_name">Scene4</string>
36+
<string name="app_name">Scene4 Beta</string>
3737
<string name="app_name_short">Scene4</string>
3838
<string name="app_name_mode_switch">Scene-快速切换模式</string>
3939

0 commit comments

Comments
 (0)