@@ -11,56 +11,56 @@ congestion_algorithms=$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)
11
11
12
12
# On startup, reset description to default
13
13
if [ -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"
16
16
fi
17
17
18
18
update_description () {
19
- local iface=" $1 "
20
- local algo=" $2 "
21
- local icon=" ⁉️"
19
+ local iface=" $1 "
20
+ local algo=" $2 "
21
+ local icon=" ⁉️"
22
22
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
27
27
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"
30
30
}
31
31
32
32
kill_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
39
39
}
40
40
41
41
set_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
57
57
$( run_as_su " /system/bin/ip route show | grep \" dev $active_iface \" " )
58
58
EOF
59
59
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
64
64
}
65
65
66
66
set_qdisc () {
@@ -74,56 +74,56 @@ set_qdisc() {
74
74
}
75
75
76
76
set_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
87
87
}
88
88
89
89
get_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 "
92
92
}
93
93
94
94
apply_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"
100
100
if [ " $algo " = " bbr" ]; then
101
101
set_qdisc " $iface " " fq_codel"
102
102
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 "
109
109
return $applied
110
110
}
111
111
112
112
apply_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"
118
118
if [ " $algo " = " bbr" ]; then
119
119
set_qdisc " $iface " " fq_codel"
120
120
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 "
127
127
return $applied
128
128
}
129
129
@@ -157,47 +157,47 @@ vowifi_start_time=0
157
157
158
158
while true ; do
159
159
current_time=$( date +%s)
160
- iface=$( get_active_iface)
160
+ iface=$( get_active_iface)
161
161
[ -z " $iface " ] && sleep 5 && continue
162
162
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
174
174
# 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
178
178
vowifi_pending=0
179
- apply_cellular_settings " $iface "
180
- fi
179
+ apply_cellular_settings " $iface "
180
+ fi
181
181
last_mode=" $new_mode "
182
182
change_time=" $current_time "
183
183
rm -f " $MODPATH /force_apply"
184
- fi
185
- fi
184
+ fi
185
+ fi
186
186
187
187
# === 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
189
189
vowifi=$( get_wifi_calling_state)
190
190
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
203
203
done
0 commit comments