manager: Add require new kernel version.
This commit is contained in:
@@ -12,6 +12,10 @@ object Natives {
|
||||
const val DEFAULT_ROOT_PROFILE_KEY = "_root_default_"
|
||||
const val DEFAULT_NON_ROOT_PROFILE_KEY = "_non_root_default_"
|
||||
|
||||
// minimal supported kernel version
|
||||
// 10915: allowlist breaking change
|
||||
const val MINIMAL_SUPPORTED_KERNEL = 10916
|
||||
|
||||
init {
|
||||
System.loadLibrary("kernelsu")
|
||||
}
|
||||
@@ -39,6 +43,9 @@ object Natives {
|
||||
external fun getAppProfile(key: String?, uid: Int): Profile
|
||||
external fun setAppProfile(profile: Profile?): Boolean
|
||||
|
||||
fun requireNewKernel(): Boolean {
|
||||
return version < MINIMAL_SUPPORTED_KERNEL
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@Parcelize
|
||||
|
||||
@@ -66,9 +66,10 @@ class MainActivity : ComponentActivity() {
|
||||
@Composable
|
||||
private fun BottomBar(navController: NavHostController) {
|
||||
val isManager = Natives.becomeManager(ksuApp.packageName)
|
||||
val fullFeatured = isManager && !Natives.requireNewKernel()
|
||||
NavigationBar(tonalElevation = 8.dp) {
|
||||
BottomBarDestination.values().forEach { destination ->
|
||||
if (!isManager && destination.rootRequired) return@forEach
|
||||
if (!fullFeatured && destination.rootRequired) return@forEach
|
||||
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
|
||||
NavigationBarItem(
|
||||
selected = isCurrentDestOnBackStack,
|
||||
|
||||
@@ -59,6 +59,14 @@ fun HomeScreen(navigator: DestinationsNavigator) {
|
||||
val ksuVersion = if (isManager) Natives.version else null
|
||||
|
||||
StatusCard(kernelVersion, ksuVersion)
|
||||
if (Natives.requireNewKernel()) {
|
||||
WarningCard(
|
||||
stringResource(id = R.string.require_kernel_version).format(
|
||||
ksuVersion,
|
||||
Natives.MINIMAL_SUPPORTED_KERNEL
|
||||
)
|
||||
)
|
||||
}
|
||||
InfoCard()
|
||||
DonateCard()
|
||||
LearnMoreCard()
|
||||
@@ -159,7 +167,10 @@ private fun StatusCard(kernelVersion: KernelVersion, ksuVersion: Int?) {
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.home_superuser_count, getSuperuserCount()),
|
||||
text = stringResource(
|
||||
R.string.home_superuser_count,
|
||||
getSuperuserCount()
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
@@ -169,6 +180,7 @@ private fun StatusCard(kernelVersion: KernelVersion, ksuVersion: Int?) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
kernelVersion.isGKI() -> {
|
||||
Icon(Icons.Outlined.Warning, stringResource(R.string.home_not_installed))
|
||||
Column(Modifier.padding(start = 20.dp)) {
|
||||
@@ -183,6 +195,7 @@ private fun StatusCard(kernelVersion: KernelVersion, ksuVersion: Int?) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
Icon(Icons.Outlined.Block, stringResource(R.string.home_unsupported))
|
||||
Column(Modifier.padding(start = 20.dp)) {
|
||||
@@ -203,6 +216,29 @@ private fun StatusCard(kernelVersion: KernelVersion, ksuVersion: Int?) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun WarningCard(message: String) {
|
||||
ElevatedCard(
|
||||
colors = CardDefaults.elevatedCardColors(
|
||||
containerColor = MaterialTheme.colorScheme.error
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column() {
|
||||
Text(
|
||||
text = message,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LearnMoreCard() {
|
||||
val uriHandler = LocalUriHandler.current
|
||||
|
||||
@@ -51,10 +51,9 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
|
||||
val isSafeMode = Natives.isSafeMode
|
||||
val isKSUVersionInvalid = Natives.version < 0
|
||||
val hasMagisk = hasMagisk()
|
||||
|
||||
val hideInstallButton = isSafeMode || isKSUVersionInvalid || hasMagisk
|
||||
val hideInstallButton = isSafeMode || hasMagisk
|
||||
|
||||
Scaffold(topBar = {
|
||||
TopBar()
|
||||
@@ -93,11 +92,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
ConfirmDialog()
|
||||
|
||||
when {
|
||||
isKSUVersionInvalid -> {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Text(stringResource(R.string.require_kernel_version_8))
|
||||
}
|
||||
}
|
||||
hasMagisk -> {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<string name="home_support_title">支持开发</string>
|
||||
<string name="home_support_content">KernelSU 将保持免费和开源,向开发者捐赠以表示支持。</string>
|
||||
<string name="about_source_code"><![CDATA[在 %1$s 查看源码<br/>加入我们的 %2$s 频道<br/>加入我们的 <b><a href="https://pd.qq.com/s/8lipl1brp">QQ 频道</a></b>]]></string>
|
||||
<string name="require_kernel_version">当前内核版本: %d 过低,管理器无法正常工作,请升级内核版本至 %d 或以上!</string>
|
||||
<string name="app_profile_title1">应用</string>
|
||||
<string name="app_profile_title0">全局</string>
|
||||
<string name="app_profile_allowlist">白名单</string>
|
||||
|
||||
@@ -78,4 +78,5 @@
|
||||
<string name="profile_allow_root_request">Allow root request</string>
|
||||
<string name="failed_to_update_root_profile">Failed to update root profile for %s</string>
|
||||
<string name="failed_to_update_app_profile">Failed to update app profile for %s</string>
|
||||
<string name="require_kernel_version">The current kernel version: %d is too low for the manager to function properly. Please upgrade to version %d or higher!</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user