Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkManager: Enable "before wifi action" support on every hasWifiToggle platform #10669

Merged
merged 39 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9498638
Okay, that looks like a feasible gameplan....
NiLuJe Jul 9, 2023
198ed2b
The Emu is already flagges hasWifiToggle
NiLuJe Jul 9, 2023
a0cced7
Start updating the KOSync capchecks
NiLuJe Jul 9, 2023
9518e2f
Decouple restoreWifiAsync from hasWifiManager
NiLuJe Jul 9, 2023
2293354
Implement restoreWifiAsync on Kindle
NiLuJe Jul 9, 2023
2d88d05
Add a crappy flag to potentially avoid running multiple connectvity
NiLuJe Jul 10, 2023
b509acd
Forgot that one
NiLuJe Jul 10, 2023
222f6c3
Slightly more accurate check there
NiLuJe Jul 10, 2023
74a8d5a
Why, yes, rM is actually a first-class wireless citizen ;p
NiLuJe Jul 10, 2023
d9d5d2d
Don't delay the first connectvity check for no reason
NiLuJe Jul 10, 2023
a591b22
Simplify NetworkMgr init
NiLuJe Jul 10, 2023
f378cf9
Eh, nextTick *should* be just fine for the initial, startup
NiLuJe Jul 10, 2023
a9ca0c2
Actively check the connectivity after a menu toggle on !ntx platforms
NiLuJe Jul 10, 2023
f915d1d
Add a tiny bit of debugging context to the async resume
NiLuJe Jul 10, 2023
362ddbf
Ditto on NetworkMgr's side
NiLuJe Jul 10, 2023
b2b54d6
Log the time spent in goOnlineToRun, like the real connectivity check
NiLuJe Jul 10, 2023
506876c
Tweak the connectvity check's help message on Kindle
NiLuJe Jul 10, 2023
811ac91
Unbreak the test, maybe.
NiLuJe Jul 10, 2023
89b98d7
Trust Network(Dis)Connected events to update NetworkMgr's internal
NiLuJe Jul 10, 2023
de66939
Actually kill WiFi on suspend on platforms not using Generic's
NiLuJe Jul 10, 2023
244280b
Now with a proper NetworkDisconnected event
NiLuJe Jul 10, 2023
4aa01df
I'm butchering stuff up, let's table this for tonight.
NiLuJe Jul 10, 2023
7f09967
Hmmm...
NiLuJe Jul 10, 2023
bae28e0
Unify network even signaling by using wrappers around turnOn/turnOff
NiLuJe Jul 10, 2023
53b9b37
On !hasWifiToggle platforms, assume connectivity is *always* available
NiLuJe Jul 10, 2023
8a9d594
Make it clearer that the NetworkListener activity check is class-wide
NiLuJe Jul 10, 2023
9a6403c
COmment tweak
NiLuJe Jul 10, 2023
94e74c3
Err, that made no sense?
NiLuJe Jul 10, 2023
d249a76
No need for an extra query there, both the connectivity check and the
NiLuJe Jul 10, 2023
a1e3c7f
Stop the connectivity check at 45s, not 45.25 ;).
NiLuJe Jul 10, 2023
730c7ab
Stash that behind a hasWifiToggle capcheck, like its onPowerEvent
NiLuJe Jul 11, 2023
04402ad
Review pass
NiLuJe Jul 11, 2023
e2f08ed
Dedupe those handlers
NiLuJe Jul 11, 2023
e228ed5
Clarify that comment
NiLuJe Jul 11, 2023
1659bc0
Stray river
NiLuJe Jul 11, 2023
b25c8f9
Comment tweak
NiLuJe Jul 11, 2023
9a68311
Harmless typo
NiLuJe Jul 11, 2023
5ba0f9e
Post-rebase fixup
NiLuJe Jul 11, 2023
f1df419
Skip the wifi teardown on suspend on Android
NiLuJe Jul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/device/cervantes/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local Cervantes = Generic:extend{
hasFastWifiStatusQuery = yes,
hasKeys = yes,
hasWifiManager = yes,
hasWifiRestore = yes,
canReboot = yes,
canPowerOff = yes,
canSuspend = yes,
Expand Down
14 changes: 3 additions & 11 deletions frontend/device/generic/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ local Device = {
hasFewKeys = no,
hasWifiToggle = yes,
hasWifiManager = no,
hasWifiRestore = no,
isDefaultFullscreen = yes,
isHapticFeedbackEnabled = no,
isDeprecated = no, -- device no longer receive OTA updates
Expand Down Expand Up @@ -278,13 +279,6 @@ function Device:onPowerEvent(ev)
else
logger.dbg("Resuming...")
UIManager:unschedule(self.suspend)
if self:hasWifiManager() then
local network_manager = require("ui/network/manager")
if network_manager.wifi_was_on and G_reader_settings:isTrue("auto_restore_wifi") then
network_manager:restoreWifiAsync()
network_manager:scheduleConnectivityCheck()
end
end
self:resume()
local widget_was_closed = Screensaver:close()
if widget_was_closed and self:needsScreenRefreshAfterResume() then
Expand Down Expand Up @@ -313,8 +307,7 @@ function Device:onPowerEvent(ev)
if self:hasWifiToggle() then
local network_manager = require("ui/network/manager")
if network_manager:isWifiOn() then
UIManager:broadcastEvent(Event:new("NetworkDisconnecting"))
network_manager:turnOffWifi()
network_manager:disableWifi()
end
end
self:rescheduleSuspend()
Expand Down Expand Up @@ -347,8 +340,7 @@ function Device:onPowerEvent(ev)
-- because suspend will at best fail, and at worst deadlock the system if Wi-Fi is on,
-- regardless of who enabled it!
if network_manager:isWifiOn() then
UIManager:broadcastEvent(Event:new("NetworkDisconnecting"))
network_manager:turnOffWifi()
network_manager:disableWifi()
end
end
-- Only turn off the frontlight *after* we've displayed the screensaver and dealt with Wi-Fi,
Expand Down
5 changes: 5 additions & 0 deletions frontend/device/kindle/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ local Kindle = Generic:extend{
isSpecialOffers = isSpecialOffers(),
hasOTAUpdates = yes,
hasFastWifiStatusQuery = yes,
hasWifiRestore = yes,
-- NOTE: HW inversion is generally safe on mxcfb Kindles
canHWInvert = yes,
-- NOTE: And the fb driver is generally sane on those, too
Expand Down Expand Up @@ -186,6 +187,10 @@ function Kindle:initNetworkManager(NetworkMgr)
return "wlan0" -- so far, all Kindles appear to use wlan0
end

function NetworkMgr:restoreWifiAsync()
kindleEnableWifi(1)
end

NetworkMgr.isWifiOn = NetworkMgr.sysfsWifiOn
NetworkMgr.isConnected = NetworkMgr.ifHasAnAddress
end
Expand Down
1 change: 1 addition & 0 deletions frontend/device/kobo/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ local Kobo = Generic:extend{
hasOTAUpdates = yes,
hasFastWifiStatusQuery = yes,
hasWifiManager = yes,
hasWifiRestore = yes,
canStandby = no, -- will get updated by checkStandby()
canReboot = yes,
canPowerOff = yes,
Expand Down
2 changes: 2 additions & 0 deletions frontend/device/remarkable/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ local Remarkable = Generic:extend{
hasKeys = yes,
needsScreenRefreshAfterResume = no,
hasOTAUpdates = yes,
hasFastWifiStatusQuery = yes,
hasWifiManager = yes,
canReboot = yes,
canPowerOff = yes,
canSuspend = yes,
Expand Down
4 changes: 0 additions & 4 deletions frontend/device/sony-prstux/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ function SonyPRSTUX:initNetworkManager(NetworkMgr)
os.execute("dhclient -x wlan0")
end

function NetworkMgr:restoreWifiAsync()
-- os.execute("./restore-wifi-async.sh")
end

--[[
function NetworkMgr:isWifiOn()
return 0 == os.execute("wmiconfig -i wlan0 --wlan query | grep -q enabled")
Expand Down
64 changes: 32 additions & 32 deletions frontend/ui/data/onetime_migration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local logger = require("logger")
local _ = require("gettext")

-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20230707
local CURRENT_MIGRATION_DATE = 20230710

-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
Expand Down Expand Up @@ -517,9 +517,36 @@ if last_migration_date < 20230531 then
end
end

-- 20230627, Migrate to a full settings table, and disable KOSync's auto sync mode if wifi_enable_action is not turn_on
if last_migration_date < 20230627 then
logger.info("Performing one-time migration for 20230627")
-- 20230703, FileChooser Sort by: "date modified" only
if last_migration_date < 20230703 then
logger.info("Performing one-time migration for 20230703")
local collate = G_reader_settings:readSetting("collate")
if collate == "modification" or collate == "access" or collate == "change" then
G_reader_settings:saveSetting("collate", "date")
end
end

-- 20230707, OPDS, no more special calibre catalog
if last_migration_date < 20230707 then
logger.info("Performing one-time migration for 20230707")

local calibre_opds = G_reader_settings:readSetting("calibre_opds")
if calibre_opds and calibre_opds.host and calibre_opds.port then
local opds_servers = G_reader_settings:readSetting("opds_servers") or {}
table.insert(opds_servers, 1, {
title = _("Local calibre library"),
url = string.format("http://%s:%d/opds", calibre_opds.host, calibre_opds.port),
username = calibre_opds.username,
password = calibre_opds.password,
})
G_reader_settings:saveSetting("opds_servers", opds_servers)
G_reader_settings:delSetting("calibre_opds")
end
end

-- 20230710, Migrate to a full settings table, and disable KOSync's auto sync mode if wifi_enable_action is not turn_on
if last_migration_date < 20230710 then
logger.info("Performing one-time migration for 20230710")

-- c.f., PluginLoader
local package_path = package.path
Expand Down Expand Up @@ -549,7 +576,7 @@ if last_migration_date < 20230627 then
end

local Device = require("device")
if Device:hasWifiManager() and G_reader_settings:readSetting("wifi_enable_action") ~= "turn_on" then
if Device:hasWifiToggle() and G_reader_settings:readSetting("wifi_enable_action") ~= "turn_on" then
local kosync = G_reader_settings:readSetting("kosync")
if kosync and kosync.auto_sync then
kosync.auto_sync = false
Expand All @@ -558,32 +585,5 @@ if last_migration_date < 20230627 then
end
end

-- 20230703, FileChooser Sort by: "date modified" only
if last_migration_date < 20230703 then
logger.info("Performing one-time migration for 20230703")
local collate = G_reader_settings:readSetting("collate")
if collate == "modification" or collate == "access" or collate == "change" then
G_reader_settings:saveSetting("collate", "date")
end
end

-- 20230707, OPDS, no more special calibre catalog
if last_migration_date < 20230707 then
logger.info("Performing one-time migration for 20230707")

local calibre_opds = G_reader_settings:readSetting("calibre_opds")
if calibre_opds and calibre_opds.host and calibre_opds.port then
local opds_servers = G_reader_settings:readSetting("opds_servers") or {}
table.insert(opds_servers, 1, {
title = _("Local calibre library"),
url = string.format("http://%s:%d/opds", calibre_opds.host, calibre_opds.port),
username = calibre_opds.username,
password = calibre_opds.password,
})
G_reader_settings:saveSetting("opds_servers", opds_servers)
G_reader_settings:delSetting("calibre_opds")
end
end

-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
Loading