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
This commit is contained in:
topjohnwu
2026-10-05 18:20:32 -07:00
committed by John Wu
parent 813f9cb9d4
commit e097945851
2 changed files with 15 additions and 33 deletions
@@ -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)
}
}
}
}
+8 -32
View File
@@ -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);
}