manager: hide root-related features if kernelsu version null (#71)

Related PR:
tiann#2483

Also attempting to address this:
tiann#2483 (comment)

Co-authored-by: rsuntk <rsuntk@yukiprjkt.my.id>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
ShirkNeko
2025-04-20 22:30:23 +08:00
parent 1dd8651a1a
commit 5941fa1ec7
4 changed files with 83 additions and 54 deletions

View File

@@ -91,6 +91,14 @@ object Natives {
return version < MINIMAL_SUPPORTED_KERNEL
}
fun isKsuValid(pkgName: String?): Boolean {
if (becomeManager(pkgName)) {
return true
} else {
return false
}
}
@Immutable
@Parcelize
@Keep

View File

@@ -283,14 +283,18 @@ private fun TopBar(
}
var showDropdown by remember { mutableStateOf(false) }
if (Natives.isKsuValid(ksuApp.packageName)) {
IconButton(onClick = { showDropdown = true }) {
Icon(Icons.Filled.Refresh, stringResource(R.string.reboot))
DropdownMenu(expanded = showDropdown, onDismissRequest = { showDropdown = false }
DropdownMenu(
expanded = showDropdown,
onDismissRequest = { showDropdown = false }
) {
RebootDropdownItem(id = R.string.reboot)
val pm = LocalContext.current.getSystemService(Context.POWER_SERVICE) as PowerManager?
val pm =
LocalContext.current.getSystemService(Context.POWER_SERVICE) as PowerManager?
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && pm?.isRebootingUserspaceSupported == true) {
RebootDropdownItem(id = R.string.reboot_userspace, reason = "userspace")
@@ -301,12 +305,14 @@ private fun TopBar(
RebootDropdownItem(id = R.string.reboot_edl, reason = "edl")
}
}
}
},
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
scrollBehavior = scrollBehavior
)
}
@Composable
private fun StatusCard(
kernelVersion: KernelVersion,

View File

@@ -40,6 +40,7 @@ import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.util.*
import androidx.core.content.edit
import zako.zako.zako.R
import zako.zako.zako.*
fun saveCardConfig(context: Context) {
@@ -175,6 +176,7 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
)
var showThemeColorDialog by remember { mutableStateOf(false) }
val ksuIsValid = Natives.isKsuValid(ksuApp.packageName)
// 图片选择器
val pickImageLauncher = rememberLauncherForActivityResult(
@@ -208,6 +210,7 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
.padding(top = 12.dp)
) {
// SELinux 开关
if (ksuIsValid) {
SwitchItem(
icon = Icons.Filled.Security,
title = stringResource(R.string.selinux),
@@ -221,6 +224,7 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
if (result.isSuccess) selinuxEnabled = enabled
}
}
}
var isExpanded by remember { mutableStateOf(false) }

View File

@@ -49,6 +49,7 @@ import kotlinx.coroutines.withContext
import zako.zako.zako.BuildConfig
import zako.zako.zako.Natives
import zako.zako.zako.R
import zako.zako.zako.*
import zako.zako.zako.ui.component.*
import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.util.LocalSnackbarHost
@@ -68,6 +69,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
// region 界面基础设置
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val snackBarHost = LocalSnackbarHost.current
val ksuIsValid = Natives.isKsuValid(ksuApp.packageName)
// endregion
Scaffold(
@@ -115,6 +117,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
// region 配置项列表
// 配置文件模板入口
val profileTemplate = stringResource(id = R.string.settings_profile_template)
if (ksuIsValid) {
ListItem(
leadingContent = { Icon(Icons.Filled.Fence, profileTemplate) },
headlineContent = { Text(profileTemplate) },
@@ -123,10 +126,13 @@ fun SettingScreen(navigator: DestinationsNavigator) {
navigator.navigate(AppProfileTemplateScreenDestination)
}
)
}
// 卸载模块开关
var umountChecked by rememberSaveable {
mutableStateOf(Natives.isDefaultUmountModules())
}
if (ksuIsValid) {
SwitchItem(
icon = Icons.Filled.FolderDelete,
title = stringResource(id = R.string.settings_umount_modules_default),
@@ -137,7 +143,9 @@ fun SettingScreen(navigator: DestinationsNavigator) {
umountChecked = it
}
}
}
// SU 禁用开关(仅在兼容版本显示)
if (ksuIsValid) {
if (Natives.version >= Natives.MINIMAL_SUPPORTED_SU_COMPAT) {
var isSuDisabled by rememberSaveable {
mutableStateOf(!Natives.isSuEnabled())
@@ -154,6 +162,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
}
}
}
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
@@ -179,6 +188,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
prefs.getBoolean("enable_web_debugging", false)
)
}
if (Natives.isKsuValid(ksuApp.packageName)) {
SwitchItem(
icon = Icons.Filled.DeveloperMode,
title = stringResource(id = R.string.enable_web_debugging),
@@ -188,6 +198,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
prefs.edit { putBoolean("enable_web_debugging", it) }
enableWebDebugging = it
}
}
// 更多设置
val newButtonTitle = stringResource(id = R.string.more_settings)
ListItem(