@@ -11,56 +11,56 @@ congestion_algorithms=$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)
1111
1212# On startup, reset description to default
1313if [ -f " $MODPATH /module.prop" ]; then
14- default_desc=" TCP Optimisations & update tcp_cong_algo based on interface"
15- sed -i ' /^description=/d' " $MODPATH /module.prop" && echo " description=$default_desc " >> " $MODPATH /module.prop"
14+ default_desc=" TCP Optimisations & update tcp_cong_algo based on interface"
15+ sed -i ' /^description=/d' " $MODPATH /module.prop" && echo " description=$default_desc " >> " $MODPATH /module.prop"
1616fi
1717
1818update_description () {
19- local iface=" $1 "
20- local algo=" $2 "
21- local icon=" ⁉️"
19+ local iface=" $1 "
20+ local algo=" $2 "
21+ local icon=" ⁉️"
2222
23- case " $iface " in
24- Wi-Fi) icon=" 🛜" ;;
25- Cellular) icon=" 📶" ;;
26- esac
23+ case " $iface " in
24+ Wi-Fi) icon=" 🛜" ;;
25+ Cellular) icon=" 📶" ;;
26+ esac
2727
28- local desc=" TCP Optimisations & update tcp_cong_algo based on interface | iface: $iface $icon | algo: $algo "
29- sed -i ' /^description=/d' " $MODPATH /module.prop" && echo " description=$desc " >> " $MODPATH /module.prop"
28+ local desc=" TCP Optimisations & update tcp_cong_algo based on interface | iface: $iface $icon | algo: $algo "
29+ sed -i ' /^description=/d' " $MODPATH /module.prop" && echo " description=$desc " >> " $MODPATH /module.prop"
3030}
3131
3232kill_tcp_connections () {
33- if [ -f " $MODPATH /kill_connections" ]; then
34- log_print " Killing all TCP connections (IPv4 and IPv6) due to congestion change"
35-
36- # Kill all connections
37- ss -K
38- fi
33+ if [ -f " $MODPATH /kill_connections" ]; then
34+ log_print " Killing all TCP connections (IPv4 and IPv6) due to congestion change"
35+
36+ # Kill all connections
37+ ss -K
38+ fi
3939}
4040
4141set_max_initcwnd_initrwnd () {
42- local active_iface=" $1 "
43- if [ -f " $MODPATH /initcwnd_initrwnd" ]; then
44- maxBufferSize=$( cat /proc/sys/net/ipv4/tcp_rmem | awk ' {print $3}' )
45- mtu=$( ip link show " $active_iface " | awk ' /mtu/ {print $NF}' )
46- mtu=$(( mtu - 40 ))
47- maxInitrwndValue=$(( maxBufferSize / mtu))
48- local applied
49- applied=0
50-
51- while IFS= read -r line; do
52- run_as_su " /system/bin/ip route change $line initcwnd 10 initrwnd $maxInitrwndValue "
53- if [ $? -eq 0 ]; then
54- applied=1
55- fi
56- done << EOF
42+ local active_iface=" $1 "
43+ if [ -f " $MODPATH /initcwnd_initrwnd" ]; then
44+ maxBufferSize=$( cat /proc/sys/net/ipv4/tcp_rmem | awk ' {print $3}' )
45+ mtu=$( ip link show " $active_iface " | awk ' /mtu/ {print $NF}' )
46+ mtu=$(( mtu - 40 ))
47+ maxInitrwndValue=$(( maxBufferSize / mtu))
48+ local applied
49+ applied=0
50+
51+ while IFS= read -r line; do
52+ run_as_su " /system/bin/ip route change $line initcwnd 10 initrwnd $maxInitrwndValue "
53+ if [ $? -eq 0 ]; then
54+ applied=1
55+ fi
56+ done << EOF
5757$( run_as_su " /system/bin/ip route show | grep \" dev $active_iface \" " )
5858EOF
5959
60- if [ " $applied " -eq 1 ]; then
61- log_print " Setting initcwnd = 10; initrwnd = $maxInitrwndValue !"
62- fi
63- fi
60+ if [ " $applied " -eq 1 ]; then
61+ log_print " Setting initcwnd = 10; initrwnd = $maxInitrwndValue !"
62+ fi
63+ fi
6464}
6565
6666set_qdisc () {
@@ -74,56 +74,56 @@ set_qdisc() {
7474}
7575
7676set_congestion () {
77- local algo=" $1 "
78- local mode=" $2 "
79- if echo " $congestion_algorithms " | grep -qw " $algo " ; then
80- echo " $algo " > /proc/sys/net/ipv4/tcp_congestion_control 2> /dev/null
81- log_print " Applied congestion control: $algo ($mode )"
82- kill_tcp_connections
83- update_description " $mode " " $algo "
84- else
85- log_print " Unavailable algorithm: $algo "
86- fi
77+ local algo=" $1 "
78+ local mode=" $2 "
79+ if echo " $congestion_algorithms " | grep -qw " $algo " ; then
80+ echo " $algo " > /proc/sys/net/ipv4/tcp_congestion_control 2> /dev/null
81+ log_print " Applied congestion control: $algo ($mode )"
82+ kill_tcp_connections
83+ update_description " $mode " " $algo "
84+ else
85+ log_print " Unavailable algorithm: $algo "
86+ fi
8787}
8888
8989get_active_iface () {
90- iface=$( ip route get 192.0.2.1 2> /dev/null | awk ' /dev/ {for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}' )
91- echo " $iface "
90+ iface=$( ip route get 192.0.2.1 2> /dev/null | awk ' /dev/ {for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}' )
91+ echo " $iface "
9292}
9393
9494apply_wifi_settings () {
95- local iface=" $1 "
96- local applied=0
97- for algo in $congestion_algorithms ; do
98- if [ -f " $MODPATH /wlan_$algo " ]; then
99- set_congestion " $algo " " Wi-Fi"
95+ local iface=" $1 "
96+ local applied=0
97+ for algo in $congestion_algorithms ; do
98+ if [ -f " $MODPATH /wlan_$algo " ]; then
99+ set_congestion " $algo " " Wi-Fi"
100100 if [ " $algo " = " bbr" ]; then
101101 set_qdisc " $iface " " fq_codel"
102102 fi
103- set_max_initcwnd_initrwnd " $iface "
104- applied=1
105- break
106- fi
107- done
108- [ " $applied " -eq 0 ] && set_congestion cubic " Wi-Fi" && set_max_initcwnd_initrwnd " $iface "
103+ set_max_initcwnd_initrwnd " $iface "
104+ applied=1
105+ break
106+ fi
107+ done
108+ [ " $applied " -eq 0 ] && set_congestion cubic " Wi-Fi" && set_max_initcwnd_initrwnd " $iface "
109109 return $applied
110110}
111111
112112apply_cellular_settings () {
113- local iface=" $1 "
114- local applied=0
115- for algo in $congestion_algorithms ; do
116- if [ -f " $MODPATH /rmnet_data_$algo " ]; then
117- set_congestion " $algo " " Cellular"
113+ local iface=" $1 "
114+ local applied=0
115+ for algo in $congestion_algorithms ; do
116+ if [ -f " $MODPATH /rmnet_data_$algo " ]; then
117+ set_congestion " $algo " " Cellular"
118118 if [ " $algo " = " bbr" ]; then
119119 set_qdisc " $iface " " fq_codel"
120120 fi
121- set_max_initcwnd_initrwnd " $iface "
122- applied=1
123- break
124- fi
125- done
126- [ " $applied " -eq 0 ] && set_congestion cubic " Cellular" && set_max_initcwnd_initrwnd " $iface "
121+ set_max_initcwnd_initrwnd " $iface "
122+ applied=1
123+ break
124+ fi
125+ done
126+ [ " $applied " -eq 0 ] && set_congestion cubic " Cellular" && set_max_initcwnd_initrwnd " $iface "
127127 return $applied
128128}
129129
@@ -157,47 +157,47 @@ vowifi_start_time=0
157157
158158while true ; do
159159 current_time=$( date +%s)
160- iface=$( get_active_iface)
160+ iface=$( get_active_iface)
161161 [ -z " $iface " ] && sleep 5 && continue
162162
163- new_mode=" none"
164- case " $iface " in
165- wlan* ) new_mode=" Wi-Fi" ;;
166- rmnet* |ccmni* ) new_mode=" Cellular" ;;
167- * ) new_mode=" none" ;;
168- esac
169-
170- if [ " $new_mode " != " $last_mode " ] || [ -f " $MODPATH /force_apply" ]; then
171- if [ " $(( current_time - change_time)) " -ge " $DEBOUNCE_TIME " ]; then
172- applied=0
173- if [ " $new_mode " = " Wi-Fi" ]; then
163+ new_mode=" none"
164+ case " $iface " in
165+ wlan* ) new_mode=" Wi-Fi" ;;
166+ rmnet* |ccmni* ) new_mode=" Cellular" ;;
167+ * ) new_mode=" none" ;;
168+ esac
169+
170+ if [ " $new_mode " != " $last_mode " ] || [ -f " $MODPATH /force_apply" ]; then
171+ if [ " $(( current_time - change_time)) " -ge " $DEBOUNCE_TIME " ]; then
172+ applied=0
173+ if [ " $new_mode " = " Wi-Fi" ]; then
174174 # Start waiting for VoWiFi
175- vowifi_pending=1
176- vowifi_start_time=" $current_time "
177- elif [ " $new_mode " = " Cellular" ]; then
175+ vowifi_pending=1
176+ vowifi_start_time=" $current_time "
177+ elif [ " $new_mode " = " Cellular" ]; then
178178 vowifi_pending=0
179- apply_cellular_settings " $iface "
180- fi
179+ apply_cellular_settings " $iface "
180+ fi
181181 last_mode=" $new_mode "
182182 change_time=" $current_time "
183183 rm -f " $MODPATH /force_apply"
184- fi
185- fi
184+ fi
185+ fi
186186
187187 # === Wi-Fi Pending Logic ===
188- if [ " $new_mode " = " Wi-Fi" ] && [ " $vowifi_pending " -eq 1 ]; then
188+ if [ " $new_mode " = " Wi-Fi" ] && [ " $vowifi_pending " -eq 1 ]; then
189189 vowifi=$( get_wifi_calling_state)
190190 vowifi=${vowifi:- 1}
191- if [ " $(( current_time - vowifi_start_time)) " -ge " $VOWIFI_CONNECT_TIME " ]; then
192- log_print " [INFO] VoWiFi timeout reached. Applying Wi-Fi settings..."
193- vowifi_pending=0
194- apply_wifi_settings " $iface "
195- elif [ " $vowifi " -eq 0 ]; then
196- log_print " [INFO] VoWiFi activated. Applying Wi-Fi settings..."
197- vowifi_pending=0
198- apply_wifi_settings " $iface "
199- fi
200- fi
201-
202- sleep 5
191+ if [ " $(( current_time - vowifi_start_time)) " -ge " $VOWIFI_CONNECT_TIME " ]; then
192+ log_print " [INFO] VoWiFi timeout reached. Applying Wi-Fi settings..."
193+ vowifi_pending=0
194+ apply_wifi_settings " $iface "
195+ elif [ " $vowifi " -eq 0 ]; then
196+ log_print " [INFO] VoWiFi activated. Applying Wi-Fi settings..."
197+ vowifi_pending=0
198+ apply_wifi_settings " $iface "
199+ fi
200+ fi
201+
202+ sleep 5
203203done
0 commit comments