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