From 8f0cc199e72cdc4403778aef9e126b6f12f68a25 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 5 Oct 2026 23:54:11 +0000 Subject: [PATCH] core: resolve user 0 assumptions for HSUM On Headless System User Mode (HSUM) devices, user 0 is headless while human users operate under secondary user IDs. Eliminate residual assumptions in core native components where user 0 was presumed to be the sole or active manager user: - In setup_magisk_env, scan all existing users via get_users() to check if the app-local binary install directory exists. - In ensure_manager, check all users before falling back to stub install so an already-installed manager on a secondary user is recognized. - Pass --user all to pm install, pm uninstall, and appops set in package management scripts to handle manager lifecycle device-wide. Assisted-by: Gemini 3.8 Flash --- native/src/core/bootstages.rs | 18 +++++++++++------- native/src/core/package.rs | 6 ++++++ native/src/core/scripting.cpp | 6 +++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/native/src/core/bootstages.rs b/native/src/core/bootstages.rs index d0403def1..bada63a90 100644 --- a/native/src/core/bootstages.rs +++ b/native/src/core/bootstages.rs @@ -35,17 +35,21 @@ impl MagiskD { let mut buf = cstr::buf::default(); - let app_bin_dir = buf - .append_path(self.app_data_dir()) - .append_path("0") - .append_path(APP_PACKAGE_NAME) - .append_path("install"); + for user in self.get_users() { + buf.append_path(self.app_data_dir()) + .append_path_fmt(user) + .append_path(APP_PACKAGE_NAME) + .append_path("install"); + if buf.exists() { + break; + } + } // Alternative binaries paths - let alt_bin_dirs = &[ + let alt_bin_dirs = [ cstr!("/cache/data_adb/magisk"), cstr!("/data/magisk"), - app_bin_dir, + &buf, ]; for dir in alt_bin_dirs { if dir.exists() { diff --git a/native/src/core/package.rs b/native/src/core/package.rs index 3e266549d..79089c929 100644 --- a/native/src/core/package.rs +++ b/native/src/core/package.rs @@ -469,6 +469,12 @@ impl MagiskD { pub fn ensure_manager(&self) { let mut info = self.manager_info.lock(); + for user in self.get_users() { + let (_, pkg) = info.get_manager(self, user, false); + if !pkg.is_empty() { + return; + } + } let _ = info.get_manager(self, 0, true); } diff --git a/native/src/core/scripting.cpp b/native/src/core/scripting.cpp index e6ddedf4e..7b7929380 100644 --- a/native/src/core/scripting.cpp +++ b/native/src/core/scripting.cpp @@ -235,8 +235,8 @@ void exec_module_scripts(Utf8CStr stage, const rust::Vec &module_lis constexpr char install_script[] = R"EOF( APK=%s log -t Magisk "pm_install: $APK" -log -t Magisk "pm_install: $(pm install -g -r $APK 2>&1)" -appops set %s REQUEST_INSTALL_PACKAGES allow +log -t Magisk "pm_install: $(pm install --user all -g -r $APK 2>&1)" +appops set --user all %s REQUEST_INSTALL_PACKAGES allow rm -f $APK )EOF"; @@ -250,7 +250,7 @@ void install_apk(Utf8CStr apk) { constexpr char uninstall_script[] = R"EOF( PKG=%s log -t Magisk "pm_uninstall: $PKG" -log -t Magisk "pm_uninstall: $(pm uninstall $PKG 2>&1)" +log -t Magisk "pm_uninstall: $(pm uninstall --user all $PKG 2>&1)" )EOF"; void uninstall_pkg(Utf8CStr pkg) {