添加安装工具类,并增加把kpmmgr安装到/data/adb/ksu/bin的功能,方便模块调用 (#30)

Co-authored-by: liankong <xhsw.new@qq.com>
This commit is contained in:
ShirkNeko
2025-04-07 15:17:46 +08:00
committed by GitHub
parent 040cc30e73
commit 1fce0fd77d
4 changed files with 51 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
package io.sukisu.ultra;
import com.topjohnwu.superuser.Shell;
import java.util.ArrayList;
import shirkneko.zako.sukisu.ui.util.KsuCli;
public class UltraShellHelper {
public static String runCmd(String cmds) {
StringBuilder sb = new StringBuilder();
for(String str : KsuCli.INSTANCE.getGLOBAL_MNT_SHELL()
.newJob()
.add(cmds)
.to(new ArrayList<>(), null)
.exec()
.getOut()) {
sb.append(str).append("\n");
}
return sb.toString();
}
public static boolean isPathExists(String path) {
return !runCmd("file " + path).contains("No such file or directory");
}
public static void CopyFileTo(String path, String target) {
runCmd("cp -f " + path + " " + target);
}
}

View File

@@ -0,0 +1,15 @@
package io.sukisu.ultra;
import static shirkneko.zako.sukisu.ui.util.KsuCliKt.getKpmmgrPath;
import shirkneko.zako.sukisu.ui.util.KsuCli;
public class UltraToolInstall {
private static final String OUTSIDE_KPMMGR_PATH = "/data/adb/ksu/bin/kpmmgr";
public static void tryToInstall() {
String kpmmgrPath = getKpmmgrPath();
if (!UltraShellHelper.isPathExists(OUTSIDE_KPMMGR_PATH)) {
UltraShellHelper.CopyFileTo(kpmmgrPath, OUTSIDE_KPMMGR_PATH);
UltraShellHelper.runCmd("chmod a+rx " + OUTSIDE_KPMMGR_PATH);
}
}
}

View File

@@ -41,6 +41,7 @@ import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationSty
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState
import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator
import io.sukisu.ultra.UltraToolInstall
import shirkneko.zako.sukisu.Natives
import shirkneko.zako.sukisu.ksuApp
import shirkneko.zako.sukisu.ui.screen.BottomBarDestination
@@ -72,7 +73,10 @@ class MainActivity : ComponentActivity() {
val isManager = Natives.becomeManager(ksuApp.packageName)
if (isManager) install()
if (isManager) {
install()
UltraToolInstall.tryToInstall()
}
setContent {
KernelSUTheme {

View File

@@ -481,7 +481,7 @@ fun susfsSUS_SU_Mode(): String {
return result
}
private fun getKpmmgrPath(): String {
fun getKpmmgrPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libkpmmgr.so"
}