diff --git a/base b/base index 3727ef33c..f6baf7c6d 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 3727ef33c92b8a94dc64873c6305726699207ad8 +Subproject commit f6baf7c6d166f2106bce2666d52353415298384c diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 1877fcb56..d683fef00 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -540,6 +540,7 @@ local function check_unexpected_wakeup() -- just in case other events like SleepCoverClosed also scheduled a suspend UIManager:unschedule(Kobo.suspend) + -- Do an initial validation to discriminate unscheduled wakeups happening *outside* of the alarm proximity window. if WakeupMgr:isWakeupAlarmScheduled() and WakeupMgr:validateWakeupAlarmByProximity() then logger.info("Kobo suspend: scheduled wakeup.") local res = WakeupMgr:wakeupAction() @@ -557,6 +558,9 @@ local function check_unexpected_wakeup() -- Don't put device back to sleep under the following two cases: -- 1. a resume event triggered Kobo:resume() function -- 2. trying to put device back to sleep more than 20 times after unexpected wakeup + -- Broadcast a specific event, so that AutoSuspend can pick up the baton... + local Event = require("ui/event") + UIManager:broadcastEvent(Event:new("UnexpectedWakeupLimit")) return end diff --git a/frontend/device/wakeupmgr.lua b/frontend/device/wakeupmgr.lua index 6a76e3978..fcf15e381 100644 --- a/frontend/device/wakeupmgr.lua +++ b/frontend/device/wakeupmgr.lua @@ -55,7 +55,7 @@ function WakeupMgr:addTask(seconds_from_now, callback) if not type(seconds_from_now) == "number" and not type(callback) == "function" then return end local epoch = RTC:secondsFromNowToEpoch(seconds_from_now) - logger.info("WakeupMgr: scheduling wakeup for:", seconds_from_now, epoch) + logger.info("WakeupMgr: scheduling wakeup in", seconds_from_now) local old_upcoming_task = (self._task_queue[1] or {}).epoch @@ -181,7 +181,13 @@ Simple wrapper for @{ffi.rtc.isWakeupAlarmScheduled}. --]] function WakeupMgr:isWakeupAlarmScheduled() local wakeup_scheduled = RTC:isWakeupAlarmScheduled() - logger.dbg("isWakeupAlarmScheduled", wakeup_scheduled) + if wakeup_scheduled then + -- NOTE: This can't return nil given that we're behind an isWakeupAlarmScheduled check. + local alarm = RTC:getWakeupAlarmEpoch() + logger.dbg("WakeupMgr:isWakeupAlarmScheduled: An alarm is scheduled for " .. alarm .. os.date(" (%F %T %z)", alarm)) + else + logger.dbg("WakeupMgr:isWakeupAlarmScheduled: No alarm is currently scheduled.") + end return wakeup_scheduled end diff --git a/plugins/autosuspend.koplugin/main.lua b/plugins/autosuspend.koplugin/main.lua index 9905f546c..b68397979 100644 --- a/plugins/autosuspend.koplugin/main.lua +++ b/plugins/autosuspend.koplugin/main.lua @@ -36,8 +36,8 @@ function AutoSuspend:_enabledShutdown() return Device:canPowerOff() and self.autoshutdown_timeout_seconds > 0 end -function AutoSuspend:_schedule() - if not self:_enabled() then +function AutoSuspend:_schedule(shutdown_only) + if not self:_enabled() and (Device:canPowerOff() and not self:_enabledShutdown()) then logger.dbg("AutoSuspend:_schedule is disabled") return end @@ -57,17 +57,17 @@ function AutoSuspend:_schedule() if delay_shutdown <= 0 then logger.dbg("AutoSuspend: initiating shutdown") UIManager:poweroff_action() - elseif delay_suspend <= 0 then + elseif delay_suspend <= 0 and not shutdown_only then logger.dbg("AutoSuspend: will suspend the device") UIManager:suspend() else - if self:_enabled() then - logger.dbg("AutoSuspend: schedule suspend in", delay_suspend) - UIManager:scheduleIn(delay_suspend, self._schedule, self) + if self:_enabled() and not shutdown_only then + logger.dbg("AutoSuspend: scheduling next suspend check in", delay_suspend) + UIManager:scheduleIn(delay_suspend, self._schedule, self, shutdown_only) end if self:_enabledShutdown() then - logger.dbg("AutoSuspend: schedule shutdown in", delay_shutdown) - UIManager:scheduleIn(delay_shutdown, self._schedule, self) + logger.dbg("AutoSuspend: scheduling next shutdown check in", delay_shutdown) + UIManager:scheduleIn(delay_shutdown, self._schedule, self, shutdown_only) end end end @@ -86,6 +86,16 @@ function AutoSuspend:_start() end end +-- Variant that only re-engages the shutdown timer for onUnexpectedWakeupLimit +function AutoSuspend:_restart() + if self:_enabledShutdown() then + local now_ts = os.time() + logger.dbg("AutoSuspend: restart at", now_ts) + self.last_action_sec = now_ts + self:_schedule(true) + end +end + function AutoSuspend:init() if Device:isPocketBook() and not Device:canSuspend() then return end UIManager.event_hook:registerWidget("InputEvent", self) @@ -116,9 +126,17 @@ function AutoSuspend:onResume() if self:_enabledShutdown() and Device.wakeup_mgr then Device.wakeup_mgr:removeTask(nil, nil, UIManager.poweroff_action) end + -- Unschedule in case we tripped onUnexpectedWakeupLimit first... + self:_unschedule() self:_start() end +function AutoSuspend:onUnexpectedWakeupLimit() + logger.dbg("AutoSuspend: onUnexpectedWakeupLimit") + -- Only re-engage the *shutdown* schedule to avoid doing the same dance indefinitely. + self:_restart() +end + function AutoSuspend:onAllowStandby() self.standby_prevented = false end