manager: Add app profile implementation

This commit is contained in:
tiann
2023-05-16 17:15:01 +08:00
parent c1427f658a
commit c7adb8e3b1
6 changed files with 166 additions and 15 deletions

View File

@@ -60,10 +60,49 @@ Java_me_weishu_kernelsu_Natives_allowRoot(JNIEnv *env, jclass clazz, jint uid, j
return allow_su(uid, allow);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_isSafeMode(JNIEnv *env, jclass clazz) {
return is_safe_mode();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_isAllowlistMode(JNIEnv *env, jclass clazz) {
return is_allowlist_mode();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_setAllowlistMode(JNIEnv *env, jclass clazz, jboolean is_allowlist) {
return set_allowlist_mode(is_allowlist);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_addUidToAllowlist(JNIEnv *env, jclass clazz, jint uid) {
return add_to_allow_list(uid);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_removeUidFromAllowlist(JNIEnv *env, jclass clazz, jint uid) {
return remove_from_allow_list(uid);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_addUidToDenylist(JNIEnv *env, jclass clazz, jint uid) {
return add_to_deny_list(uid);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_removeUidFromDenylist(JNIEnv *env, jclass clazz, jint uid) {
return remove_from_deny_list(uid);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_isUidInAllowlist(JNIEnv *env, jclass clazz, jint uid) {
return is_in_allow_list(uid);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_isUidInDenylist(JNIEnv *env, jclass clazz, jint uid) {
return is_in_deny_list(uid);
}

View File

@@ -18,10 +18,19 @@
#define CMD_GET_VERSION 2
#define CMD_ALLOW_SU 3
#define CMD_DENY_SU 4
#define CMD_GET_ALLOW_LIST 5
#define CMD_GET_SU_LIST 5
#define CMD_GET_DENY_LIST 6
#define CMD_CHECK_SAFEMODE 9
#define CMD_GET_WORK_MODE 10
#define CMD_SET_WORK_MODE 11
#define CMD_IN_ALLOW_LIST 12
#define CMD_IN_DENY_LIST 13
#define CMD_ADD_ALLOW_LIST 14
#define CMD_REMOVE_ALLOW_LIST 15
#define CMD_ADD_DENY_LIST 16
#define CMD_REMOVE_DENY_LIST 17
static bool ksuctl(int cmd, void* arg1, void* arg2) {
int32_t result = 0;
prctl(KERNEL_SU_OPTION, cmd, arg1, arg2, &result);
@@ -55,7 +64,7 @@ bool allow_su(int uid, bool allow) {
}
bool get_allow_list(int *uids, int *size) {
return ksuctl(CMD_GET_ALLOW_LIST, uids, size);
return ksuctl(CMD_GET_SU_LIST, uids, size);
}
bool get_deny_list(int *uids, int *size) {
@@ -64,4 +73,40 @@ bool get_deny_list(int *uids, int *size) {
bool is_safe_mode() {
return ksuctl(CMD_CHECK_SAFEMODE, nullptr, nullptr);
}
bool is_allowlist_mode() {
int32_t mode = -1;
ksuctl(CMD_GET_WORK_MODE, &mode, nullptr);
// for kernel that doesn't support allowlist mode, return -1 and it is always allowlist mode
return mode <= 0;
}
bool set_allowlist_mode(bool allowlist_mode) {
int32_t mode = allowlist_mode ? 0 : 1;
return ksuctl(CMD_SET_WORK_MODE, &mode, nullptr);
}
bool is_in_allow_list(int uid) {
return ksuctl(CMD_IN_ALLOW_LIST, &uid, nullptr);
}
bool is_in_deny_list(int uid) {
return ksuctl(CMD_IN_DENY_LIST, &uid, nullptr);
}
bool add_to_allow_list(int uid) {
return ksuctl(CMD_ADD_ALLOW_LIST, &uid, nullptr);
}
bool remove_from_allow_list(int uid) {
return ksuctl(CMD_REMOVE_ALLOW_LIST, &uid, nullptr);
}
bool add_to_deny_list(int uid) {
return ksuctl(CMD_ADD_DENY_LIST, &uid, nullptr);
}
bool remove_from_deny_list(int uid) {
return ksuctl(CMD_REMOVE_DENY_LIST, &uid, nullptr);
}

View File

@@ -17,4 +17,20 @@ bool get_deny_list(int *uids, int *size);
bool is_safe_mode();
bool is_allowlist_mode();
bool set_allowlist_mode(bool allowlist_mode);
bool is_in_allow_list(int uid);
bool is_in_deny_list(int uid);
bool add_to_allow_list(int uid);
bool remove_from_allow_list(int uid);
bool add_to_deny_list(int uid);
bool remove_from_deny_list(int uid);
#endif //KERNELSU_KSU_H