manager: try detect susfs prctl and

show if susfs supported and version on HomeScreen
This commit is contained in:
Rifat Azad
2024-12-22 06:32:08 +06:00
parent fd637d30cf
commit 66d7f88448
6 changed files with 52 additions and 22 deletions

View File

@@ -10,6 +10,23 @@
#define LOG_TAG "KernelSU-Next"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1
extern "C"
JNIEXPORT jstring JNICALL
Java_com_rifsxd_ksunext_Natives_getSusfsVersion(JNIEnv *env, jobject) {
int error = -1;
char susfsVersion[16];
error = prctl(KERNEL_SU_OPTION, CMD_SUSFS_SHOW_VERSION, susfsVersion, NULL, &error);
if (!error) {
return env->NewStringUTF(susfsVersion);
LOGD("susfs: found");
} else {
LOGD("susfs: not foung");
return env->NewStringUTF("Error fetching version");
}
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_rifsxd_ksunext_Natives_becomeManager(JNIEnv *env, jobject, jstring pkg) {

View File

@@ -10,8 +10,6 @@
#include "ksu.h"
#define KERNEL_SU_OPTION 0xDEADBEEF
#define CMD_GRANT_ROOT 0
#define CMD_BECOME_MANAGER 1

View File

@@ -7,6 +7,10 @@
#include <linux/capability.h>
#define KERNEL_SU_OPTION 0xDEADBEEF
#define CMD_SUSFS_SHOW_VERSION 0x555e1
bool become_manager(const char *);
int get_version();

View File

@@ -30,6 +30,8 @@ object Natives {
System.loadLibrary("kernelsu")
}
external fun getSusfsVersion(): String
// become root manager, return true if success.
external fun becomeManager(pkg: String?): Boolean
val version: Int

View File

@@ -268,10 +268,15 @@ private fun StatusCard(
style = MaterialTheme.typography.bodyMedium
)
Spacer(Modifier.height(4.dp))
Text(
text = stringResource(R.string.home_susfs, getSuSFS()),
style = MaterialTheme.typography.bodyMedium
)
val suSFS = getSuSFS()
if (suSFS != "Unsupported") {
Text(
text = stringResource(R.string.home_susfs, suSFS),
style = MaterialTheme.typography.bodyMedium
)
}
}
}
@@ -400,14 +405,16 @@ private fun InfoCard() {
)
Spacer(Modifier.height(16.dp))
val suSfsStatus = getSuSFS()
if (suSfsStatus != "Unsupported") {
val suSFS = getSuSFS()
if (suSFS != "Unsupported") {
InfoCardItem(
label = stringResource(R.string.home_susfs_version),
content = getSuSFSVersion(),
icon = Icons.Filled.SettingsSuggest,
)
}
}
}
}

View File

@@ -120,25 +120,27 @@ fun getModuleCount(): Int {
}.getOrElse { return 0 }
}
// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1
fun getSuSFS(): String {
val shell = getRootShell()
val result = ShellUtils.fastCmd(shell, "dmesg | grep -i susfs")
return if (result.isNotBlank()) {
"Supported"
} else {
"Unsupported"
return try {
val sus_version = Natives.getSusfsVersion()
if (sus_version.startsWith("v")) {
"Supported"
} else {
"Unsupported"
}
} catch (e: Exception) {
"Error: ${e.message}"
}
}
// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1
fun getSuSFSVersion(): String {
val shell = getRootShell()
val result = ShellUtils.fastCmd(shell, "su -c ksu_susfs show version")
return if (result.startsWith("v")) {
result
} else {
"Unavailable"
return try {
val sus_version = Natives.getSusfsVersion()
sus_version ?: "Unknown version"
} catch (e: Exception) {
"Error: ${e.message}"
}
}