Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkManager: Enable "before wifi action" support on every hasWifiToggle platform #10669

Merged
merged 39 commits into from
Jul 12, 2023

Conversation

NiLuJe
Copy link
Member

@NiLuJe NiLuJe commented Jul 10, 2023

It used to be limited to hasWifiManager platforms for some reason (spoiler: that reason was probably I couldn't be arsed to test it on Kindle, and/or it would have been clunky and messy before @yparitcher's cleanup of the network status checks).

Anyway, it's fairly trivial to do now, and, as #10605 showed, we kinda need it, as I was stuck in lala-land assuming everybody had it already, and KOSync is a broken mess without it ^^. (Plus, it really has no technical ties to any kind of NetworkMgr backend).

This involves some minor NetworkMgr refactors, and a few fixes along the way.

(Fix #10678)

To recap:

  • Enable before_wifi_action & after_wifi_action on hasWifiToggle platforms (which is basically all of 'em except naked SDL).
  • Decouple restoreWifiAsync from hasWifiManger, because we can do that on other platforms (namely, Kindle. Probably PB, too, but WiFi is already a mess there, and I can't test it).
  • Implement restoreWifiAsync on Kindle.
  • Properly flag rM as hasWifiManager & hasFastWifiStatusQuery, because it is actually both of those (it uses our wpa_supplicant backend).
  • Update the KOSync checks to take these changes into account, to properly disable auto_sync if necessary.
  • Really made the Network* event signaling consistent. For realz this time.
  • In an effort to make the whole beforeWifiAction framework somewhat usable there, we now assume connectivity is always available on !hasWifiToggle platforms...

This change is Reviewable

@NiLuJe NiLuJe requested review from Frenzie, pazos and poire-z as code owners July 10, 2023 01:26
@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 10, 2023

Lightly tested (on a 5.9.7 PW2), so if you have time to spare, feel free to give it a spin, @hius07 ;).

@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 10, 2023

As expected, the network activity check is hilarious on Kindle, because tmd is losing its damn mind in the background xD.

07/10/23-03:19:43 DEBUG NetworkListener: Significant network activity (delta: 19364 > threshold: 12 [ then: 1615 vs. now: 20979 ]) -> keeping Wi-Fi enabled

Ya don't say ;o).

@@ -624,7 +634,8 @@ end
function NetworkMgr:getPowersaveMenuTable()
return {
text = _("Disable Wi-Fi connection when inactive"),
help_text = _([[This will automatically turn Wi-Fi off after a generous period of network inactivity, without disrupting workflows that require a network connection, so you can just keep reading without worrying about battery drain.]]),
help_text = Device:isKindle() and _([[This is unlikely to function properly on a stock Kindle, given how chatty the framework is.]]) or
Copy link
Member

Choose a reason for hiding this comment

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

It works just fine for those of us that run frameworkless :)

Copy link
Member Author

@NiLuJe NiLuJe Jul 10, 2023

Choose a reason for hiding this comment

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

Not over here (the numbers above were from a frameworkless session) ;o).

It's an old device that has almost never been online, which probably plays a part here, but even after letting it sit connected in the framework for a bit, which calmed tmd down somewhat, I still get deltas of ~360 (EDIT: ~250 today)..

Copy link
Member

Choose a reason for hiding this comment

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

I have iptables rules that only allows outgoing connections on the local lan (i dont need any helpful connections by amazon) so that is why it works for me

Copy link
Member

Choose a reason for hiding this comment

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

Fyi in case you have any other suggestions. https://hosted.weblate.org/translate/koreader/koreader/en/?checksum=4f0eae549f1bd665#comments

The English can probably be improved but "talkative, communicative..." is indeed correct. :-) It means the Kindle framework is constantly communicating with Amazon servers or something along those lines.

In Dutch I provisionally translated it as "sends/broadcasts much information," which would likely be clearer in English too.

image

Copy link
Member Author

