From 8d133507ad696e58e5e763999bbafcacef367b92 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 30 Dec 2022 23:48:23 +0100 Subject: [PATCH] Device: Handle screen_saver_lock + WiFi corner-cases If Wi-Fi is restored on resume, going back to suspend while the screensaver is shown via the screen_saver_lock flag would have attempted to suspend *without* killing Wi-Fi first. This implodes on the vast majority of NTX boards, so take the usual precautions. --- frontend/device/generic/device.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 009ff00ae..42bfe980a 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -284,6 +284,15 @@ function Device:onPowerEvent(ev) -- suspending the hardware. This usually happens when sleep cover -- is closed after the device was sent to suspend state. logger.dbg("Already in screen saver mode, going back to suspend...") + -- Much like the real suspend codepath below, in case we got here via screen_saver_lock, + -- make sure we murder WiFi again (because restore WiFi on resume could have kicked in). + if self:hasWifiToggle() then + local network_manager = require("ui/network/manager") + if network_manager:isWifiOn() then + network_manager:releaseIP() + network_manager:turnOffWifi() + end + end self:rescheduleSuspend() end -- else we were not in screensaver mode @@ -305,6 +314,8 @@ function Device:onPowerEvent(ev) if self:needsScreenRefreshAfterResume() then self.screen:refreshFull() end + -- NOTE: In the same vein as above, this is delayed to make sure we update the screen first. + -- (This, unfortunately, means we can't just move this to Device:_beforeSuspend :/). UIManager:scheduleIn(0.1, function() -- NOTE: This side of the check needs to be laxer, some platforms can handle Wi-Fi without WifiManager ;). if self:hasWifiToggle() then