manager: Optimize SuSFS path editing functionality

- Resize thread pool to improve performance
This commit is contained in:
ShirkNeko
2025-07-31 01:00:49 +08:00
parent ea68183f80
commit 1b7c7fd726
2 changed files with 154 additions and 45 deletions

View File

@@ -945,15 +945,33 @@ object SuSFSManager {
// 编辑SUS路径 // 编辑SUS路径
suspend fun editSusPath(context: Context, oldPath: String, newPath: String): Boolean { suspend fun editSusPath(context: Context, oldPath: String, newPath: String): Boolean {
val currentPaths = getSusPaths(context).toMutableSet() return try {
if (currentPaths.remove(oldPath)) { val currentPaths = getSusPaths(context).toMutableSet()
currentPaths.add(newPath) if (!currentPaths.remove(oldPath)) {
showToast(context, "Original path not found: $oldPath")
return false
}
saveSusPaths(context, currentPaths) saveSusPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "SUS path updated: $oldPath -> $newPath") val success = addSusPath(context, newPath)
return true
if (success) {
showToast(context, "SUS path updated: $oldPath -> $newPath")
return true
} else {
// 如果添加新路径失败,恢复旧路径
currentPaths.add(oldPath)
saveSusPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update path, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating SUS path: ${e.message}")
false
} }
return false
} }
// 循环路径相关方法 // 循环路径相关方法
@@ -996,6 +1014,7 @@ object SuSFSManager {
return true return true
} }
// 编辑循环路径
suspend fun editSusLoopPath(context: Context, oldPath: String, newPath: String): Boolean { suspend fun editSusLoopPath(context: Context, oldPath: String, newPath: String): Boolean {
// 检查新路径是否有效 // 检查新路径是否有效
if (!isValidLoopPath(newPath)) { if (!isValidLoopPath(newPath)) {
@@ -1003,15 +1022,33 @@ object SuSFSManager {
return false return false
} }
val currentPaths = getSusLoopPaths(context).toMutableSet() return try {
if (currentPaths.remove(oldPath)) { val currentPaths = getSusLoopPaths(context).toMutableSet()
currentPaths.add(newPath) if (!currentPaths.remove(oldPath)) {
showToast(context, "Original loop path not found: $oldPath")
return false
}
saveSusLoopPaths(context, currentPaths) saveSusLoopPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, context.getString(R.string.susfs_loop_path_updated, oldPath, newPath)) val success = addSusLoopPath(context, newPath)
return true
if (success) {
showToast(context, context.getString(R.string.susfs_loop_path_updated, oldPath, newPath))
return true
} else {
// 如果添加新路径失败,恢复旧路径
currentPaths.add(oldPath)
saveSusLoopPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update loop path, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating SUS loop path: ${e.message}")
false
} }
return false
} }
// 添加SUS挂载 // 添加SUS挂载
@@ -1033,15 +1070,33 @@ object SuSFSManager {
// 编辑SUS挂载 // 编辑SUS挂载
suspend fun editSusMount(context: Context, oldMount: String, newMount: String): Boolean { suspend fun editSusMount(context: Context, oldMount: String, newMount: String): Boolean {
val currentMounts = getSusMounts(context).toMutableSet() return try {
if (currentMounts.remove(oldMount)) { val currentMounts = getSusMounts(context).toMutableSet()
currentMounts.add(newMount) if (!currentMounts.remove(oldMount)) {
showToast(context, "Original mount not found: $oldMount")
return false
}
saveSusMounts(context, currentMounts) saveSusMounts(context, currentMounts)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "SUS mount updated: $oldMount -> $newMount") val success = addSusMount(context, newMount)
return true
if (success) {
showToast(context, "SUS mount updated: $oldMount -> $newMount")
return true
} else {
// 如果添加新挂载点失败,恢复旧挂载点
currentMounts.add(oldMount)
saveSusMounts(context, currentMounts)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update mount, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating SUS mount: ${e.message}")
false
} }
return false
} }
// 添加尝试卸载 // 添加尝试卸载
@@ -1068,15 +1123,33 @@ object SuSFSManager {
// 编辑尝试卸载 // 编辑尝试卸载
suspend fun editTryUmount(context: Context, oldEntry: String, newPath: String, newMode: Int): Boolean { suspend fun editTryUmount(context: Context, oldEntry: String, newPath: String, newMode: Int): Boolean {
val currentUmounts = getTryUmounts(context).toMutableSet() return try {
if (currentUmounts.remove(oldEntry)) { val currentUmounts = getTryUmounts(context).toMutableSet()
currentUmounts.add("$newPath|$newMode") if (!currentUmounts.remove(oldEntry)) {
showToast(context, "Original umount entry not found: $oldEntry")
return false
}
saveTryUmounts(context, currentUmounts) saveTryUmounts(context, currentUmounts)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Try umount updated: $oldEntry -> $newPath|$newMode") val success = addTryUmount(context, newPath, newMode)
return true
if (success) {
showToast(context, "Try umount updated: $oldEntry -> $newPath|$newMode")
return true
} else {
// 如果添加新条目失败,恢复旧条目
currentUmounts.add(oldEntry)
saveTryUmounts(context, currentUmounts)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update umount entry, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating try umount: ${e.message}")
false
} }
return false
} }
suspend fun runTryUmount(context: Context): Boolean = executeSusfsCommand(context, "run_try_umount") suspend fun runTryUmount(context: Context): Boolean = executeSusfsCommand(context, "run_try_umount")
@@ -1132,16 +1205,34 @@ object SuSFSManager {
suspend fun editKstatConfig(context: Context, oldConfig: String, path: String, ino: String, dev: String, nlink: String, suspend fun editKstatConfig(context: Context, oldConfig: String, path: String, ino: String, dev: String, nlink: String,
size: String, atime: String, atimeNsec: String, mtime: String, mtimeNsec: String, size: String, atime: String, atimeNsec: String, mtime: String, mtimeNsec: String,
ctime: String, ctimeNsec: String, blocks: String, blksize: String): Boolean { ctime: String, ctimeNsec: String, blocks: String, blksize: String): Boolean {
val currentConfigs = getKstatConfigs(context).toMutableSet() return try {
if (currentConfigs.remove(oldConfig)) { val currentConfigs = getKstatConfigs(context).toMutableSet()
val newConfigEntry = "$path|$ino|$dev|$nlink|$size|$atime|$atimeNsec|$mtime|$mtimeNsec|$ctime|$ctimeNsec|$blocks|$blksize" if (!currentConfigs.remove(oldConfig)) {
currentConfigs.add(newConfigEntry) showToast(context, "Original kstat config not found")
return false
}
saveKstatConfigs(context, currentConfigs) saveKstatConfigs(context, currentConfigs)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, context.getString(R.string.kstat_config_updated, path)) val success = addKstatStatically(context, path, ino, dev, nlink, size, atime, atimeNsec,
return true mtime, mtimeNsec, ctime, ctimeNsec, blocks, blksize)
if (success) {
showToast(context, context.getString(R.string.kstat_config_updated, path))
return true
} else {
// 如果添加新配置失败,恢复旧配置
currentConfigs.add(oldConfig)
saveKstatConfigs(context, currentConfigs)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update kstat config, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating kstat config: ${e.message}")
false
} }
return false
} }
// 添加kstat路径 // 添加kstat路径
@@ -1165,15 +1256,33 @@ object SuSFSManager {
// 编辑kstat路径 // 编辑kstat路径
@SuppressLint("StringFormatInvalid") @SuppressLint("StringFormatInvalid")
suspend fun editAddKstat(context: Context, oldPath: String, newPath: String): Boolean { suspend fun editAddKstat(context: Context, oldPath: String, newPath: String): Boolean {
val currentPaths = getAddKstatPaths(context).toMutableSet() return try {
if (currentPaths.remove(oldPath)) { val currentPaths = getAddKstatPaths(context).toMutableSet()
currentPaths.add(newPath) if (!currentPaths.remove(oldPath)) {
showToast(context, "Original kstat path not found: $oldPath")
return false
}
saveAddKstatPaths(context, currentPaths) saveAddKstatPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, context.getString(R.string.kstat_path_updated, oldPath, newPath)) val success = addKstat(context, newPath)
return true
if (success) {
showToast(context, context.getString(R.string.kstat_path_updated, oldPath, newPath))
return true
} else {
// 如果添加新路径失败,恢复旧路径
currentPaths.add(oldPath)
saveAddKstatPaths(context, currentPaths)
if (isAutoStartEnabled(context)) updateMagiskModule(context)
showToast(context, "Failed to update kstat path, reverted to original")
return false
}
} catch (e: Exception) {
e.printStackTrace()
showToast(context, "Error updating kstat path: ${e.message}")
false
} }
return false
} }
// 更新kstat // 更新kstat

View File

@@ -84,8 +84,8 @@ class SuperUserViewModel : ViewModel() {
private const val KEY_SHOW_SYSTEM_APPS = "show_system_apps" private const val KEY_SHOW_SYSTEM_APPS = "show_system_apps"
private const val KEY_SELECTED_CATEGORY = "selected_category" private const val KEY_SELECTED_CATEGORY = "selected_category"
private const val KEY_CURRENT_SORT_TYPE = "current_sort_type" private const val KEY_CURRENT_SORT_TYPE = "current_sort_type"
private const val CORE_POOL_SIZE = 4 private const val CORE_POOL_SIZE = 8
private const val MAX_POOL_SIZE = 8 private const val MAX_POOL_SIZE = 16
private const val KEEP_ALIVE_TIME = 60L private const val KEEP_ALIVE_TIME = 60L
private const val BATCH_SIZE = 20 private const val BATCH_SIZE = 20
} }