@NiLuJe NiLuJe Jul 14, 2023

Choose a reason for hiding this comment

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

Yeah, it's probably a bit jargony. I can't quite think of something else as succinct, though; so the alternative would be to explain it, i.e., that the native system already triggers a lot of network activity on its own.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's probably clearer. "given how much network activity the framework generates" or something.

@NiLuJe NiLuJe marked this pull request as draft July 10, 2023 02:47
@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 10, 2023

(Draft, got some more stuff to test/fix tomorrow).

Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 10 files at r1, 1 of 2 files at r2, 1 of 3 files at r4, 2 of 2 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Frenzie, @pazos, @poire-z, and @yparitcher)

Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Frenzie, @pazos, @poire-z, and @yparitcher)

@NiLuJe NiLuJe marked this pull request as ready for review July 11, 2023 02:09
@NiLuJe
Copy link
Member Author

NiLuJe commented Jul 11, 2023

Okay, re-tested on a PW2 & a H2O, this ought to be ready now ;).

Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Dismissed @yparitcher from a discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Frenzie, @pazos, and @poire-z)

NiLuJe added 8 commits July 11, 2023 16:14
I'm... not sure there was ever anything else, but I only have a vague
recollection of writing this, and I've already fixed dumb things about it
in this PR, so, who knows xD.
That was less painful than I expected (p4merge ftw!)
@NiLuJe NiLuJe force-pushed the universal_before_wifi_action branch from d9e6687 to 5ba0f9e Compare July 11, 2023 14:17
Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Frenzie, @pazos, and @poire-z)

The toggles are interactive there, so, that's not great...

We'll see how NetworkMgr's connectivity check fares there,
it might need to be nerfed on Android, too...
Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Frenzie, @pazos, and @poire-z)

