From 177ef6b6345c2c9ad48a9587b7ffa77643700a3c Mon Sep 17 00:00:00 2001 From: weishu Date: Sun, 17 Mar 2024 12:00:44 +0800 Subject: [PATCH] manager: Add tips for select boot image --- .../me/weishu/kernelsu/ui/screen/Install.kt | 36 ++++++++++++++++--- .../java/me/weishu/kernelsu/ui/util/KsuCli.kt | 7 ++++ .../src/main/res/values-zh-rCN/strings.xml | 1 + manager/app/src/main/res/values/strings.xml | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt index d376b0c7..bb7a6766 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.widget.Toast import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts +import androidx.annotation.StringRes import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -46,6 +47,7 @@ import me.weishu.kernelsu.ui.util.DownloadListener import me.weishu.kernelsu.ui.util.download import me.weishu.kernelsu.ui.util.getLKMUrl import me.weishu.kernelsu.ui.util.isAbDevice +import me.weishu.kernelsu.ui.util.isInitBoot import me.weishu.kernelsu.ui.util.rootAvailable /** @@ -173,8 +175,11 @@ fun InstallScreen(navigator: DestinationsNavigator) { } sealed class InstallMethod { - data class SelectFile(val uri: Uri? = null, override val label: Int = R.string.select_file) : - InstallMethod() + data class SelectFile( + val uri: Uri? = null, + @StringRes override val label: Int = R.string.select_file, + override val summary: String? + ) : InstallMethod() object DirectInstall : InstallMethod() { override val label: Int @@ -187,13 +192,19 @@ sealed class InstallMethod { } abstract val label: Int + open val summary: String? = null } @Composable private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) { val rootAvailable = rootAvailable() val isAbDevice = isAbDevice() - val radioOptions = mutableListOf(InstallMethod.SelectFile()) + val selectFileTip = stringResource( + id = R.string.select_file_tip, + if (isInitBoot()) "init_boot" else "boot" + ) + val radioOptions = + mutableListOf(InstallMethod.SelectFile(summary = selectFileTip)) if (rootAvailable) { radioOptions.add(InstallMethod.DirectInstall) @@ -208,7 +219,7 @@ private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) { ) { if (it.resultCode == Activity.RESULT_OK) { it.data?.data?.let { uri -> - val option = InstallMethod.SelectFile(uri) + val option = InstallMethod.SelectFile(uri, summary = selectFileTip) selectedOption = option onSelected(option) } @@ -255,7 +266,22 @@ private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) { RadioButton(selected = option.javaClass == selectedOption?.javaClass, onClick = { onClick(option) }) - Text(text = stringResource(id = option.label)) + Column { + Text( + text = stringResource(id = option.label), + fontSize = MaterialTheme.typography.titleMedium.fontSize, + fontFamily = MaterialTheme.typography.titleMedium.fontFamily, + fontStyle = MaterialTheme.typography.titleMedium.fontStyle + ) + option.summary?.let { + Text( + text = it, + fontSize = MaterialTheme.typography.bodySmall.fontSize, + fontFamily = MaterialTheme.typography.bodySmall.fontFamily, + fontStyle = MaterialTheme.typography.bodySmall.fontStyle + ) + } + } } } } diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt index 030da06f..c76b646d 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt @@ -1,6 +1,7 @@ package me.weishu.kernelsu.ui.util import android.net.Uri +import android.os.Build import android.os.Environment import android.os.SystemClock import android.util.Log @@ -237,6 +238,12 @@ fun isAbDevice(): Boolean { return ShellUtils.fastCmd(shell, "getprop ro.build.ab_update").trim().toBoolean() } +fun isInitBoot(): Boolean { + val shell = getRootShell() + // https://source.android.com/docs/core/architecture/partitions/generic-boot + return ShellUtils.fastCmd(shell, "getprop ro.product.first_api_level").trim().toInt() >= Build.VERSION_CODES.TIRAMISU +} + fun overlayFsAvailable(): Boolean { val shell = getRootShell() // check /proc/filesystems diff --git a/manager/app/src/main/res/values-zh-rCN/strings.xml b/manager/app/src/main/res/values-zh-rCN/strings.xml index 804ee1a2..41d1a0bb 100644 --- a/manager/app/src/main/res/values-zh-rCN/strings.xml +++ b/manager/app/src/main/res/values-zh-rCN/strings.xml @@ -115,4 +115,5 @@ 下一步 获取 LKM 链接失败:%1$s 正在下载:%1$s + 建议选择 %1$s 分区镜像 \ No newline at end of file diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index 7ecb7578..04d95a2b 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -117,4 +117,5 @@ Next Failed to fetch LKM url: %1$s Downloading %1$s + %1$s partition image is recommended