|
|
@ -140,18 +140,21 @@ function NetworkListener:_scheduleActivityCheck()
|
|
|
|
|
|
|
|
|
|
|
|
local tx_packets = NetworkListener:_getTxPackets()
|
|
|
|
local tx_packets = NetworkListener:_getTxPackets()
|
|
|
|
if self._last_tx_packets then
|
|
|
|
if self._last_tx_packets then
|
|
|
|
-- Compute noise margin based on the current delay
|
|
|
|
-- Compute noise threshold based on the current delay
|
|
|
|
local delay = self._activity_check_delay or default_network_timeout_seconds
|
|
|
|
local delay = self._activity_check_delay or default_network_timeout_seconds
|
|
|
|
local noise = delay / default_network_timeout_seconds * network_activity_noise_margin
|
|
|
|
local noise_threshold = delay / default_network_timeout_seconds * network_activity_noise_margin
|
|
|
|
|
|
|
|
local delta = tx_packets - self._last_tx_packets
|
|
|
|
-- If there was no meaningful activity (+/- a couple packets), kill the Wi-Fi
|
|
|
|
-- If there was no meaningful activity (+/- a couple packets), kill the Wi-Fi
|
|
|
|
if math.max(0, tx_packets - noise) <= self._last_tx_packets then
|
|
|
|
if delta <= noise_threshold then
|
|
|
|
logger.dbg("NetworkListener: No meaningful network activity ( then:", self._last_tx_packets, "vs. now:", tx_packets, "), disabling Wi-Fi")
|
|
|
|
logger.dbg("NetworkListener: No meaningful network activity (delta:", delta, "<= threshold:", noise_threshold, "[ then:", self._last_tx_packets, "vs. now:", tx_packets, "]) -> disabling Wi-Fi")
|
|
|
|
keep_checking = false
|
|
|
|
keep_checking = false
|
|
|
|
local complete_callback = function()
|
|
|
|
local complete_callback = function()
|
|
|
|
UIManager:broadcastEvent(Event:new("NetworkDisconnected"))
|
|
|
|
UIManager:broadcastEvent(Event:new("NetworkDisconnected"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
NetworkMgr:turnOffWifi(complete_callback)
|
|
|
|
NetworkMgr:turnOffWifi(complete_callback)
|
|
|
|
-- NOTE: We leave wifi_was_on as-is on purpose, we wouldn't want to break auto_restore_wifi workflows on the next start...
|
|
|
|
-- NOTE: We leave wifi_was_on as-is on purpose, we wouldn't want to break auto_restore_wifi workflows on the next start...
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
logger.dbg("NetworkListener: Significant network activity (delta:", delta, "> threshold:", noise_threshold, "[ then:", self._last_tx_packets, "vs. now:", tx_packets, "]) -> keeping Wi-Fi enabled")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|