Skip to content

Various Wi-Fi QoL improvements#6424

Merged
NiLuJe merged 110 commits into
koreader:masterfrom
NiLuJe:wifi-powersave
Jul 27, 2020
Merged

Various Wi-Fi QoL improvements#6424
NiLuJe merged 110 commits into
koreader:masterfrom
NiLuJe:wifi-powersave

Conversation

@NiLuJe

@NiLuJe NiLuJe commented Jul 24, 2020

Copy link
Copy Markdown
Member
  • Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
  • Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
  • Consistently use "Wi-Fi" everywhere.
  • On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained network inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
    (i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
  • Made sending NetworkConnected / NetworkDisconnected events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
  • restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
  • We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
  • Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
  • Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
  • Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments below for details). Fix UI freezes frequently, seemingly correlated with network usage #6421
    Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
  • For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.

Original message:

Possibly a bit heuristic-y, but seems to do the job well enough on my H2O.

Limited to hasWifiManager devices (i.e., Kobo/Cervantes/Sony).

Could possibly work on a few other pure-Linux devices with a sane turnOffWifi? (Kindle? [EDIT: Nope, see below])
(This would require implementing NetworkMgr:getNetworkInterfaceName() there, too).


This change is Reviewable

NiLuJe added 22 commits July 24, 2020 01:48
(NetworkListener is instantiated by the FM & Reader apps).
(This is absolutely not based on the AutoSuspend plugin, no siree :D).
30s was a weee bit short ;p.
i.e., it could conceivably be tripped while reading a Wikipedia blurb,
a point during which you'd probably expect to not have to suddenly
re-enable WiFi ;).
different sessions

(Meaning the first check will be bogus and will quite likely kill WiFi
instantly).
_unschedule already handles this check
@NiLuJe NiLuJe requested review from Frenzie, pazos and poire-z as code owners July 24, 2020 02:28
NiLuJe added 3 commits July 24, 2020 04:40
Prevents spamming the logs with bogus attempts if wifi_was_on is true,
but WiFi is no longer enabled.
@NiLuJe

NiLuJe commented Jul 24, 2020

Copy link
Copy Markdown
Member Author

The noise margin is still low enough to make an idle SSH session (w/ KeepAlive) enough to keep Wi-Fi up ;).

@NiLuJe NiLuJe requested a review from poire-z July 26, 2020 03:20

@poire-z poire-z left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not really familiar with all that, but looks alright.

self:beforeWifiAction(callback)
return true
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nitpick, but unnecessary blank line - here and above)

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.

That one was on purpose, to separate the actual core logic from the menu/UI shenanigans that come later.

The one in networkListener was done with the same kind of thing in mind, but doesn't really make sense because there are event handlers above AND below it ;p.

@Frenzie Frenzie added this to the 2020.08 milestone Jul 26, 2020

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

(untested) lgtm. If something crashes on Cervantes we can fix it later.

BTW, Does make sense to invest time to simulate the same auto down when idle behaviour on the (linux) emulator?

It shouldn't be too hard to fake it like we fake wifi state. Given that /sys/class/iface/ can be changed to something like /tmp/. Anyways, nothing to do with this PR.

Very good job 👍

(Generally, to separate logical units of code).
@NiLuJe

NiLuJe commented Jul 26, 2020

Copy link
Copy Markdown
Member Author

@pazos: I don't expect much trouble on Cervantes, FWIW. Might want to resync the Wi-Fi scripts at one point, but that's it ;).


I will run a test on Kindle later today, though :).

@NiLuJe

NiLuJe commented Jul 26, 2020

Copy link
Copy Markdown
Member Author

BTW, Does make sense to invest time to simulate the same auto down when idle behaviour on the (linux) emulator?

Do we even handle Wi-Fi at all on the emulator? (i.e., a NetworkManager backend or something?).

NiLuJe added 2 commits July 26, 2020 19:06
It more-or-less behaves like the prompt action on Kobo, but with way
less UI feedback (i.e., we essentially hang with no feedback until the
connection is successful, at which point the action fires).
wifi-async kill to only run it on devices that have one.
@NiLuJe

NiLuJe commented Jul 26, 2020

Copy link
Copy Markdown
Member Author

Okay, made it not regress and mostly usable on Kindle, I'll leave UI fine-tuning to others if necessary ;).

At a quick glance, on PB, I'm hoping the InkView stuff is blocking, so we should be okay.

On reMarkable, err, do we even support controlling the Wi-Fi at all?

And on Android, the callbacks are never forwarded, so it shouldn't regress.

@Frenzie

Frenzie commented Jul 26, 2020

Copy link
Copy Markdown
Member

Do we even handle Wi-Fi at all on the emulator? (i.e., a NetworkManager backend or something?).

Haha no, nor should we.

(Unless it's necessary for some platform I suppose, in which case we might as well I guess.)

@pazos

pazos commented Jul 26, 2020

Copy link
Copy Markdown
Member

Nope, no Wi-Fi handled on the emulator, but there's a fake networkManager instance in https://github.com/koreader/koreader/blob/master/frontend/device/sdl/device.lua#L313-L334, which is useful to test things that rely on network state changes.

On reMarkable, err, do we even support controlling the Wi-Fi at all?

Nope, reMarkable has Wi-Fi but we don't manage it. It should be pretty similar to Nickel: if we kill the blob running then WiFi will stay alive until the battery is empty.

@NiLuJe NiLuJe merged commit 37a0110 into koreader:master Jul 27, 2020

@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 like I forgot to press submit on the review thing (but I hadn't finished reading the diff yet)


function NetworkMgr:getPowersaveMenuTable()
return {
text = _("Kill Wi-Fi connection when inactive"),

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.

Kill sounds a bit aggressive perhaps ^_^

Suggested change
text = _("Kill Wi-Fi connection when inactive"),
text = _("Automatically disable Wi-Fi connection"),
Suggested change
text = _("Kill Wi-Fi connection when inactive"),
text = _("Disable Wi-Fi connection when inactive"),

@NiLuJe NiLuJe Jul 27, 2020

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.

I'll admit that was somewhat colored by rfkill buttons, where the term is already used to make it exceedingly clear that the modem is actually turned off ;).

(It's also short, which was a plus ;p).

NiLuJe added a commit that referenced this pull request Jul 28, 2020
* Minor cosmetic code cleanup
* String tweak
NiLuJe added a commit that referenced this pull request Jul 29, 2020
* Simplify logic, and more detailed debug logging
* Kill Nickel's FIFO on startup
Avoids udev/udhcpc scripts hanging when trying to open() it.
@NiLuJe NiLuJe mentioned this pull request Jul 30, 2020
@Galunid Galunid mentioned this pull request Aug 9, 2020
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](koreader#6424 (comment)) for details). Fix koreader#6421 
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
* Minor cosmetic code cleanup
* String tweak
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
* Simplify logic, and more detailed debug logging
* Kill Nickel's FIFO on startup
Avoids udev/udhcpc scripts hanging when trying to open() 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.

UI freezes frequently, seemingly correlated with network usage

4 participants