From e969563df08b6b137a92376205546cde10b218b5 Mon Sep 17 00:00:00 2001 From: weishu Date: Sun, 4 Jun 2023 09:52:45 +0800 Subject: [PATCH] manager: Add UMOUNT badge --- manager/app/src/main/cpp/jni.cc | 5 +++++ manager/app/src/main/cpp/ksu.cc | 8 ++++++++ manager/app/src/main/cpp/ksu.h | 2 ++ manager/app/src/main/java/me/weishu/kernelsu/Natives.kt | 2 ++ .../main/java/me/weishu/kernelsu/ui/screen/SuperUser.kt | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/manager/app/src/main/cpp/jni.cc b/manager/app/src/main/cpp/jni.cc index e110566f..fc1857e8 100644 --- a/manager/app/src/main/cpp/jni.cc +++ b/manager/app/src/main/cpp/jni.cc @@ -237,4 +237,9 @@ Java_me_weishu_kernelsu_Natives_setAppProfile(JNIEnv *env, jobject clazz, jobjec } return set_app_profile(&p); +} +extern "C" +JNIEXPORT jboolean JNICALL +Java_me_weishu_kernelsu_Natives_uidShouldUmount(JNIEnv *env, jobject thiz, jint uid) { + return uid_should_umount(uid); } \ No newline at end of file diff --git a/manager/app/src/main/cpp/ksu.cc b/manager/app/src/main/cpp/ksu.cc index d9529b2b..1ad43763 100644 --- a/manager/app/src/main/cpp/ksu.cc +++ b/manager/app/src/main/cpp/ksu.cc @@ -25,6 +25,9 @@ #define CMD_GET_APP_PROFILE 10 #define CMD_SET_APP_PROFILE 11 +#define CMD_IS_UID_GRANTED_ROOT 12 +#define CMD_IS_UID_SHOULD_UMOUNT 13 + static bool ksuctl(int cmd, void* arg1, void* arg2) { int32_t result = 0; prctl(KERNEL_SU_OPTION, cmd, arg1, arg2, &result); @@ -60,6 +63,11 @@ bool is_safe_mode() { return ksuctl(CMD_CHECK_SAFEMODE, nullptr, nullptr); } +bool uid_should_umount(int uid) { + bool should; + return ksuctl(CMD_IS_UID_SHOULD_UMOUNT, reinterpret_cast(uid), &should) && should; +} + bool set_app_profile(const app_profile *profile) { return ksuctl(CMD_SET_APP_PROFILE, (void*) profile, nullptr); } diff --git a/manager/app/src/main/cpp/ksu.h b/manager/app/src/main/cpp/ksu.h index b7dec766..0fea38c0 100644 --- a/manager/app/src/main/cpp/ksu.h +++ b/manager/app/src/main/cpp/ksu.h @@ -11,6 +11,8 @@ int get_version(); bool get_allow_list(int *uids, int *size); +bool uid_should_umount(int uid); + bool is_safe_mode(); #define KSU_APP_PROFILE_VER 1 diff --git a/manager/app/src/main/java/me/weishu/kernelsu/Natives.kt b/manager/app/src/main/java/me/weishu/kernelsu/Natives.kt index 52c391c2..13de8598 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/Natives.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/Natives.kt @@ -31,6 +31,8 @@ object Natives { val isSafeMode: Boolean external get + external fun uidShouldUmount(uid: Int): Boolean + /** * Get the profile of the given package. * @param key usually the package name diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/SuperUser.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/SuperUser.kt index eb85a52d..643c4741 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/SuperUser.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/SuperUser.kt @@ -28,6 +28,7 @@ import coil.request.ImageRequest import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.navigation.DestinationsNavigator import kotlinx.coroutines.launch +import me.weishu.kernelsu.Natives import me.weishu.kernelsu.R import me.weishu.kernelsu.ui.component.ConfirmDialog import me.weishu.kernelsu.ui.component.SearchAppBar @@ -139,6 +140,10 @@ private fun AppItem( FlowRow { if (app.allowSu) { LabelText(label = "ROOT") + } else { + if (Natives.uidShouldUmount(app.uid)) { + LabelText(label = "UMOUNT") + } } if (app.hasCustomProfile) { LabelText(label = "CUSTOM")