2
2
3
3
MODPATH=" ${0%/* } "
4
4
DEBOUNCE_TIME=10
5
+ VOWIFI_CONNECT_TIME=10
5
6
6
7
. $MODPATH /utils.sh # Load utils
7
8
@@ -80,6 +81,35 @@ get_active_iface() {
80
81
echo " $iface "
81
82
}
82
83
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
+ }
83
113
84
114
# Start Run Code
85
115
@@ -106,49 +136,52 @@ echo "4096 65536 16777216" > /proc/sys/net/ipv6/tcp_wmem 2>/dev/null
106
136
107
137
last_mode=" "
108
138
change_time=0
139
+ vowifi_pending=0
140
+ vowifi_start_time=0
109
141
110
142
while true ; do
143
+ current_time=$( date +%s)
111
144
iface=$( get_active_iface)
145
+ [ -z " $iface " ] && sleep 5 && continue
112
146
113
147
new_mode=" none"
114
148
case " $iface " in
115
149
wlan* ) new_mode=" Wi-Fi" ;;
116
- rmnet* ) new_mode=" Cellular" ;;
117
- ccmni* ) new_mode=" Cellular" ;;
150
+ rmnet* |ccmni* ) new_mode=" Cellular" ;;
118
151
* ) new_mode=" none" ;;
119
152
esac
120
153
121
- current_time=$( date +%s)
122
-
123
154
if [ " $new_mode " != " $last_mode " ] || [ -f " $MODPATH /force_apply" ]; then
124
155
if [ " $(( current_time - change_time)) " -ge " $DEBOUNCE_TIME " ]; then
125
156
applied=0
126
157
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 "
136
161
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 "
146
164
fi
147
- last_mode=" $new_mode "
148
- change_time=" $current_time "
165
+ last_mode=" $new_mode "
166
+ change_time=" $current_time "
149
167
rm -f " $MODPATH /force_apply"
150
168
fi
151
169
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
152
185
153
186
sleep 5
154
187
done
0 commit comments