mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
NetworkManager: Always prefer system APs as intended.
If we had a local prefered AP with a higher RSSI, we attempted to associate with it over wpa_supplicant being already attempting to associate with its own preferred AP. That... failed horribly. Also adapt to the new lj-wpaclient API, fixing a few other edge-cases, and making the whole thing slightly faster because we no longer uselessly sleep. And more reliable because we now actually wait for replies to our requests. Bump base https://github.com/koreader/koreader-base/pull/1424
This commit is contained in:
@@ -599,6 +599,7 @@ function NetworkMgr:reconnectOrShowNetworkMenu(complete_callback)
|
||||
-- rescan if the first scan appeared to yield an empty list.
|
||||
--- @fixme This *might* be an issue better handled in lj-wpaclient...
|
||||
if #network_list == 0 then
|
||||
logger.warn("Initial Wi-Fi scan yielded no results, rescanning")
|
||||
network_list, err = self:getNetworkList()
|
||||
if network_list == nil then
|
||||
UIManager:show(InfoMessage:new{text = err})
|
||||
@@ -613,27 +614,53 @@ function NetworkMgr:reconnectOrShowNetworkMenu(complete_callback)
|
||||
if self.wifi_toggle_long_press then
|
||||
self.wifi_toggle_long_press = nil
|
||||
else
|
||||
local ssid
|
||||
-- We need to do two passes, as we may have *both* an already connected network (from the global wpa config),
|
||||
-- *and* preferred networks, and if the prferred networks have a better signal quality,
|
||||
-- they'll be sorted *earlier*, which would cause us to try to associate to a different AP than
|
||||
-- what wpa_supplicant is already trying to do...
|
||||
for dummy, network in ipairs(network_list) do
|
||||
if network.connected then
|
||||
-- On platforms where we use wpa_supplicant (if we're calling this, we are),
|
||||
-- the invocation will check its global config, and if an AP configured there is reachable,
|
||||
-- it'll already have connected to it on its own.
|
||||
success = true
|
||||
elseif network.password then
|
||||
success = NetworkMgr:authenticateNetwork(network)
|
||||
end
|
||||
if success then
|
||||
NetworkMgr:obtainIP()
|
||||
if complete_callback then
|
||||
complete_callback()
|
||||
end
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Connected to network %1"), BD.wrap(network.ssid)),
|
||||
timeout = 3,
|
||||
})
|
||||
ssid = network.ssid
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Next, look for our own prferred networks...
|
||||
local err_msg = _("Connection failed")
|
||||
if not success then
|
||||
for dummy, network in ipairs(network_list) do
|
||||
if network.password then
|
||||
-- If we hit a preferred network and we're not already connected,
|
||||
-- attempt to connect to said preferred network....
|
||||
success, err_msg = NetworkMgr:authenticateNetwork(network)
|
||||
if success then
|
||||
ssid = network.ssid
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
NetworkMgr:obtainIP()
|
||||
if complete_callback then
|
||||
complete_callback()
|
||||
end
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Connected to network %1"), BD.wrap(ssid)),
|
||||
timeout = 3,
|
||||
})
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = err_msg,
|
||||
timeout = 3,
|
||||
})
|
||||
end
|
||||
end
|
||||
if not success then
|
||||
-- NOTE: Also supports a disconnect_callback, should we use it for something?
|
||||
|
||||
Reference in New Issue
Block a user