WakeupMgr: Minor usage tweak (#7400)

* Unify logging with AutoSuspend (e.g., keep ourselves to showing the delay in seconds, not the raw timestamp, as that's way harder to interpret, and the RTC module and/or logger will do that for us when the time comes).
* Speaking of, minor revamp of RTC related logging to make it more human-readable.
* On Kobo, if we hit the unexpected wakeup limit, re-engage AutoSuspend's *suspend* check, so that the device has a chance to poweroff instead of being kept awake.
reviewable/pr7404/r1
NiLuJe 3 years ago committed by GitHub
parent 3f0654f530
commit 0b3747927c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 3727ef33c92b8a94dc64873c6305726699207ad8
Subproject commit f6baf7c6d166f2106bce2666d52353415298384c

@ -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

@ -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

@ -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

Loading…
Cancel
Save