From 8db5a37c651cba4908cb59e85e00994c5ca5061e Mon Sep 17 00:00:00 2001 From: hhhbwc <1926185276@qq.com> Date: Mon, 12 Oct 2026 08:11:15 +0800 Subject: [PATCH] Prefer an installed manager, and start the daemon where unshare is poorer action.sh: the injection path needs ${INJECTED_PACKAGE_NAME} to host a 2D activity and to receive the injected manager dex, neither of which holds in every environment. When the manager has been installed as a regular package -- manager.apk ships inside the module for exactly that -- launch its activity directly and leave the injection path as the fallback. service.sh: "unshare --propagation slave -m" is GNU util-linux syntax; toybox builds that implement only a subset reject the flag outright, which leaves the daemon dead with nothing anywhere to say so. Probe the flag with a throwaway command and fall back to "unshare -m", then to running the daemon without a namespace at all. --- zygisk/module/action.sh | 11 +++++++++++ zygisk/module/service.sh | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/zygisk/module/action.sh b/zygisk/module/action.sh index c3ea8c1a3..58b7d206d 100644 --- a/zygisk/module/action.sh +++ b/zygisk/module/action.sh @@ -1,4 +1,15 @@ MANAGER_PACKAGE_NAME="@MANAGER_PACKAGE_NAME@" INJECTED_PACKAGE_NAME="@INJECTED_PACKAGE_NAME@" +# The manager also ships inside this module as manager.apk and may have been +# installed as a regular package. When it has, launching its activity directly +# is more reliable than the injection path below, which needs +# ${INJECTED_PACKAGE_NAME} to start a 2D activity at all and to receive the +# injected manager dex -- neither holds in every environment (some systems +# never let the shell host an activity, and dynamic code loading restrictions +# can block the dex the way GrapheneOS does, see #805). +if pm path "$MANAGER_PACKAGE_NAME" >/dev/null 2>&1; then + am start -n "$MANAGER_PACKAGE_NAME/.ui.MainActivity" >/dev/null 2>&1 && exit 0 +fi + am start -c "${MANAGER_PACKAGE_NAME}.LAUNCH_MANAGER" "${INJECTED_PACKAGE_NAME}/.BugreportWarningActivity" diff --git a/zygisk/module/service.sh b/zygisk/module/service.sh index e49f8859b..4f2cd362f 100644 --- a/zygisk/module/service.sh +++ b/zygisk/module/service.sh @@ -1,6 +1,16 @@ -# Extract the directory path and change directory +# Extract the directory path and change directory MODDIR="${0%/*}" cd "$MODDIR" || exit 1 -# Start the daemon directly in the background within a private mount namespace -unshare --propagation slave -m "$MODDIR/daemon" --system-server-max-retry=3 "$@" & +# Start the daemon directly in the background within a private mount namespace. +# Not every environment's unshare understands --propagation: toybox builds that +# implement only a subset of util-linux reject the flag outright, which leaves +# the daemon dead with nothing anywhere to say so. Probe the flag with a +# throwaway command and fall back to progressively simpler invocations. +if unshare --propagation slave -m true >/dev/null 2>&1; then + unshare --propagation slave -m "$MODDIR/daemon" --system-server-max-retry=3 "$@" & +elif unshare -m true >/dev/null 2>&1; then + unshare -m "$MODDIR/daemon" --system-server-max-retry=3 "$@" & +else + "$MODDIR/daemon" --system-server-max-retry=3 "$@" & +fi