From e09794585172858c64e220e4a84b5ed9ad2d4e76 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 5 Oct 2026 21:53:29 +0000 Subject: [PATCH] su: unify su usage callback to notify action Consolidate su notification and logging IPC calls into a single notify action on the native side, passing all logging parameters along with an explicit "log" boolean key. On the application side, retain the existing "log" action entry point for backwards compatibility with older daemons, and update the "notify" handler to dispatch to either logging or notification based on the boolean values. Assisted-by: Gemini 3.8 Flash --- .../magisk/core/su/SuCallbackHandler.kt | 8 +++- native/src/core/su/connect.rs | 40 ++++--------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt index cd85ebe43..f0a6842fb 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt @@ -36,7 +36,13 @@ object SuCallbackHandler { when (action) { LOG -> handleLogging(context, data) - NOTIFY -> handleNotify(context, data) + NOTIFY -> { + if (data.getBoolean("log", false)) { + handleLogging(context, data) + } else if (data.getBoolean("notify", true)) { + handleNotify(context, data) + } + } } } diff --git a/native/src/core/su/connect.rs b/native/src/core/su/connect.rs index 6ddd54651..0051aaadc 100644 --- a/native/src/core/su/connect.rs +++ b/native/src/core/su/connect.rs @@ -108,31 +108,7 @@ impl MagiskD { } } - fn app_notify(&self, cred: &UCred, info: &SuInfo) { - let extras = [ - Extra { - key: "from.uid", - value: Int(cred.uid.as_()), - }, - Extra { - key: "pid", - value: Int(cred.pid.unwrap_or(-1).as_()), - }, - Extra { - key: "policy", - value: Int(info.settings.policy.repr), - }, - ]; - if to_app_id(info.eval_uid) < AID_APP_START { - for user in self.get_users() { - self.exec_cmd(user, &info.mgr_pkg, "notify", &extras); - } - } else { - self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "notify", &extras); - } - } - - fn app_log(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) { + fn app_notify(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) { let command = if request.command.is_empty() { &request.shell } else { @@ -175,13 +151,17 @@ impl MagiskD { key: "notify", value: Bool(info.settings.notify), }, + Extra { + key: "log", + value: Bool(info.settings.log), + }, ]; if to_app_id(info.eval_uid) < AID_APP_START { for user in self.get_users() { - self.exec_cmd(user, &info.mgr_pkg, "log", &extras); + self.exec_cmd(user, &info.mgr_pkg, "notify", &extras); } } else { - self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "log", &extras); + self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "notify", &extras); } } @@ -199,11 +179,7 @@ impl MagiskD { } // Notify su usage to application - if info.settings.log { - self.app_log(cred, info, request); - } else if info.settings.notify { - self.app_notify(cred, info); - } + self.app_notify(cred, info, request); exit(0); }