Skip to content

PM: Minor refactor to suspend/resume code flow#10426

Merged
NiLuJe merged 53 commits into
koreader:masterfrom
NiLuJe:pm_shenanigans
May 18, 2023
Merged

PM: Minor refactor to suspend/resume code flow#10426
NiLuJe merged 53 commits into
koreader:masterfrom
NiLuJe:pm_shenanigans

Conversation

@NiLuJe

@NiLuJe NiLuJe commented May 12, 2023

Copy link
Copy Markdown
Member

Make sure we only send Suspend/Resume events when we actually suspend/resume. This is done via the Device _beforeSuspend/_afterResume methods, and those were called by the input handlers, not the PM logic; which means they would fire, while the PM logic could actually take a smarter decision and not do what the event just sent implied ;).

(i.e., sleep with a cover -> suspend + actual suspend, OK; but if you then resume with a button -> input assumes resume, but PM will actually suspend again!).

Existing design issue made more apparent by #9448 ;).

Also fixes/generalizes a few corner-cases related to screen_saver_lock handling (e.g., don't allow USBMS during a lock).

And deal with the fallout of the main change to the Kobo frontlight ramp behavior ;).


This change is Reviewable

@NiLuJe

NiLuJe commented May 12, 2023

Copy link
Copy Markdown
Member Author

Draft because lightly tested and heavily sleep deprived ;p.

(I was supposed to test Android stuff tonight, not lose my mind >_<").

EDIT: Oh, and leftover debugging to be removed, too.

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7 of 17 files at r1, 13 of 15 files at r2, 2 of 2 files at r3, 11 of 11 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @NiLuJe)

NiLuJe added 27 commits May 14, 2023 16:44
API

With the goal of deduplicating the slight madness involved here, and,
most importantly, not calling them when we don't actually suspend or
resume...
Makes more sense, ensures it deals with sleepcover events, too (lathough
good luck tripping that ;p), and should dedupe a bunch of code.
And make sure we don't fire duplicate events
(Might be tricky in practice, given that we're following system events,
IIRC, and they should already be guarded properly).
And move things around so it's close to setEventHandlers
NiLuJe added 5 commits May 14, 2023 17:14
It effectively delays it until after the full refresh, and that's... a
lot.

Will have to see how the previous approach behaves on other, non awful
devices.

(Testing on an H2O right now)
Thankfully, newer, SMP devices can power through the resource
contention.

(i.e., on a Sage, it will smoothly ramp *during* the refresh.
This is robably for a mix of reasons:  because it's SMP, more powerful,
and also because the display driver doesn't really give us
great vsync fences, so we unblock earlier after the flashing refresh).

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @NiLuJe)

@NiLuJe NiLuJe marked this pull request as ready for review May 16, 2023 18:33
@NiLuJe NiLuJe requested review from Frenzie, pazos and poire-z as code owners May 16, 2023 18:33
@NiLuJe

NiLuJe commented May 16, 2023

Copy link
Copy Markdown
Member Author

Oohkay, me and my trusty fridge magnet haven't managed to break this on a few other devices, so this should be ready.

A bit more churn than I would have initially hoped, but the gist of it is to move the emission of Suspend/Resume Events from the input handlers to the actual PM logic, so as not to send spurious events when the logic does something more complex than what the input could entail (this usually involves sleepcover interactions ;)).

@NiLuJe NiLuJe added this to the 2023.05 milestone May 18, 2023

@Frenzie Frenzie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay, but it's quite large so the impact's a bit hard to gauge. If you think it's ready.

@NiLuJe

NiLuJe commented May 18, 2023

Copy link
Copy Markdown
Member Author

It shouldn't be any worse, yeah ;o).

(Famous last words ^^).

