|
| 1 | +#!/system/bin/sh |
| 2 | + |
| 3 | +function reloadAudioServer() |
| 4 | +{ |
| 5 | + if [ -n "`getprop init.svc.audioserver`" ]; then |
| 6 | + setprop ctl.restart audioserver |
| 7 | + sleep 1.2 |
| 8 | + if [ "`getprop init.svc.audioserver`" != "running" ]; then |
| 9 | + # workaround for Android 12 old devices hanging up the audioserver after "setprop ctl.restart audioserver" is executed |
| 10 | + local pid="`getprop init.svc_debug_pid.audioserver`" |
| 11 | + if [ -n "$pid" ]; then |
| 12 | + kill -HUP $pid 1>"/dev/null" 2>&1 |
| 13 | + fi |
| 14 | + fi |
| 15 | + fi |
| 16 | +} |
| 17 | + |
| 18 | +# Sleep some secs needed for Audioserver's preparation |
| 19 | +function waitAudioServer() |
| 20 | +{ |
| 21 | + # wait for system boot completion and audiosever boot up |
| 22 | + sleep 11 |
| 23 | + local i |
| 24 | + for i in `seq 1 10` ; do |
| 25 | + if [ "`getprop sys.boot_completed`" = "1" -a -n "`getprop init.svc.audioserver`" ]; then |
| 26 | + break |
| 27 | + fi |
| 28 | + sleep $i |
| 29 | + done |
| 30 | +} |
| 31 | + |
| 32 | +# A rewritten version because some ROM's fail to execute "dumpsys media.audio_policy" on the service phase |
| 33 | +# arg1 : Magisk's module folder path, typically "/data/adb/modules/<module name>" |
| 34 | +function remountFiles() |
| 35 | +{ |
| 36 | + local modPath flist x deletePat forceReload=0 |
| 37 | + |
| 38 | + if [ $# -eq 1 -a -e "$1" ]; then |
| 39 | + modPath="$1" |
| 40 | + else |
| 41 | + return |
| 42 | + fi |
| 43 | + |
| 44 | + deletePat=$(echo "${modPath}/system" | sed -e 's/\//\\\//g') |
| 45 | + |
| 46 | + # Get absolute paths for Magisk's magic mount, then remount by itself |
| 47 | + flist="`find \"${modPath}/system\" -type f | sed -e \"s/$deletePat//\"`" |
| 48 | + |
| 49 | + # Check if the audio policy XML file and others mounted by Magisk is still unmounted. |
| 50 | + # Some Qcomm devices from Xiaomi, OnePlus, etc. overlays another on it in a boot process |
| 51 | + # and phh GSI's on Qcomm devices unmount it for the phh settings of the GSI's. |
| 52 | + |
| 53 | + for x in $flist; do |
| 54 | + if [ -e "${modPath}/skip_mount" -a "${x##*/}" = ".replace" ]; then |
| 55 | + # Mount a directory instead of ".replace" file if skipping Magisk's magic mount |
| 56 | + mount -o bind "${modPath}/system${x%/.replace}" "${x%/.replace}" |
| 57 | + forceReload=1 |
| 58 | + elif [ -r "$x" -a -r "${modPath}/system${x}" ]; then |
| 59 | + cmp "$x" "${modPath}/system${x}" >"/dev/null" 2>&1 |
| 60 | + if [ "$?" -ne 0 ]; then |
| 61 | + umount "$x" >"/dev/null" 2>&1 |
| 62 | + umount "$x" >"/dev/null" 2>&1 |
| 63 | + mount -o bind "${modPath}/system${x}" "$x" |
| 64 | + forceReload=1 |
| 65 | + fi |
| 66 | + fi |
| 67 | + done |
| 68 | + |
| 69 | + if [ "$forceReload" -gt 0 ]; then |
| 70 | + # Since this library file may be shared multiple modules, it is needed to disperse the timing of each module not to collide |
| 71 | + sleep $(expr $RANDOM % 20) |
| 72 | + reloadAudioServer |
| 73 | + fi |
| 74 | +} |
0 commit comments