manager: keep mount system preference persistent

This commit is contained in:
rifsxd
2025-06-01 03:37:10 +06:00
parent 8803058521
commit 609926bff1
3 changed files with 26 additions and 8 deletions

View File

@@ -165,9 +165,7 @@ fun BackupRestoreScreen(navigator: DestinationsNavigator) {
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE) val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
var useOverlayFs by rememberSaveable { var useOverlayFs by rememberSaveable {
mutableStateOf( mutableStateOf(readMountSystemFile())
prefs.getBoolean("use_overlay_fs", false)
)
} }
val moduleRestore = stringResource(id = R.string.module_restore) val moduleRestore = stringResource(id = R.string.module_restore)

View File

@@ -224,9 +224,11 @@ fun SettingScreen(navigator: DestinationsNavigator) {
} }
var useOverlayFs by rememberSaveable { var useOverlayFs by rememberSaveable {
mutableStateOf( mutableStateOf(readMountSystemFile())
prefs.getBoolean("use_overlay_fs", false) }
)
LaunchedEffect(Unit) {
useOverlayFs = readMountSystemFile()
} }
var showRebootDialog by remember { mutableStateOf(false) } var showRebootDialog by remember { mutableStateOf(false) }
@@ -244,8 +246,10 @@ fun SettingScreen(navigator: DestinationsNavigator) {
useOverlayFs = it useOverlayFs = it
if (useOverlayFs) { if (useOverlayFs) {
moduleBackup() moduleBackup()
updateMountSystemFile(true)
} else { } else {
moduleMigration() moduleMigration()
updateMountSystemFile(false)
} }
if (isManager) install() if (isManager) install()
showRebootDialog = true showRebootDialog = true

View File

@@ -37,10 +37,16 @@ private fun ksuDaemonOverlayfsPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_overlayfs.so" return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_overlayfs.so"
} }
fun readMountSystemFile(): Boolean {
val shell = getRootShell()
val filePath = "/data/adb/ksu/mount_system"
val result = ShellUtils.fastCmd(shell, "cat $filePath").trim()
return result == "OVERLAYFS"
}
// Get the path based on the user's choice // Get the path based on the user's choice
fun getKsuDaemonPath(): String { fun getKsuDaemonPath(): String {
val prefs = ksuApp.getSharedPreferences("settings", Context.MODE_PRIVATE) val useOverlayFs = readMountSystemFile()
val useOverlayFs = prefs.getBoolean("use_overlay_fs", false)
return if (useOverlayFs) { return if (useOverlayFs) {
ksuDaemonOverlayfsPath() ksuDaemonOverlayfsPath()
@@ -49,6 +55,16 @@ fun getKsuDaemonPath(): String {
} }
} }
fun updateMountSystemFile(useOverlayFs: Boolean) {
val shell = getRootShell()
val filePath = "/data/adb/ksu/mount_system"
if (useOverlayFs) {
ShellUtils.fastCmd(shell, "echo -n OVERLAYFS > $filePath")
} else {
ShellUtils.fastCmd(shell, "echo -n MAGIC_MOUNT > $filePath")
}
}
data class FlashResult(val code: Int, val err: String, val showReboot: Boolean) { data class FlashResult(val code: Int, val err: String, val showReboot: Boolean) {
constructor(result: Shell.Result, showReboot: Boolean) : this(result.code, result.err.joinToString("\n"), showReboot) constructor(result: Shell.Result, showReboot: Boolean) : this(result.code, result.err.joinToString("\n"), showReboot)
constructor(result: Shell.Result) : this(result, result.isSuccess) constructor(result: Shell.Result) : this(result, result.isSuccess)