manager: improved module mount system & fixed bug for module installation file name error

This commit is contained in:
Rifat Azad
2025-01-08 11:13:29 +06:00
parent 159d9d2594
commit 6bbe40dfda
8 changed files with 42 additions and 45 deletions
@@ -354,6 +354,10 @@ private fun InfoCard() {
mutableStateOf(prefs.getBoolean("use_overlay_fs", false))
}
LaunchedEffect(Unit) {
useOverlayFs = prefs.getBoolean("use_overlay_fs", false)
}
ElevatedCard {
Column(
modifier = Modifier
@@ -429,10 +433,8 @@ private fun InfoCard() {
InfoCardItem(
label = stringResource(R.string.home_module_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,
@@ -96,6 +96,7 @@ import com.rifsxd.ksunext.R
import com.rifsxd.ksunext.ui.component.ConfirmResult
import com.rifsxd.ksunext.ui.component.rememberConfirmDialog
import com.rifsxd.ksunext.ui.component.rememberLoadingDialog
import com.rifsxd.ksunext.ui.util.*
import com.rifsxd.ksunext.ui.util.DownloadListener
import com.rifsxd.ksunext.ui.util.LocalSnackbarHost
import com.rifsxd.ksunext.ui.util.download
@@ -240,8 +241,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
) { innerPadding ->
// confirmation dialog
if (showConfirmDialog && zipUri != null) {
// extract the module name from the zipUri
val moduleName = zipUri?.lastPathSegment?.substringAfterLast('/') ?: "Unknown Module"
val moduleName = getFileName(context, zipUri!!)
AlertDialog(
onDismissRequest = { showConfirmDialog = false },
@@ -251,7 +251,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(zipUri!!)))
viewModel.markNeedRefresh()
}) {
Text(stringResource(R.string.confirm))
}
@@ -261,15 +260,16 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
Text(stringResource(android.R.string.cancel))
}
},
title = { Text(stringResource(R.string.confirm_module_installation)) },
text = {
title = { Text(stringResource(R.string.module)) },
text = {
Text(
stringResource(R.string.module_install_prompt_with_name, moduleName)
)
)
}
)
}
when {
hasMagisk -> {
Box(
@@ -70,6 +70,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import com.rifsxd.ksunext.BuildConfig
import com.rifsxd.ksunext.Natives
import com.rifsxd.ksunext.ksuApp
import com.rifsxd.ksunext.R
import com.rifsxd.ksunext.ui.component.AboutDialog
import com.rifsxd.ksunext.ui.component.ConfirmResult
@@ -168,7 +169,9 @@ fun SettingScreen(navigator: DestinationsNavigator) {
)
}
var showRestartDialog by remember { mutableStateOf(false) }
val isManager = Natives.becomeManager(ksuApp.packageName)
var showRebootDialog by remember { mutableStateOf(false) }
SwitchItem(
icon = Icons.Filled.Build,
@@ -178,24 +181,25 @@ fun SettingScreen(navigator: DestinationsNavigator) {
) {
prefs.edit().putBoolean("use_overlay_fs", it).apply()
useOverlayFs = it
showRestartDialog = true
if (isManager) install()
showRebootDialog = true
}
if (showRestartDialog) {
if (showRebootDialog) {
AlertDialog(
onDismissRequest = { showRestartDialog = false },
title = { Text(stringResource(R.string.restart_required)) },
text = { Text(stringResource(R.string.restart_message)) },
onDismissRequest = { showRebootDialog = false },
title = { Text(stringResource(R.string.reboot_required)) },
text = { Text(stringResource(R.string.reboot_message)) },
confirmButton = {
TextButton(onClick = {
showRestartDialog = false
restartKsuNext(context)
showRebootDialog = false
reboot()
}) {
Text(stringResource(R.string.restart_now))
Text(stringResource(R.string.reboot))
}
},
dismissButton = {
TextButton(onClick = { showRestartDialog = false }) {
TextButton(onClick = { showRebootDialog = false }) {
Text(stringResource(R.string.later))
}
}
@@ -427,6 +427,21 @@ fun getAppProfileTemplate(id: String): String {
.to(ArrayList(), null).exec().out.joinToString("\n")
}
fun getFileName(context: Context, uri: Uri): String {
var name = "Unknown Module"
if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
cursor?.use {
if (it.moveToFirst()) {
name = it.getString(it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
}
}
} else if (uri.scheme == "file") {
name = uri.lastPathSegment ?: "Unknown Module"
}
return name
}
fun setAppProfileTemplate(id: String, template: String): Boolean {
val shell = getRootShell()
val escapedTemplate = template.replace("\"", "\\\"")
@@ -460,11 +475,4 @@ fun launchApp(packageName: String) {
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)
}
}