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,13 +167,22 @@ 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
.filter {
// Hide SuperUser and Module when su compat is enabled
if (suCompatDisabled) {
it != BottomBarDestination.SuperUser && it != BottomBarDestination.Module
} else true
}
.forEach { destination ->
if (!fullFeatured && destination.rootRequired) return@forEach if (!fullFeatured && destination.rootRequired) return@forEach
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction) val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
NavigationBarItem( NavigationBarItem(

View File

@@ -322,6 +322,10 @@ private fun StatusCard(
val labelStyle = LabelItemDefaults.style val labelStyle = LabelItemDefaults.style
TextRow( TextRow(
trailingContent = { trailingContent = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
LabelItem( LabelItem(
icon = if (Natives.isSafeMode) { icon = if (Natives.isSafeMode) {
{ {
@@ -341,6 +345,26 @@ private fun StatusCard(
) )
} }
) )
if (isSuCompatDisabled()) {
LabelItem(
icon = {
Icon(
tint = 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>