|
|
|
@ -108,299 +108,8 @@ function UIManager:init()
|
|
|
|
|
Device:reboot()
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
if Device:isPocketBook() then
|
|
|
|
|
-- Only fg/bg state plugin notifiers, not real power event.
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if Device:isKobo() then
|
|
|
|
|
-- We do not want auto suspend procedure to waste battery during
|
|
|
|
|
-- suspend. So let's unschedule it when suspending, and restart it after
|
|
|
|
|
-- resume. Done via the plugin's onSuspend/onResume handlers.
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:onPowerEvent("Suspend")
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
Device:onPowerEvent("Resume")
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerPress"] = function()
|
|
|
|
|
-- Always schedule power off.
|
|
|
|
|
-- Press the power button for 2+ seconds to shutdown directly from suspend.
|
|
|
|
|
UIManager:scheduleIn(2, self.poweroff_action)
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerRelease"] = function()
|
|
|
|
|
if not self._entered_poweroff_stage then
|
|
|
|
|
UIManager:unschedule(self.poweroff_action)
|
|
|
|
|
-- resume if we were suspended
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:resume()
|
|
|
|
|
else
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- Sleep Cover handling
|
|
|
|
|
if G_reader_settings:isTrue("ignore_power_sleepcover") then
|
|
|
|
|
-- NOTE: The hardware event itself will wake the kernel up if it's in suspend (:/).
|
|
|
|
|
-- Let the unexpected wakeup guard handle that.
|
|
|
|
|
self.event_handlers["SleepCoverClosed"] = nil
|
|
|
|
|
self.event_handlers["SleepCoverOpened"] = nil
|
|
|
|
|
elseif G_reader_settings:isTrue("ignore_open_sleepcover") then
|
|
|
|
|
-- Just ignore wakeup events, and do NOT set is_cover_closed,
|
|
|
|
|
-- so device/generic/device will let us use the power button to wake ;).
|
|
|
|
|
self.event_handlers["SleepCoverClosed"] = function()
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["SleepCoverOpened"] = function()
|
|
|
|
|
Device.is_cover_closed = false
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
self.event_handlers["SleepCoverClosed"] = function()
|
|
|
|
|
Device.is_cover_closed = true
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["SleepCoverOpened"] = function()
|
|
|
|
|
Device.is_cover_closed = false
|
|
|
|
|
self:resume()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Light"] = function()
|
|
|
|
|
Device:getPowerDevice():toggleFrontlight()
|
|
|
|
|
end
|
|
|
|
|
-- USB plug events with a power-only charger
|
|
|
|
|
self.event_handlers["Charging"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
-- NOTE: Plug/unplug events will wake the device up, which is why we put it back to sleep.
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["NotCharging"] = function()
|
|
|
|
|
-- We need to put the device into suspension, other things need to be done before it.
|
|
|
|
|
Device:usbPlugOut()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- USB plug events with a data-aware host
|
|
|
|
|
self.event_handlers["UsbPlugIn"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
-- NOTE: Plug/unplug events will wake the device up, which is why we put it back to sleep.
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
else
|
|
|
|
|
-- Potentially start an USBMS session
|
|
|
|
|
local MassStorage = require("ui/elements/mass_storage")
|
|
|
|
|
MassStorage:start()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["UsbPlugOut"] = function()
|
|
|
|
|
-- We need to put the device into suspension, other things need to be done before it.
|
|
|
|
|
Device:usbPlugOut()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
else
|
|
|
|
|
-- Potentially dismiss the USBMS ConfirmBox
|
|
|
|
|
local MassStorage = require("ui/elements/mass_storage")
|
|
|
|
|
MassStorage:dismiss()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["__default__"] = function(input_event)
|
|
|
|
|
-- Suspension in Kobo can be interrupted by screen updates. We ignore user touch input
|
|
|
|
|
-- in screen_saver_mode so screen updates won't be triggered in suspend mode.
|
|
|
|
|
-- We should not call self:suspend() in screen_saver_mode lest we stay on forever
|
|
|
|
|
-- trying to reschedule suspend. Other systems take care of unintended wake-up.
|
|
|
|
|
if not Device.screen_saver_mode then
|
|
|
|
|
self:sendEvent(input_event)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif Device:isKindle() then
|
|
|
|
|
self.event_handlers["IntoSS"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:intoScreenSaver()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["OutOfSS"] = function()
|
|
|
|
|
Device:outofScreenSaver()
|
|
|
|
|
self:_afterResume();
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Charging"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
Device:usbPlugIn()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["NotCharging"] = function()
|
|
|
|
|
Device:usbPlugOut()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["WakeupFromSuspend"] = function()
|
|
|
|
|
Device:wakeupFromSuspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["ReadyToSuspend"] = function()
|
|
|
|
|
Device:readyToSuspend()
|
|
|
|
|
end
|
|
|
|
|
elseif Device:isRemarkable() then
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:onPowerEvent("Suspend")
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
Device:onPowerEvent("Resume")
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerPress"] = function()
|
|
|
|
|
UIManager:scheduleIn(2, self.poweroff_action)
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerRelease"] = function()
|
|
|
|
|
if not self._entered_poweroff_stage then
|
|
|
|
|
UIManager:unschedule(self.poweroff_action)
|
|
|
|
|
-- resume if we were suspended
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:resume()
|
|
|
|
|
else
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["__default__"] = function(input_event)
|
|
|
|
|
-- Same as in Kobo: we want to ignore keys during suspension
|
|
|
|
|
if not Device.screen_saver_mode then
|
|
|
|
|
self:sendEvent(input_event)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif Device:isSonyPRSTUX() then
|
|
|
|
|
self.event_handlers["PowerPress"] = function()
|
|
|
|
|
UIManager:scheduleIn(2, self.poweroff_action)
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerRelease"] = function()
|
|
|
|
|
if not self._entered_poweroff_stage then
|
|
|
|
|
UIManager:unschedule(self.poweroff_action)
|
|
|
|
|
-- resume if we were suspended
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:resume()
|
|
|
|
|
else
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:intoScreenSaver()
|
|
|
|
|
Device:suspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
Device:resume()
|
|
|
|
|
Device:outofScreenSaver()
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Charging"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["NotCharging"] = function()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["UsbPlugIn"] = function()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
Device:resume()
|
|
|
|
|
Device:outofScreenSaver()
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
Device:usbPlugIn()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["UsbPlugOut"] = function()
|
|
|
|
|
Device:usbPlugOut()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["__default__"] = function(input_event)
|
|
|
|
|
-- Same as in Kobo: we want to ignore keys during suspension
|
|
|
|
|
if not Device.screen_saver_mode then
|
|
|
|
|
self:sendEvent(input_event)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif Device:isCervantes() then
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:onPowerEvent("Suspend")
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
Device:onPowerEvent("Resume")
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerPress"] = function()
|
|
|
|
|
UIManager:scheduleIn(2, self.poweroff_action)
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerRelease"] = function()
|
|
|
|
|
if not self._entered_poweroff_stage then
|
|
|
|
|
UIManager:unschedule(self.poweroff_action)
|
|
|
|
|
-- resume if we were suspended
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:resume()
|
|
|
|
|
else
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Charging"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["NotCharging"] = function()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["UsbPlugIn"] = function()
|
|
|
|
|
self:_beforeCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
else
|
|
|
|
|
-- Potentially start an USBMS session
|
|
|
|
|
local MassStorage = require("ui/elements/mass_storage")
|
|
|
|
|
MassStorage:start()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["UsbPlugOut"] = function()
|
|
|
|
|
self:_afterNotCharging()
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:suspend()
|
|
|
|
|
else
|
|
|
|
|
-- Potentially dismiss the USBMS ConfirmBox
|
|
|
|
|
local MassStorage = require("ui/elements/mass_storage")
|
|
|
|
|
MassStorage:dismiss()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["__default__"] = function(input_event)
|
|
|
|
|
-- Same as in Kobo: we want to ignore keys during suspension
|
|
|
|
|
if not Device.screen_saver_mode then
|
|
|
|
|
self:sendEvent(input_event)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif Device:isSDL() then
|
|
|
|
|
self.event_handlers["Suspend"] = function()
|
|
|
|
|
self:_beforeSuspend()
|
|
|
|
|
Device:simulateSuspend()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["Resume"] = function()
|
|
|
|
|
Device:simulateResume()
|
|
|
|
|
self:_afterResume()
|
|
|
|
|
end
|
|
|
|
|
self.event_handlers["PowerRelease"] = function()
|
|
|
|
|
-- Resume if we were suspended
|
|
|
|
|
if Device.screen_saver_mode then
|
|
|
|
|
self:resume()
|
|
|
|
|
else
|
|
|
|
|
self:suspend()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Device:_setEventHandlers(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
@ -1764,72 +1473,35 @@ function UIManager:runForever()
|
|
|
|
|
return self:run()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- The common operations that should be performed before suspending the device.
|
|
|
|
|
function UIManager:_beforeSuspend()
|
|
|
|
|
self:flushSettings()
|
|
|
|
|
self:broadcastEvent(Event:new("Suspend"))
|
|
|
|
|
|
|
|
|
|
-- Block input events unrelated to power management
|
|
|
|
|
Input:inhibitInput(true)
|
|
|
|
|
|
|
|
|
|
-- Disable key repeat to avoid useless chatter (especially where Sleep Covers are concerned...)
|
|
|
|
|
Device:disableKeyRepeat()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- The common operations that should be performed after resuming the device.
|
|
|
|
|
function UIManager:_afterResume()
|
|
|
|
|
-- Restore key repeat
|
|
|
|
|
Device:restoreKeyRepeat()
|
|
|
|
|
|
|
|
|
|
-- Restore full input handling
|
|
|
|
|
Input:inhibitInput(false)
|
|
|
|
|
|
|
|
|
|
self:broadcastEvent(Event:new("Resume"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- The common operations that should be performed when the device is plugged to a power source.
|
|
|
|
|
function UIManager:_beforeCharging()
|
|
|
|
|
-- Leave the kernel some time to figure it out ;o).
|
|
|
|
|
self:scheduleIn(1, function() Device:setupChargingLED() end)
|
|
|
|
|
self:broadcastEvent(Event:new("Charging"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- The common operations that should be performed when the device is unplugged from a power source.
|
|
|
|
|
function UIManager:_afterNotCharging()
|
|
|
|
|
-- Leave the kernel some time to figure it out ;o).
|
|
|
|
|
self:scheduleIn(1, function() Device:setupChargingLED() end)
|
|
|
|
|
self:broadcastEvent(Event:new("NotCharging"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
|
Executes all the operations of a suspension (i.e., sleep) request.
|
|
|
|
|
|
|
|
|
|
This function usually puts the device into suspension.
|
|
|
|
|
]]
|
|
|
|
|
function UIManager:suspend()
|
|
|
|
|
-- Should always exist, as defined in `generic/device` or overwritten with `setEventHandlers`
|
|
|
|
|
if self.event_handlers["Suspend"] then
|
|
|
|
|
self.event_handlers["Suspend"]()
|
|
|
|
|
elseif Device:isKindle() then
|
|
|
|
|
Device.powerd:toggleSuspend()
|
|
|
|
|
elseif Device:canSuspend() then
|
|
|
|
|
Device:suspend()
|
|
|
|
|
-- Give the other event handlers a chance to be executed.
|
|
|
|
|
-- `Suspend` and `Resume` events will be sent by the handler
|
|
|
|
|
UIManager:nextTick(self.event_handlers["Suspend"])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
|
Executes all the operations of a resume (i.e., wakeup) request.
|
|
|
|
|
function UIManager:reboot()
|
|
|
|
|
-- Should always exist, as defined in `generic/device` or overwritten with `setEventHandlers`
|
|
|
|
|
if self.event_handlers["Reboot"] then
|
|
|
|
|
-- Give the other event handlers a chance to be executed.
|
|
|
|
|
-- 'Reboot' event will be sent by the handler
|
|
|
|
|
UIManager:nextTick(self.event_handlers["Reboot"])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
This function usually wakes up the device.
|
|
|
|
|
]]
|
|
|
|
|
function UIManager:resume()
|
|
|
|
|
-- MONOTONIC doesn't tick during suspend,
|
|
|
|
|
-- invalidate the last battery capacity pull time so that we get up to date data immediately.
|
|
|
|
|
Device:getPowerDevice():invalidateCapacityCache()
|
|
|
|
|
|
|
|
|
|
if self.event_handlers["Resume"] then
|
|
|
|
|
self.event_handlers["Resume"]()
|
|
|
|
|
elseif Device:isKindle() then
|
|
|
|
|
self.event_handlers["OutOfSS"]()
|
|
|
|
|
function UIManager:powerOff()
|
|
|
|
|
-- Should always exist, as defined in `generic/device` or overwritten with `setEventHandlers`
|
|
|
|
|
if self.event_handlers["PowerOff"] then
|
|
|
|
|
-- Give the other event handlers a chance to be executed.
|
|
|
|
|
-- 'PowerOff' event will be sent by the handler
|
|
|
|
|
UIManager:nextTick(self.event_handlers["PowerOff"])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|