Skip to content

Commit 2597aa2

Browse files
committed
Apply Wi-Fi Settings only after Vo-WiFi is connected or timeout
1 parent 1e2d4f9 commit 2597aa2

File tree

2 files changed

+64
-32
lines changed

2 files changed

+64
-32
lines changed

module/service.sh

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
MODPATH="${0%/*}"
44
DEBOUNCE_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

107137
last_mode=""
108138
change_time=0
139+
vowifi_pending=0
140+
vowifi_start_time=0
109141

110142
while 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
154187
done

module/utils.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ run_as_su() {
3333
}
3434

3535
get_wifi_calling_state() {
36-
dumpsys activity service SystemUIService > "$DUMPSYS_TMP_FILE" 2>/dev/null
37-
grep -qE "slot='vowifi'.*visibleState=ICON.*visible" "$DUMPSYS_TMP_FILE"
38-
rm -f "$DUMPSYS_TMP_FILE"
39-
if [ $? -eq 0 ]; then
40-
return 0
41-
else
42-
return 1
43-
fi
36+
rm -f "$DUMPSYS_TMP_FILE"
37+
dumpsys activity service SystemUIService > "$DUMPSYS_TMP_FILE" 2>/dev/null
38+
grep -qEm 1 "slot='vowifi'.*visibleState=ICON.*" "$DUMPSYS_TMP_FILE"
39+
local status=$?
40+
rm -f "$DUMPSYS_TMP_FILE"
41+
# echo's result: 0 = true (VoWiFi active), 1 = false
42+
echo $status
4443
}

0 commit comments

Comments
 (0)