22
33MODPATH=" ${0%/* } "
44DEBOUNCE_TIME=10
5+ VOWIFI_CONNECT_TIME=10
56
67. $MODPATH /utils.sh # Load utils
78
@@ -80,6 +81,35 @@ get_active_iface() {
8081 echo " $iface "
8182}
8283
84+ apply_wifi_settings () {
85+ local iface=" $1 "
86+ local applied=0
87+ for algo in $congestion_algorithms ; do
88+ if [ -f " $MODPATH /wlan_$algo " ]; then
89+ set_congestion " $algo " " Wi-Fi"
90+ set_max_initcwnd_initrwnd " $iface "
91+ applied=1
92+ break
93+ fi
94+ done
95+ [ " $applied " -eq 0 ] && set_congestion cubic " Wi-Fi" && set_max_initcwnd_initrwnd " $iface "
96+ return $applied
97+ }
98+
99+ apply_cellular_settings () {
100+ local iface=" $1 "
101+ local applied=0
102+ for algo in $congestion_algorithms ; do
103+ if [ -f " $MODPATH /rmnet_data_$algo " ]; then
104+ set_congestion " $algo " " Cellular"
105+ set_max_initcwnd_initrwnd " $iface "
106+ applied=1
107+ break
108+ fi
109+ done
110+ [ " $applied " -eq 0 ] && set_congestion cubic " Cellular" && set_max_initcwnd_initrwnd " $iface "
111+ return $applied
112+ }
83113
84114# Start Run Code
85115
@@ -106,49 +136,52 @@ echo "4096 65536 16777216" > /proc/sys/net/ipv6/tcp_wmem 2>/dev/null
106136
107137last_mode=" "
108138change_time=0
139+ vowifi_pending=0
140+ vowifi_start_time=0
109141
110142while true ; do
143+ current_time=$( date +%s)
111144 iface=$( get_active_iface)
145+ [ -z " $iface " ] && sleep 5 && continue
112146
113147 new_mode=" none"
114148 case " $iface " in
115149 wlan* ) new_mode=" Wi-Fi" ;;
116- rmnet* ) new_mode=" Cellular" ;;
117- ccmni* ) new_mode=" Cellular" ;;
150+ rmnet* |ccmni* ) new_mode=" Cellular" ;;
118151 * ) new_mode=" none" ;;
119152 esac
120153
121- current_time=$( date +%s)
122-
123154 if [ " $new_mode " != " $last_mode " ] || [ -f " $MODPATH /force_apply" ]; then
124155 if [ " $(( current_time - change_time)) " -ge " $DEBOUNCE_TIME " ]; then
125156 applied=0
126157 if [ " $new_mode " = " Wi-Fi" ]; then
127- for algo in $congestion_algorithms ; do
128- if [ -f " $MODPATH /wlan_$algo " ]; then
129- set_congestion " $algo " " $new_mode "
130- set_max_initcwnd_initrwnd " $iface "
131- applied=1
132- break
133- fi
134- done
135- [ " $applied " -eq 0 ] && set_congestion cubic " $new_mode " && set_max_initcwnd_initrwnd " $iface "
158+ # Start waiting for VoWiFi
159+ vowifi_pending=1
160+ vowifi_start_time=" $current_time "
136161 elif [ " $new_mode " = " Cellular" ]; then
137- for algo in $congestion_algorithms ; do
138- if [ -f " $MODPATH /rmnet_data_$algo " ]; then
139- set_congestion " $algo " " $new_mode "
140- set_max_initcwnd_initrwnd " $iface "
141- applied=1
142- break
143- fi
144- done
145- [ " $applied " -eq 0 ] && set_congestion cubic " $new_mode " && set_max_initcwnd_initrwnd " $iface "
162+ vowifi_pending=0
163+ apply_cellular_settings " $iface "
146164 fi
147- last_mode=" $new_mode "
148- change_time=" $current_time "
165+ last_mode=" $new_mode "
166+ change_time=" $current_time "
149167 rm -f " $MODPATH /force_apply"
150168 fi
151169 fi
170+
171+ # === Wi-Fi Pending Logic ===
172+ if [ " $new_mode " = " Wi-Fi" ] && [ " $vowifi_pending " -eq 1 ]; then
173+ vowifi=$( get_wifi_calling_state)
174+ vowifi=${vowifi:- 1}
175+ if [ " $(( current_time - vowifi_start_time)) " -ge " $VOWIFI_CONNECT_TIME " ]; then
176+ log_print " [INFO] VoWiFi timeout reached. Applying Wi-Fi settings..."
177+ vowifi_pending=0
178+ apply_wifi_settings " $iface "
179+ elif [ " $vowifi " -eq 0 ]; then
180+ log_print " [INFO] VoWiFi activated. Applying Wi-Fi settings..."
181+ vowifi_pending=0
182+ apply_wifi_settings " $iface "
183+ fi
184+ fi
152185
153186 sleep 5
154187done
0 commit comments