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

Fix PackageKit not emitting network state changed signal when stopped #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antlarr-suse
Copy link

@antlarr-suse antlarr-suse commented Mar 18, 2019

PackageKit can be configured to shutdown automatically after x seconds
of inactivity. If a computer doesn't have a network connection and PackageKit
is shut down (for example because a laptop user takes too long to enter the
wifi password) then PackageKit never emits the properties changed signal
(it can't since it's not running) so PackageKit-Qt never emits the
networkStateChanged signal and applications like the plasma pk update applet
never updates its status.

With this commit, a NetworkManagerMonitor class is added that connects
directly to the NetworkManager's StateChanged dbus signal and emits a
networkStateChanged qt signal, so we can react to a network state change
even when PackageKit is stopped. In this case, we update all properties,
which triggers PK to run and emits the appropiate PK signals as
expected.

PackageKit can be configured to shutdown automatically after x seconds
of inactivity. If a computer doesn't have a network connection and PackageKit
is shut down (for example because a laptop user takes too long to enter the
 wifi password) then PackageKit never emits the properties changed signal
(it can't since it's not running) so PackageKit-Qt never emits the
networkStateChanged signal and applications like the plasma pk update applet
never updates its status.

With this commit, a NetworkManagerMonitor class is added that connects
directly to the NetworkManager's StateChanged signal and emits a
networkStateChanged signal, so we can react to a network state change
even when PackageKit is stopped. In this case, we update all properties,
which triggers PK to run and emits the appropiate PK signals as
expected.
@dantti
Copy link
Collaborator

dantti commented Mar 18, 2019

Hmm I'm not very happy with adding code that talks to another daemon, I'm confused because IIRC PK-QT advises about PK running status.
This also won't won't work if NM is not in use.
Why the update applet needs the network status?

@antlarr-suse
Copy link
Author

Hmm I'm not very happy with adding code that talks to another daemon, I'm confused because IIRC PK-QT advises about PK running status.

I understand your concerns, but the way I see it, PK-Qt has a contract to emit the networkStateChanged signal when the network state changes, and it doesn't do that because of the configuration of PK. If PK was configured not to shutdown, it would emit the signal, so this is a way to encapsulate the internals of PK and always emit the signal when it should.

Also, note that the PR doesn't just forward the signal from NM, but it uses the signal just to reload the PK properties and to emit the corresponding signals without adding complexity to the code.

Btw, just so that you have all the information, this PR is part of the fix for https://bugzilla.opensuse.org/show_bug.cgi?id=1103678, which is basically a polish of the plasma-pk-update applet user experience related to network connectivity changes. Each of the fixes mentioned in that bugzilla issue is independent and fixes separate problems.

This also won't won't work if NM is not in use.

Yes, that's true, but still, IMHO fixing it for NM users is better than nothing and I don't think this can be fixed for non-NM users right now.

Why the update applet needs the network status?

The update applet relies on the networkStateChanged signal for a number of tasks:

  • To know if it can show the user buttons and widgets to check for updates (since checking for updates while the system doesn't have a network will for sure fail and doesn't provide a good experience).

  • To show different messages to the user depending on the network state (like "Your system is offline")

  • To check the "isNetworkMobile" property so different configuration settings can be used when the network is mobile or not. For example, the user can configure to only update the system when on a connection which is not mobile, and so, the applet checks if the network is mobile each time the network state changes.

  • The applet checks for updates automatically when it starts, but if the network is offline at that time (for example, when starting a laptop with wifi connection and the user takes long to enter the password), then the check has to be delayed until the network is online. This delayed check is also triggered by the signal. This is actually still not part of the applet, but I submitted it in https://phabricator.kde.org/D19862 which is currently under review.

kdesysadmin pushed a commit to KDE/plasma-pk-updates that referenced this pull request Mar 21, 2019
…cations.

Summary:
Hide actions that can't be taken if the system doesn't have a network
connection.

Add its own messageChanged NOTIFY signal to the message property

The message property also changes when the network state changes, not only
when isActiveChanged is emitted, so let's create its own signal that is
emitted in both cases.

Delay PkUpdates::checkUpdates calls if the network state is offline

If PkUpdates::checkUpdates is called and the network state is offline,
delay the check for updates until the network is online again.

This fixes the problem that when the user logs in, the applet is run
and just after the PkUpdates object is created, checkUpdates is called
(from main itself). But at that point the user might have not entered
the wifi password so the check would fail. Now, if we detect there's
no network, we just delay the check until the network state is online.

Note that some of these fixes may also need either one or more of the following
fixes depending on your system:

https://gitlab.gnome.org/GNOME/glib/merge_requests/719
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/138
PackageKit/PackageKit-Qt#30