@NiLuJe NiLuJe merged commit 7e98b9d into koreader:master May 18, 2023
Frenzie pushed a commit that referenced this pull request Jun 9, 2023
Fixes a regression introduced in #10426, when suspending during night and resuming during daylight.
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Nov 25, 2023
* afterResume had *two* different implementations, so the historical one
  that handled frontlight fixups no longer ran
  (regression since koreader#10426)
* isFrontlightOn was completely broken, for a couple of reasons:
  * There was no is isFrontlightOnHW implementation, so when it ran, it
    mostly always thought the frontlight was on, because
    self.fl_intensity doesn't change on toggle off.
  * _decideFrontlightState was never called on Kindle,
    so isFrontlightOnHW was never really called, making isFrontlightOn
    completely useless. Call it in setIntensityHW's coda, as it ought to
    be. And properly document that.

Generic *was* calling _decideFrontlightState is setIntensity, but
*before* actually setting the frontlight, which makes no goddamn sense,
so get rid of that, too.

* Also fix frontlight toggle notifications (regression since koreader#10305)

TL;DR: The PowerD API being a mess strikes again.
Frenzie pushed a commit that referenced this pull request Nov 25, 2023
* afterResume had *two* different implementations, so the historical one
  that handled frontlight fixups no longer ran
  (regression since #10426)
* isFrontlightOn was completely broken, for a couple of reasons:
  * There was no is isFrontlightOnHW implementation, so when it ran, it
    mostly always thought the frontlight was on, because
    self.fl_intensity doesn't change on toggle off.
  * _decideFrontlightState was never called on Kindle,
    so isFrontlightOnHW was never really called, making isFrontlightOn
    completely useless. Call it in setIntensityHW's coda, as it ought to
    be. And properly document that.

Generic *was* calling _decideFrontlightState is setIntensity, but
*before* actually setting the frontlight, which makes no goddamn sense,
so get rid of that, too.

* Also fix frontlight toggle notifications (regression since #10305)

TL;DR: The PowerD API being a mess strikes again.
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Nov 27, 2023
If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of koreader#10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Nov 27, 2023
If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of koreader#10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Nov 27, 2023
If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of koreader#10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Nov 27, 2023
If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of koreader#10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
NiLuJe added a commit that referenced this pull request Nov 28, 2023
Fix #11164 and involves a drive-by fix:

Kindle: Send Suspend/Resume event regardless of the screen saver state

If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of #10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Make sure we only send Suspend/Resume events when we *actually* suspend/resume. This is done via the Device `_beforeSuspend`/`_afterResume` methods, and those were called by the *input handlers*, not the PM logic; which means they would fire, while the PM logic could actually take a smarter decision and *not* do what the event just sent implied ;).

(i.e., sleep with a cover -> suspend + actual suspend, OK; but if you then resume with a button -> input assumes resume, but PM will actually suspend again!).

Existing design issue made more apparent by koreader#9448 ;).

Also fixes/generalizes a few corner-cases related to screen_saver_lock handling (e.g., don't allow USBMS during a lock).

And deal with the fallout of the main change to the Kobo frontlight ramp behavior ;).
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Fixes a regression introduced in koreader#10426, when suspending during night and resuming during daylight.
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
* afterResume had *two* different implementations, so the historical one
  that handled frontlight fixups no longer ran
  (regression since koreader#10426)
* isFrontlightOn was completely broken, for a couple of reasons:
  * There was no is isFrontlightOnHW implementation, so when it ran, it
    mostly always thought the frontlight was on, because
    self.fl_intensity doesn't change on toggle off.
  * _decideFrontlightState was never called on Kindle,
    so isFrontlightOnHW was never really called, making isFrontlightOn
    completely useless. Call it in setIntensityHW's coda, as it ought to
    be. And properly document that.

Generic *was* calling _decideFrontlightState is setIntensity, but
*before* actually setting the frontlight, which makes no goddamn sense,
so get rid of that, too.

* Also fix frontlight toggle notifications (regression since koreader#10305)

TL;DR: The PowerD API being a mess strikes again.
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Fix koreader#11164 and involves a drive-by fix:

Kindle: Send Suspend/Resume event regardless of the screen saver state

If we get the events, it means stuff happened, we can't just only honor
it in the most common workflows ;).

This effectively reverts a tiny bit of koreader#10426 (I was sort of expecting
this to be problematic at the time, and I most likely hadn't tested it).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants