manager: added mount system switchability

userspace: added ksud_overlayfs & ksud_magic
This commit is contained in:
Rifat Azad
2025-01-07 17:08:53 +06:00
parent decf45a69e
commit f3f4ba5897
68 changed files with 6998 additions and 52 deletions

View File

@@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -347,6 +348,12 @@ fun WarningCard(
private fun InfoCard() {
val context = LocalContext.current
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
var useOverlayFs by rememberSaveable {
mutableStateOf(prefs.getBoolean("use_overlay_fs", false))
}
ElevatedCard {
Column(
modifier = Modifier
@@ -421,7 +428,13 @@ private fun InfoCard() {
Spacer(Modifier.height(16.dp))
InfoCardItem(
label = stringResource(R.string.home_module_mount),
content = stringResource(R.string.home_magic_mount),
content = if (useOverlayFs) {
// Show different content if OverlayFS is enabled
stringResource(R.string.home_overlayfs_mount)
} else {
// Default content when OverlayFS is not enabled
stringResource(R.string.home_magic_mount)
},
icon = Icons.Filled.SettingsSuggest,
)
}

View File

@@ -497,7 +497,7 @@ private fun ModuleList(
},
) {
when {
!viewModel.isDummy -> {
!viewModel.isOverlayAvailable -> {
item {
Box(
modifier = Modifier.fillParentMaxSize(),

View File

@@ -28,6 +28,8 @@ import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.Text
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
@@ -160,6 +162,46 @@ fun SettingScreen(navigator: DestinationsNavigator) {
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
var useOverlayFs by rememberSaveable {
mutableStateOf(
prefs.getBoolean("use_overlay_fs", false)
)
}
var showRestartDialog by remember { mutableStateOf(false) }
SwitchItem(
icon = Icons.Filled.Build,
title = stringResource(id = R.string.use_overlay_fs),
summary = stringResource(id = R.string.use_overlay_fs_summary),
checked = useOverlayFs
) {
prefs.edit().putBoolean("use_overlay_fs", it).apply()
useOverlayFs = it
showRestartDialog = true
}
if (showRestartDialog) {
AlertDialog(
onDismissRequest = { showRestartDialog = false },
title = { Text(stringResource(R.string.restart_required)) },
text = { Text(stringResource(R.string.restart_message)) },
confirmButton = {
TextButton(onClick = {
showRestartDialog = false
restartKsuNext(context)
}) {
Text(stringResource(R.string.restart_now))
}
},
dismissButton = {
TextButton(onClick = { showRestartDialog = false }) {
Text(stringResource(R.string.later))
}
}
)
}
var checkUpdate by rememberSaveable {
mutableStateOf(
prefs.getBoolean("check_update", true)
@@ -299,27 +341,31 @@ fun SettingScreen(navigator: DestinationsNavigator) {
)
}
// val shrink = stringResource(id = R.string.shrink_sparse_image)
// val shrinkMessage = stringResource(id = R.string.shrink_sparse_image_message)
// ListItem(
// leadingContent = {
// Icon(
// Icons.Filled.Compress,
// shrink
// )
// },
// headlineContent = { Text(shrink) },
// modifier = Modifier.clickable {
// scope.launch {
// val result = shrinkDialog.awaitConfirm(title = shrink, content = shrinkMessage)
// if (result == ConfirmResult.Confirmed) {
// loadingDialog.withLoading {
// shrinkModules()
// }
// }
// }
// }
// )
if (useOverlayFs) {
val shrink = stringResource(id = R.string.shrink_sparse_image)
val shrinkMessage = stringResource(id = R.string.shrink_sparse_image_message)
ListItem(
leadingContent = {
Icon(
Icons.Filled.Compress,
shrink
)
},
headlineContent = { Text(shrink) },
modifier = Modifier.clickable {
scope.launch {
val result = shrinkDialog.awaitConfirm(title = shrink, content = shrinkMessage)
if (result == ConfirmResult.Confirmed) {
loadingDialog.withLoading {
shrinkModules()
}
}
}
}
)
}
val lkmMode = Natives.version >= Natives.MINIMAL_SUPPORTED_KERNEL_LKM && Natives.isLkmMode
if (lkmMode) {

View File

@@ -2,6 +2,7 @@ package com.rifsxd.ksunext.ui.util
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.database.Cursor
import android.net.Uri
import android.os.Environment
@@ -22,15 +23,30 @@ import com.rifsxd.ksunext.ksuApp
import org.json.JSONArray
import java.io.File
/**
* @author weishu
* @date 2023/1/1.
*/
private const val TAG = "KsuCli"
private fun getKsuDaemonPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud.so"
private fun ksuDaemonMagicPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_magic.so"
}
private fun ksuDaemonOverlayfsPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_overlayfs.so"
}
// Get the path based on the user's choice
fun getKsuDaemonPath(): String {
val prefs = ksuApp.getSharedPreferences("settings", Context.MODE_PRIVATE)
val useOverlayFs = prefs.getBoolean("use_overlay_fs", false)
return if (useOverlayFs) {
ksuDaemonOverlayfsPath()
} else {
ksuDaemonMagicPath()
}
}
object KsuCli {
@@ -358,12 +374,10 @@ suspend fun getSupportedKmis(): List<String> = withContext(Dispatchers.IO) {
out.filter { it.isNotBlank() }.map { it.trim() }
}
fun hasDummy(): Boolean {
//fun overlayFsAvailable(): Boolean {
// val shell = getRootShell()
// // check /proc/filesystems
// return ShellUtils.fastCmdResult(shell, "cat /proc/filesystems | grep overlay")
return true
fun overlayFsAvailable(): Boolean {
val shell = getRootShell()
// check /proc/filesystems
return ShellUtils.fastCmdResult(shell, "cat /proc/filesystems | grep overlay")
}
fun hasMagisk(): Boolean {
@@ -447,3 +461,10 @@ fun restartApp(packageName: String) {
forceStopApp(packageName)
launchApp(packageName)
}
fun restartKsuNext(context: Context) {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
Runtime.getRuntime().exit(0)
}

View File

@@ -11,7 +11,7 @@ import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import com.rifsxd.ksunext.ui.util.listModules
import com.rifsxd.ksunext.ui.util.hasDummy
import com.rifsxd.ksunext.ui.util.overlayFsAvailable
import org.json.JSONArray
import org.json.JSONObject
@@ -45,7 +45,7 @@ class ModuleViewModel : ViewModel() {
val changelog: String,
)
var isDummy by mutableStateOf(hasDummy())
var isOverlayAvailable by mutableStateOf(overlayFsAvailable())
private set
var isRefreshing by mutableStateOf(false)
@@ -82,7 +82,7 @@ class ModuleViewModel : ViewModel() {
val start = SystemClock.elapsedRealtime()
kotlin.runCatching {
isDummy = hasDummy()
isOverlayAvailable = overlayFsAvailable()
val result = listModules()

View File

@@ -1 +1,2 @@
libksud.so
libksud_overlayfs.so
libksud_magic.so

View File

@@ -65,6 +65,13 @@
<string name="module_magisk_conflict">Konflik dengan Magisk, fungsi modul ditiadakan!</string>
<string name="home_module_mount">Modul Sistem</string>
<string name="home_magic_mount">Magic Mount</string>
<string name="home_overlayfs_mount">OverlayFS</string>
<string name="use_overlay_fs">Use OverlayFS</string>
<string name="use_overlay_fs_summary">Toggle between using OverlayFS or Magic for KSU daemon</string>
<string name="restart_required">Restart Required</string>
<string name="restart_message">Changes will take effect after restarting the app. Would you like to restart now?</string>
<string name="restart_now">Restart Now</string>
<string name="later">Later</string>
<string name="home_next_kernelsu">🔥 Pembangunan Next</string>
<string name="home_next_kernelsu_repo">https://github.com/rifsxd/KernelSU-Next</string>
<string name="home_next_kernelsu_body">Next cabang eksperimental. Lihat di GitHub!</string>

View File

@@ -65,6 +65,13 @@
<string name="module_magisk_conflict">Os módulos estão indisponíveis devido a um conflito com Magisk!</string>
<string name="home_module_mount">Sistema de módulos</string>
<string name="home_magic_mount">Magic Mount</string>
<string name="home_overlayfs_mount">OverlayFS</string>
<string name="use_overlay_fs">Use OverlayFS</string>
<string name="use_overlay_fs_summary">Toggle between using OverlayFS or Magic for KSU daemon</string>
<string name="restart_required">Restart Required</string>
<string name="restart_message">Changes will take effect after restarting the app. Would you like to restart now?</string>
<string name="restart_now">Restart Now</string>
<string name="later">Later</string>
<string name="home_next_kernelsu">🔥 Compilação next</string>
<string name="home_next_kernelsu_repo">https://github.com/rifsxd/KernelSU-Next</string>
<string name="home_next_kernelsu_body">Branch next experimental. Confira no GitHub!</string>

View File

@@ -64,6 +64,13 @@
<string name="reboot_to_apply">重启生效</string>
<string name="home_module_mount">模块系统</string>
<string name="home_magic_mount">Magic Mount</string>
<string name="home_overlayfs_mount">OverlayFS</string>
<string name="use_overlay_fs">Use OverlayFS</string>
<string name="use_overlay_fs_summary">Toggle between using OverlayFS or Magic for KSU daemon</string>
<string name="restart_required">Restart Required</string>
<string name="restart_message">Changes will take effect after restarting the app. Would you like to restart now?</string>
<string name="restart_now">Restart Now</string>
<string name="later">Later</string>
<string name="module_magisk_conflict">因与 Magisk 有冲突,所有模块不可用!</string>
<string name="home_next_kernelsu">🔥 Next 构建</string>
<string name="home_next_kernelsu_repo">https://github.com/rifsxd/KernelSU-Next</string>

View File

@@ -65,6 +65,13 @@
<string name="module_magisk_conflict">Modules are unavailable due to a conflict with Magisk!</string>
<string name="home_module_mount">Module system</string>
<string name="home_magic_mount">Magic Mount</string>
<string name="home_overlayfs_mount">OverlayFS</string>
<string name="use_overlay_fs">Use OverlayFS</string>
<string name="use_overlay_fs_summary">Toggle between using OverlayFS or Magic for KSU daemon</string>
<string name="restart_required">Restart Required</string>
<string name="restart_message">Changes will take effect after restarting the app. Would you like to restart now?</string>
<string name="restart_now">Restart Now</string>
<string name="later">Later</string>
<string name="home_next_kernelsu">🔥 Next build</string>
<string name="home_next_kernelsu_repo">https://github.com/rifsxd/KernelSU-Next</string>
<string name="home_next_kernelsu_body">Next experimental branch. Check it out on GitHub!</string>