Test Plan:
Reboot a laptop with no network connection. The applet showed
network failure notifications before the commits but not after them.
Also, connect and disconnect and check the applet contents. Before the
commits are applied the applet contained options that make no sense without
network. After the commits are applied it just shows a "Network is offline"
message which makes more sense.

Reviewers: jgrulich

Reviewed By: jgrulich

Differential Revision: https://phabricator.kde.org/D19862
@antlarr-suse
Copy link
Author

ping? JFYI, the related fixes in glib2, NetworkManager and the plasma applet are already merged in their respective repositories, so only this would be left to have nicer behavior of the update notifications in the desktop.

Is there anything I can do to improve the PR?

@aleixpol
Copy link
Collaborator

aleixpol commented Apr 3, 2019

To be honest, I agree that the fix is at the wrong level. PackageKit-Qt is supposed to be an interface to what PackageKit does, and this adds autonomous behaviour modifications.

Such changes could be either implemented in clients if necessary or maybe it would make sense to have some mechanisms to have PackageKit wake up upon network status change, but that's something that could be implemented for PacakgeKit itself as it doesn't have much to do with Qt itself.

NM_DBUS_INTERFACE,
QLatin1String("state"));

QDBusMessage reply = QDBusConnection::systemBus().call(message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a blocking call.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, if you check the commit, NetworkManagerMonitor::state is not really used. I just added it for completeness (and for debug purposes). If it bothers you that someone might change the code in the future and call it, we can remove the method without any problem

void DaemonPrivate::getAllPropertiesIfPackageKitNotRunning()
{
if (!running)
getAllProperties();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If PK is not running I believe getAllProperties() is likely to wake it up again, thus, talking to NM useless if you don't let it stop.

Copy link
Author

Choose a reason for hiding this comment

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

Well, that's the whole point of this PR. We talk to NM because, when PK is not running, it doesn't emit the propertiesChanged signal when the network state changes, so we use NM to have an alternate way to find out we need to update PK properties while PK is not running. Once we got notified the network is up, we call getAllPropertiesIfPackageKitNotRunning, which, as you said, wakes PK so it can give us the updated properties through the usual channels.

Copy link
Author

@antlarr-suse antlarr-suse Apr 4, 2019

Choose a reason for hiding this comment

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

Note that the check for !running is important since that controls that we only do something different than without this PR when PK is stopped. Apart from that, the PR is just signal connections

@dantti
Copy link
Collaborator

dantti commented Apr 3, 2019

Yeah, maybe you could open an issue in PK so that we could discuss there what could be done at PK level.

@antlarr-suse
Copy link
Author

Such changes could be either implemented in clients if necessary

Well, we would have to duplicate those changes in plasma-pk-updates, discover and any other app that use this library. If we can avoid code duplication and just fix it once and for all here, I think it's better.

or maybe it would make sense to have some mechanisms to have PackageKit wake up upon network status change, but that's something that could be implemented for PacakgeKit itself as it doesn't have much to do with Qt itself.

PackageKit is not running, so who would wake it up? With this PR, it's PackageKit-Qt that takes care of transparently do it. Do you have any better suggestion?

@aleixpol
Copy link
Collaborator

aleixpol commented Apr 4, 2019

We could have a script on connectivity-change together in /etc/NetworkManager/dispatcher.d.
https://developer.gnome.org/NetworkManager/stable/NetworkManager.html

This could call pkcon to do whatever is necessary. Does that help?

MingcongBai pushed a commit to AOSC-Tracking/plasma-pk-updates that referenced this pull request Jan 30, 2024
…cations.

Summary:
Hide actions that can't be taken if the system doesn't have a network
connection.

Add its own messageChanged NOTIFY signal to the message property

The message property also changes when the network state changes, not only
when isActiveChanged is emitted, so let's create its own signal that is
emitted in both cases.

Delay PkUpdates::checkUpdates calls if the network state is offline

If PkUpdates::checkUpdates is called and the network state is offline,
delay the check for updates until the network is online again.

This fixes the problem that when the user logs in, the applet is run
and just after the PkUpdates object is created, checkUpdates is called
(from main itself). But at that point the user might have not entered
the wifi password so the check would fail. Now, if we detect there's
no network, we just delay the check until the network state is online.

Note that some of these fixes may also need either one or more of the following
fixes depending on your system:

https://gitlab.gnome.org/GNOME/glib/merge_requests/719
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/138
PackageKit/PackageKit-Qt#30

Test Plan:
Reboot a laptop with no network connection. The applet showed
network failure notifications before the commits but not after them.
Also, connect and disconnect and check the applet contents. Before the
commits are applied the applet contained options that make no sense without
network. After the commits are applied it just shows a "Network is offline"
message which makes more sense.

Reviewers: jgrulich

Reviewed By: jgrulich

Differential Revision: https://phabricator.kde.org/D19862
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.

None yet

3 participants