@NiLuJe NiLuJe merged commit d57325a into koreader:master Jul 12, 2023
@Frenzie Frenzie added this to the 2023.07 milestone Jul 12, 2023
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jul 15, 2023
NiLuJe added a commit that referenced this pull request Jul 15, 2023
Frenzie pushed a commit that referenced this pull request Jun 25, 2024
* Kindle: Implement a NetworkMgr backend loosely based on WpaClient in order to allow feature-parity with hasWifiManager platforms. This involves dealing with the native wifid over lipc (the native IPC system, based on DBus), through custom Lua bindings (https://github.com/notmarek/openlipclua), since the stock ones lack support for the needed hasharray data type.
* NetworkMgr: Clear up leftover hallucinations from #10669, making `enableWifi` much simpler (and much more similar to `turnOnWifiAndWaitForConnection`).
* NetworkMgr: Made it clearer that `turnOnWifi` implementations *must* deal with `complete_callback`, as part of the aforementioned changes mean that it's *always* wrapped in a connectivity check, and we need that for proper event signaling.
* Android, Emu: Run `complete_callback` properly in `turnOnWifi`.
* Kindle: Support `powerd:isCharged()` on the PW2 (yes, this is random, it just happened to be my test device :D).
* NetworkMgr:disableWifi: Properly tear down any potential ongoing connection attempt (e.g., connectivity check).
* NetworkMgr:promptWifi: Make the "wifi enabled but not connected" popup clearer if there's an ongoing connection attempt, and gray out the "Connect" button in this case (as it would only lead to another "connection already in progress" popup anyway).
* NetworkMgr:reconnectOrShowNetworkMenu: Make *total* scanning failures fatal (they will lead to an immediate wifi teardown).
* NetworkMgr:reconnectOrShowNetworkMenu: Clear up the long-press behavior (which *always* shows the network list popup) so that it doesn't weirdly break all the things (technical term!).
* NetworkMgr:reconnectOrShowNetworkMenu: When we manage to connect to a preferred network on our own *before* showing the network list, make sure it is flagged as "connected" in said list.
* NetworkMgr:reconnectOrShowNetworkMenu: Make connection failures fatal in non-interactive workflows (they'll lead to a wifi teardown).
* NetworkSetting (the aforementioned network list widget): Clear NetworkMgr's "connection pending" flag on dismiss when nothing else will (i.e., when there's no connectivity check ticking).
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jul 24, 2024
so as not to break the beforeWifiction shenanigans...

Which is most of them, only the Emulator subclass sets it, for...
reasons.

(That Emulator quirk is also why we can't simply scrap the whole thing
to use NetworkMgr's default imps).

Fix koreader#12203 (thanks to @benoit-pierre for spotting that one).

This was clearly an oversight on my part when working on koreader#10669
NiLuJe added a commit that referenced this pull request Jul 26, 2024
…s, (#12217)

so as not to break the beforeWifiction shenanigans...

Which is most of them, only the Emulator subclass sets it, for...
reasons.

(That Emulator quirk is also why we can't simply scrap the whole thing
to use NetworkMgr's default imps).

Fix #12203 (thanks to @benoit-pierre for spotting that one).

This was clearly an oversight on my part when working on #10669
Commodore64user pushed a commit to Commodore64user/KOReader_fork that referenced this pull request Aug 2, 2024
* Kindle: Implement a NetworkMgr backend loosely based on WpaClient in order to allow feature-parity with hasWifiManager platforms. This involves dealing with the native wifid over lipc (the native IPC system, based on DBus), through custom Lua bindings (https://github.com/notmarek/openlipclua), since the stock ones lack support for the needed hasharray data type.
* NetworkMgr: Clear up leftover hallucinations from koreader#10669, making `enableWifi` much simpler (and much more similar to `turnOnWifiAndWaitForConnection`).
* NetworkMgr: Made it clearer that `turnOnWifi` implementations *must* deal with `complete_callback`, as part of the aforementioned changes mean that it's *always* wrapped in a connectivity check, and we need that for proper event signaling.
* Android, Emu: Run `complete_callback` properly in `turnOnWifi`.
* Kindle: Support `powerd:isCharged()` on the PW2 (yes, this is random, it just happened to be my test device :D).
* NetworkMgr:disableWifi: Properly tear down any potential ongoing connection attempt (e.g., connectivity check).
* NetworkMgr:promptWifi: Make the "wifi enabled but not connected" popup clearer if there's an ongoing connection attempt, and gray out the "Connect" button in this case (as it would only lead to another "connection already in progress" popup anyway).
* NetworkMgr:reconnectOrShowNetworkMenu: Make *total* scanning failures fatal (they will lead to an immediate wifi teardown).
* NetworkMgr:reconnectOrShowNetworkMenu: Clear up the long-press behavior (which *always* shows the network list popup) so that it doesn't weirdly break all the things (technical term!).
* NetworkMgr:reconnectOrShowNetworkMenu: When we manage to connect to a preferred network on our own *before* showing the network list, make sure it is flagged as "connected" in said list.
* NetworkMgr:reconnectOrShowNetworkMenu: Make connection failures fatal in non-interactive workflows (they'll lead to a wifi teardown).
* NetworkSetting (the aforementioned network list widget): Clear NetworkMgr's "connection pending" flag on dismiss when nothing else will (i.e., when there's no connectivity check ticking).
Commodore64user pushed a commit to Commodore64user/KOReader_fork that referenced this pull request Aug 2, 2024
…s, (koreader#12217)

so as not to break the beforeWifiction shenanigans...

Which is most of them, only the Emulator subclass sets it, for...
reasons.

(That Emulator quirk is also why we can't simply scrap the whole thing
to use NetworkMgr's default imps).

Fix koreader#12203 (thanks to @benoit-pierre for spotting that one).

This was clearly an oversight on my part when working on koreader#10669
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.

"Error connecting to the network" when opening the file browser - KOSync trying to sync with Wi-Fi disabled?
3 participants