manager: disable module and superuser navigation if sucompat is disabled and also show an indicator in status card

This commit is contained in:
Rifat Azad
2025-06-15 22:07:15 +06:00
parent f1ef0afc20
commit 71eba5df8b
4 changed files with 83 additions and 45 deletions

View File

@@ -1,5 +1,7 @@
package com.rifsxd.ksunext.ui package com.rifsxd.ksunext.ui
import android.content.Intent
import android.net.Uri
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@@ -54,9 +56,7 @@ import com.rifsxd.ksunext.ui.theme.KernelSUTheme
import com.rifsxd.ksunext.ui.util.LocalSnackbarHost import com.rifsxd.ksunext.ui.util.LocalSnackbarHost
import com.rifsxd.ksunext.ui.util.rootAvailable import com.rifsxd.ksunext.ui.util.rootAvailable
import com.rifsxd.ksunext.ui.util.install import com.rifsxd.ksunext.ui.util.install
import com.rifsxd.ksunext.ui.util.isSuCompatDisabled
import android.content.Intent
import android.net.Uri
import com.rifsxd.ksunext.ui.screen.FlashIt import com.rifsxd.ksunext.ui.screen.FlashIt
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@@ -167,39 +167,48 @@ private fun BottomBar(navController: NavHostController) {
val navigator = navController.rememberDestinationsNavigator() val navigator = navController.rememberDestinationsNavigator()
val isManager = Natives.becomeManager(ksuApp.packageName) val isManager = Natives.becomeManager(ksuApp.packageName)
val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable() val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable()
val suCompatDisabled = isSuCompatDisabled()
NavigationBar( NavigationBar(
tonalElevation = 8.dp, tonalElevation = 8.dp,
windowInsets = WindowInsets.systemBars.union(WindowInsets.displayCutout).only( windowInsets = WindowInsets.systemBars.union(WindowInsets.displayCutout).only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
) )
) { ) {
BottomBarDestination.entries.forEach { destination -> BottomBarDestination.entries
if (!fullFeatured && destination.rootRequired) return@forEach .filter {
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction) // Hide SuperUser and Module when su compat is enabled
NavigationBarItem( if (suCompatDisabled) {
selected = isCurrentDestOnBackStack, it != BottomBarDestination.SuperUser && it != BottomBarDestination.Module
onClick = { } else true
if (isCurrentDestOnBackStack) { }
navigator.popBackStack(destination.direction, false) .forEach { destination ->
} if (!fullFeatured && destination.rootRequired) return@forEach
navigator.navigate(destination.direction) { val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
popUpTo(NavGraphs.root) { NavigationBarItem(
saveState = true selected = isCurrentDestOnBackStack,
onClick = {
if (isCurrentDestOnBackStack) {
navigator.popBackStack(destination.direction, false)
} }
launchSingleTop = true navigator.navigate(destination.direction) {
restoreState = true popUpTo(NavGraphs.root) {
} saveState = true
}, }
icon = { launchSingleTop = true
if (isCurrentDestOnBackStack) { restoreState = true
Icon(destination.iconSelected, stringResource(destination.label)) }
} else { },
Icon(destination.iconNotSelected, stringResource(destination.label)) icon = {
} if (isCurrentDestOnBackStack) {
}, Icon(destination.iconSelected, stringResource(destination.label))
label = { Text(stringResource(destination.label)) }, } else {
alwaysShowLabel = true Icon(destination.iconNotSelected, stringResource(destination.label))
) }
} },
label = { Text(stringResource(destination.label)) },
alwaysShowLabel = true
)
}
} }
} }

View File

@@ -322,25 +322,49 @@ private fun StatusCard(
val labelStyle = LabelItemDefaults.style val labelStyle = LabelItemDefaults.style
TextRow( TextRow(
trailingContent = { trailingContent = {
LabelItem( Row(
icon = if (Natives.isSafeMode) { verticalAlignment = Alignment.CenterVertically,
{ horizontalArrangement = Arrangement.spacedBy(6.dp)
Icon( ) {
tint = labelStyle.contentColor, LabelItem(
imageVector = Icons.Filled.Security, icon = if (Natives.isSafeMode) {
contentDescription = null {
Icon(
tint = labelStyle.contentColor,
imageVector = Icons.Filled.Security,
contentDescription = null
)
}
} else {
null
},
text = {
Text(
text = workingMode,
style = labelStyle.textStyle.copy(color = labelStyle.contentColor),
) )
} }
} else { )
null if (isSuCompatDisabled()) {
}, LabelItem(
text = { icon = {
Text( Icon(
text = workingMode, tint = labelStyle.contentColor,
style = labelStyle.textStyle.copy(color = labelStyle.contentColor), imageVector = Icons.Filled.Warning,
contentDescription = null
)
},
text = {
Text(
text = stringResource(R.string.sucompat_disabled),
style = labelStyle.textStyle.copy(
color = labelStyle.contentColor,
)
)
}
) )
} }
) }
} }
) { ) {
Text( Text(

View File

@@ -628,6 +628,10 @@ fun getModuleSize(dir: File): Long {
return result.toLongOrNull() ?: 0L return result.toLongOrNull() ?: 0L
} }
fun isSuCompatDisabled(): Boolean {
return Natives.version >= Natives.MINIMAL_SUPPORTED_SU_COMPAT && !Natives.isSuEnabled()
}
fun setAppProfileTemplate(id: String, template: String): Boolean { fun setAppProfileTemplate(id: String, template: String): Boolean {
val shell = getRootShell() val shell = getRootShell()
val escapedTemplate = template.replace("\"", "\\\"") val escapedTemplate = template.replace("\"", "\\\"")

View File

@@ -221,4 +221,5 @@
<string name="use_webuix_eruda_summary">Inject a debug console into WebUI X to make debugging easier. Requires web debugging to be on.</string> <string name="use_webuix_eruda_summary">Inject a debug console into WebUI X to make debugging easier. Requires web debugging to be on.</string>
<string name="customization">Customization</string> <string name="customization">Customization</string>
<string name="developer">Developer</string> <string name="developer">Developer</string>
<string name="sucompat_disabled">SUCOMPAT DISABLED</string>
</resources> </resources>