From df3f35f4e992de9a65f08b42d46a8ff74e5c7511 Mon Sep 17 00:00:00 2001 From: kenneth topp Date: Thu, 19 Nov 2026 21:02:42 -0500 Subject: [PATCH] Make ViPER installation resilient to unrelated XML and app data timing --- magiskmodule/customize.sh | 14 +++++--------- magiskmodule/service.sh | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/magiskmodule/customize.sh b/magiskmodule/customize.sh index 89a5236..e12adf3 100644 --- a/magiskmodule/customize.sh +++ b/magiskmodule/customize.sh @@ -87,7 +87,7 @@ presetCompatible() { } mkdir -p "$FOLDER"/Preset -CUSTOM_PRESET_FILES=$(find "$SDCARD" -name '*.xml' -not -path "$SDCARD/Android/*") +CUSTOM_PRESET_FILES=$(find "$SDCARD" -path "$SDCARD/Android" -prune -o -type f -name '*.xml' -size -1048576c -print) if [ -n "$CUSTOM_PRESET_FILES" ]; then ui_print "- Copying custom preset files" for file in $CUSTOM_PRESET_FILES; do @@ -106,7 +106,7 @@ osp_detect() { local osp=music case $file in *.conf) - spaces=$(sed -n "/^output_session_processing {/,/^}/ {/^ *$osp {/p}" "$fil"e | sed -r "s/( *).*/\1/") + spaces=$(sed -n "/^output_session_processing {/,/^}/ {/^ *$osp {/p}" "$file" | sed -r "s/( *).*/\1/") effects=$(sed -n "/^output_session_processing {/,/^}/ {/^$spaces\$osp {/,/^$spaces}/p}" "$file" | grep -E "^$spaces +[A-Za-z]+" | sed -r "s/( *.*) .*/\1/g") for effect in ${effects}; do spaces=$(sed -n "/^effects {/,/^}/ {/^ *$effect {/p}" "$file" | sed -r "s/( *).*/\1/") @@ -174,13 +174,9 @@ installAPK || { ! $APK_UPGRADE && pm disable "$VIPERFXPACKAGE" >&2 ui_print "- Configuring ViPER4Android" -VIPERFXPREFS="$(pm dump "$VIPERFXPACKAGE" | grep dataDir | head -n 1 | cut -d'=' -f2)" -VIPERFXPREFSOWNER="$(stat -c '%U' "$VIPERFXPREFS")" -VIPERFXSHAREDPREFS="$VIPERFXPREFS"/shared_prefs -[ ! -d "$VIPERFXSHAREDPREFS" ] && mkdir "$VIPERFXSHAREDPREFS" -cp -f "$MODPATH"/viperfx_preferences.xml "$VIPERFXSHAREDPREFS"/"${VIPERFXPACKAGE}_preferences.xml" -chown -R "$VIPERFXPREFSOWNER":"$VIPERFXPREFSOWNER" "$VIPERFXPREFS" -set_perm_recursive "$FOLDER" "$VIPERFXPREFSOWNER" sdcard_rw 771 660 u:object_r:sdcardfs:s0 +VIPERFXSTORAGEOWNER="$(stat -c '%u' "$FOLDER")" +[ -n "$VIPERFXSTORAGEOWNER" ] || abort "Could not determine ViPER4Android shared-storage owner" +set_perm_recursive "$FOLDER" "$VIPERFXSTORAGEOWNER" sdcard_rw 771 660 u:object_r:sdcardfs:s0 # this permanently hides the notifications without the possiblity of reenabling them [ "$API" -ge 31 ] && pm set-distracting-restriction --flag hide-notifications "$VIPERFXPACKAGE" [ "$API" -ge 33 ] && { diff --git a/magiskmodule/service.sh b/magiskmodule/service.sh index 31c414d..49f2925 100644 --- a/magiskmodule/service.sh +++ b/magiskmodule/service.sh @@ -14,6 +14,28 @@ waitUntilBootCompleted() { waitUntilBootCompleted sleep 10 pm list packages -d | grep -q "$VIPERFXPACKAGE" && pm enable "$VIPERFXPACKAGE" + + # PackageManager may not expose the app's private data during module install. + # Install default preferences once the normal boot namespace can see it. + APPDATA="$(pm dump "$VIPERFXPACKAGE" | grep dataDir | head -n 1 | cut -d'=' -f2)" + attempts=0 + while [ ! -d "$APPDATA" ] && [ "$attempts" -lt 12 ]; do + sleep 5 + attempts=$((attempts + 1)) + done + if [ -d "$APPDATA" ]; then + PREFDIR="$APPDATA/shared_prefs" + PREF="$PREFDIR/${VIPERFXPACKAGE}_preferences.xml" + if [ ! -e "$PREF" ]; then + mkdir -p "$PREFDIR" && cp ./viperfx_preferences.xml "$PREF" && { + chown "$(stat -c '%u:%g' "$APPDATA")" "$PREFDIR" "$PREF" + chmod 700 "$PREFDIR" + chmod 600 "$PREF" + APP_CONTEXT="$(stat -c '%C' "$APPDATA")" + [ -n "$APP_CONTEXT" ] && chcon "$APP_CONTEXT" "$PREFDIR" "$PREF" + } + fi + fi ) & (