|
1 | 1 | #!/system/bin/sh
|
2 | 2 |
|
3 |
| -# MODDIR=${0%/*} will be nherited from the parent sh module |
4 |
| - |
5 |
| -# This script functions will be used in services mode |
6 |
| - |
7 |
| -. "$MODDIR/jitter-reducer-functions.shlib" |
8 |
| - |
9 |
| -function disableAdaptiveFeatures() |
10 |
| -{ |
11 |
| - # Reducing jitter by battery draining and charging manager, and 5G data manager |
12 |
| - settings put global adaptive_battery_management_enabled 0 |
13 |
| - settings put secure adaptive_charging_enabled 0 |
14 |
| - settings put secure adaptive_connectivity_enabled 0 |
15 |
| - # Reducing wifi jitter by suspend wifi optimizations |
16 |
| - settings put global wifi_suspend_optimizations_enabled 0 |
17 |
| -} |
18 |
| - |
19 |
| -function setVolumeMediaSteps() |
| 3 | +function reloadAudioServer() |
20 | 4 | {
|
21 |
| - # Volume medial steps to be 100 if a volume steps facility is used |
22 |
| - settings put system volume_steps_music 100 |
23 |
| -} |
24 |
| - |
25 |
| -function forceIgnoreAudioEffects() |
26 |
| -{ |
27 |
| - local force_restart_server=0 |
28 |
| - |
29 |
| - if [ "`getprop persist.sys.phh.disable_audio_effects`" = "0" ]; then |
30 |
| - # Workaround for recent Pixel Firmwares (not to reboot when resetprop'ing) |
31 |
| - resetprop --delete ro.audio.ignore_effects 1>"/dev/null" 2>&1 |
32 |
| - # End of workaround |
33 |
| - resetprop ro.audio.ignore_effects true |
34 |
| - force_restart_server=1 |
35 |
| - fi |
36 |
| - |
37 |
| - # Stop Tensor device's AOC daemon for reducing significant jitter |
38 |
| - if [ "`getprop init.svc.aocd`" = "running" ]; then |
39 |
| - setprop ctl.stop aocd |
40 |
| - force_restart_server=1 |
41 |
| - fi |
42 |
| - |
43 |
| - # Nullifying the volume listener for no compressing audio (maybe a peak limiter) |
44 |
| - if [ "`getprop persist.sys.phh.disable_soundvolume_effect`" = "0" ]; then |
45 |
| - if [ -r "/system/phh/empty" -a -r "/vendor/lib/soundfx/libvolumelistener.so" ]; then |
46 |
| - mount -o bind "/system/phh/empty" "/vendor/lib/soundfx/libvolumelistener.so" |
47 |
| - force_restart_server=1 |
48 |
| - fi |
49 |
| - if [ -r "/system/phh/empty" -a -r "/vendor/lib64/soundfx/libvolumelistener.so" ]; then |
50 |
| - mount -o bind "/system/phh/empty" "/vendor/lib64/soundfx/libvolumelistener.so" |
51 |
| - force_restart_server=1 |
52 |
| - fi |
53 |
| - |
54 |
| - elif [ "`getprop persist.sys.phh.disable_soundvolume_effect`" != "1" ]; then |
55 |
| - # for non- phh GSI's (Qcomm devices only?) |
56 |
| - if [ -r "/vendor/lib/soundfx/libvolumelistener.so" ]; then |
57 |
| - mount -o bind "/dev/null" "/vendor/lib/soundfx/libvolumelistener.so" |
58 |
| - force_restart_server=1 |
| 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 |
59 | 14 | fi
|
60 |
| - if [ -r "/vendor/lib64/soundfx/libvolumelistener.so" ]; then |
61 |
| - mount -o bind "/dev/null" "/vendor/lib64/soundfx/libvolumelistener.so" |
62 |
| - force_restart_server=1 |
63 |
| - fi |
64 |
| - |
65 |
| - fi |
66 |
| - |
67 |
| - if [ "$force_restart_server" = "1" -o "`getprop ro.system.build.version.release`" -ge "12" ]; then |
68 |
| - reloadAudioServer |
69 | 15 | fi
|
70 | 16 | }
|
71 | 17 |
|
72 |
| -# This function has six arguments: |
73 |
| -# 1. Enable $1:thermal core control, $2:Camera service (interfering in jitters on audio outputs), $3:Selinux enforcing, $4:Doze (battery optimizations) |
74 |
| -# and $5:Logd service or not, respectively ("yes" or "no") |
75 |
| -# 2. Disable $6:clearest tone ("yes" or "no"), perhaps for sensitive Bluetooth earphones. |
76 |
| - |
77 |
| -function optimizeOS() |
78 |
| -{ |
79 |
| - if [ $# -neq 6 ]; then |
80 |
| - exit 1 |
81 |
| - fi |
82 |
| - |
| 18 | +# Sleep some secs needed for Audioserver's preparation |
| 19 | +function waitAudioServer() |
| 20 | +{ |
83 | 21 | # wait for system boot completion and audiosever boot up
|
| 22 | + sleep 11 |
84 | 23 | local i
|
85 |
| - for i in `seq 1 30` ; do |
| 24 | + for i in `seq 1 10` ; do |
86 | 25 | if [ "`getprop sys.boot_completed`" = "1" -a -n "`getprop init.svc.audioserver`" ]; then
|
87 | 26 | break
|
88 | 27 | fi
|
89 |
| - sleep 0.9 |
| 28 | + sleep $i |
90 | 29 | done
|
91 |
| - |
92 |
| - if [ "$1" = "no" ]; then |
93 |
| - reduceThermalJitter 1 0 |
94 |
| - fi |
95 |
| - if [ "$2" = "no" ]; then |
96 |
| - reduceCameraJitter 1 0 |
97 |
| - fi |
98 |
| - if [ "$3" = "no" ]; then |
99 |
| - reduceSelinuxJitter 1 0 |
100 |
| - fi |
101 |
| - if [ "$4" = "no" ]; then |
102 |
| - reduceDozeJitter 1 0 |
103 |
| - fi |
104 |
| - if [ "$5" = "no" ]; then |
105 |
| - reduceLogdJitter 1 0 |
106 |
| - fi |
107 |
| - reduceGovernorJitter 1 0 |
108 |
| - if [ "$6" = "no" ]; then |
109 |
| - reduceIoJitter 1 '*' 'boost' 0 |
110 |
| - else |
111 |
| - reduceIoJitter 1 '*' 'medium' 0 |
112 |
| - fi |
113 |
| - reduceVmJitter 1 0 |
114 |
| - forceIgnoreAudioEffects |
115 |
| - disableAdaptiveFeatures |
116 |
| - setVolumeMediaSteps |
117 | 30 | }
|
118 | 31 |
|
119 |
| -# Get the active audio policy configuration fille from the audioserever |
120 |
| - |
121 |
| -function getActivePolicyFile() |
| 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() |
122 | 35 | {
|
123 |
| - dumpsys media.audio_policy | awk ' |
124 |
| - /^ Config source: / { |
125 |
| - print $3 |
126 |
| - }' |
127 |
| -} |
128 |
| - |
129 |
| -function remountFile() |
130 |
| -{ |
131 |
| - local configXML |
| 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 |
132 | 43 |
|
133 |
| - # Set the active configuration file name retrieved from the audio policy server |
134 |
| - configXML="`getActivePolicyFile`" |
| 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//\"`" |
135 | 48 |
|
136 |
| - # Check if the audio policy XML file mounted by Magisk is still unmounted. |
| 49 | + # Check if the audio policy XML file and others mounted by Magisk is still unmounted. |
137 | 50 | # Some Qcomm devices from Xiaomi, OnePlus, etc. overlays another on it in a boot process
|
138 |
| - # and phh GSI on Qcomm devices unmount it |
139 |
| - |
140 |
| - if [ -r "$configXML" -a -r "${MODDIR}/system${configXML}" ]; then |
141 |
| - cmp "$configXML" "${MODDIR}/system${configXML}" >"/dev/null" 2>&1 |
142 |
| - if [ "$?" -ne 0 ]; then |
143 |
| - umount "$configXML" >"/dev/null" 2>&1 |
144 |
| - umount "$configXML" >"/dev/null" 2>&1 |
145 |
| - mount -o bind "${MODDIR}/system${configXML}" "$configXML" |
146 |
| - reloadAudioServer |
| 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 |
147 | 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 |
148 | 73 | fi
|
149 | 74 | }
|
0 commit comments