Bug 492859 - As of power-profiles-daemon-0.22, Power and Battery Applet doesn't detect power profiles until powerdevil is restarted
Summary: As of power-profiles-daemon-0.22, Power and Battery Applet doesn't detect pow...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Battery Monitor (show other bugs)
Version: 6.2.2
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
: 492945 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-09-09 04:54 UTC by vis
Modified: 2024-11-05 16:38 UTC (History)
10 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.2.3
Sentry Crash Report:


Attachments
Screenshot of the power management applet in this case. (56.86 KB, image/png)
2024-09-09 04:54 UTC, vis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vis 2024-09-09 04:54:26 UTC
Created attachment 173468 [details]
Screenshot of the power management applet in this case.

SUMMARY
The power management applet doesn't seem to want to communicate with the power-profiles-daemon despite it being running without errors. It reads as if the daemon isn't installed. However, the hotkey to switch power profiles (Super+b by default) works and is able to change the power profile. This coincided with updating power-profiles-daemon to version 0.22-2 on archlinux. 

STEPS TO REPRODUCE
1. On arch, update power-profiles-daemon to 0.22-2
2. Reboot the system
3. Open the power management applet

OBSERVED RESULT
(see attachment) the power management applet does not detect the running power-profiles-daemon, and does not allow the user to change the power profile. 

EXPECTED RESULT
The power management applet allows the user to select a power profile. 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 6.10.8-arch1-1
KDE Plasma Version: 6.1.4-1
KDE Frameworks Version: 5.116.0-1
Qt Version: 6.7.2-2
Comment 1 kilgore.trout 2024-09-09 18:59:19 UTC
(In reply to vis from comment #0)
Can you check that the power-profiles-daemon service is running?

$ systemctl status power-profiles-daemon.service
Comment 2 vis 2024-09-09 19:43:23 UTC
(In reply to kilgore.trout from comment #1)
> (In reply to vis from comment #0)
> Can you check that the power-profiles-daemon service is running?
> 
> $ systemctl status power-profiles-daemon.service

~> systemctl status power-profiles-daemon.service
● power-profiles-daemon.service - Power Profiles daemon
     Loaded: loaded (/usr/lib/systemd/system/power-profiles-daemon.service; ena>
     Active: active (running) since Mon 2024-09-09 14:30:51 CDT; 10min ago
 Invocation: da9e98004ed2464a883de8b5fb3f002f
   Main PID: 3434 (power-profiles-)
      Tasks: 4 (limit: 37651)
     Memory: 2M (peak: 3M)
        CPU: 91ms
     CGroup: /system.slice/power-profiles-daemon.service
             └─3434 /usr/lib/power-profiles-daemon

Sep 09 14:30:51 bousfield systemd[1]: Starting Power Profiles daemon...
Sep 09 14:30:51 bousfield systemd[1]: Started Power Profiles daemon.

It's definitely running, as I can change the power profile via powerprofilesctl and the KDE hotkey.
Comment 3 kilgore.trout 2024-09-09 20:30:04 UTC
(In reply to vis from comment #2)
Check also that dbus.service is running, for both user and system.
Comment 4 vis 2024-09-11 12:41:45 UTC
(In reply to kilgore.trout from comment #3)
> (In reply to vis from comment #2)
> Check also that dbus.service is running, for both user and system.

It is, for both user and system.
Comment 5 Bug Janitor Service 2024-09-13 18:04:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/425
Comment 7 vis 2024-09-18 16:57:55 UTC
(In reply to Li Jiajun from comment #6)
> This is caused by
> https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/commit/
> 8277adb7cd89293fd4d32407eee1596ffbf6acce
> ppd starts too late for powerdevil

Aah that makes sense. And, when I restarted powerdevil manually (systemctl --user restart plasma-powerdevil) it starts working.
Comment 8 Nate Graham 2024-09-18 18:11:08 UTC
*** Bug 492945 has been marked as a duplicate of this bug. ***
Comment 9 Jakob Petsovits 2024-09-19 18:12:51 UTC
Git commit 8e698dbcdc9ce95095ea2739713fde05ca4822f5 by Jakob Petsovits.
Committed on 19/09/2024 at 18:06.
Pushed by jpetso into branch 'master'.

applets/batterymonitor: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for two out of three applet parts
(power profiles, inhibitions) but does not fix battery status;
the data for that is coming from `BatteryControlModel`
in plasma-workspace. A similar fix will have to be implemented there.
Related: bug 488915, bug 489003, bug 492945

M  +88   -12   applets/batterymonitor/plugin/powermanagementcontrol.cpp
M  +10   -2    applets/batterymonitor/plugin/powermanagementcontrol.h
M  +77   -1    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +10   -1    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/8e698dbcdc9ce95095ea2739713fde05ca4822f5
Comment 10 Bug Janitor Service 2024-09-19 19:26:39 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4729
Comment 11 Jakob Petsovits 2024-09-20 12:48:23 UTC
Git commit 0979a34248efa8eac087e418a4cf4419549ece0c by Jakob Petsovits.
Committed on 20/09/2024 at 12:26.
Pushed by jpetso into branch 'master'.

components/batterycontrol: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for one out of three applet parts
(battery state) but does not fix power profiles & inhibitions;
these were fixed separately in the powerdevil repository
via commit 8e698dbc.
Related: bug 488915, bug 489003, bug 492945

M  +82   -15   components/batterycontrol/batterycontrol.cpp
M  +6    -1    components/batterycontrol/batterycontrol.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/0979a34248efa8eac087e418a4cf4419549ece0c
Comment 12 Bug Janitor Service 2024-09-23 21:46:22 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/428
Comment 13 Jakob Petsovits 2024-09-23 21:49:08 UTC
Git commit 5e8cd380806da20d0b12bf97a3629ac70aa2b77c by Jakob Petsovits.
Committed on 23/09/2024 at 21:41.
Pushed by jpetso into branch 'Plasma/6.2'.

applets/batterymonitor: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for two out of three applet parts
(power profiles, inhibitions) but does not fix battery status;
the data for that is coming from `BatteryControlModel`
in plasma-workspace. A similar fix will have to be implemented there.
Related: bug 488915, bug 489003, bug 492945

M  +88   -12   applets/batterymonitor/plugin/powermanagementcontrol.cpp
M  +10   -2    applets/batterymonitor/plugin/powermanagementcontrol.h
M  +77   -1    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +10   -1    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/5e8cd380806da20d0b12bf97a3629ac70aa2b77c
Comment 14 Bug Janitor Service 2024-09-23 21:53:42 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4740
Comment 15 Jakob Petsovits 2024-09-23 22:09:58 UTC
The above fixes make the "Power and Battery" applet independent from timing of the PowerDevil daemon itself, which *might* fix this issue. But there is another snag in PowerDevil's applets/batterymonitor/plugin/powerprofilescontrol.cpp that could introduce problems:

After having detected the PowerDevil D-Bus service, the code in PowerProfilesControl::onServiceRegistered() checks for the D-Bus service of power-profiles-daemon being present. But if p-p-d appears later than PowerDevil itself, then this code will miss it and won't be looking out for p-p-d to reappear again later.

We'll have to tweak this code a little more to be entirely robust against timing issues.
Comment 16 Jakob Petsovits 2024-09-23 22:10:59 UTC
Git commit 43ca4f3bf083651c2ac8b803596e3827ed8d5e76 by Jakob Petsovits.
Committed on 23/09/2024 at 21:48.
Pushed by jpetso into branch 'Plasma/6.2'.

components/batterycontrol: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for one out of three applet parts
(battery state) but does not fix power profiles & inhibitions;
these were fixed separately in the powerdevil repository
via commit 8e698dbc (master branch) / commit 5e8cd380 (Plasma/6.2).
Related: bug 488915, bug 489003, bug 492945

M  +82   -15   components/batterycontrol/batterycontrol.cpp
M  +6    -1    components/batterycontrol/batterycontrol.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/43ca4f3bf083651c2ac8b803596e3827ed8d5e76
Comment 17 Andrea Ippolito 2024-10-30 23:52:58 UTC
(In reply to Jakob Petsovits from comment #16)
> Git commit 43ca4f3bf083651c2ac8b803596e3827ed8d5e76 by Jakob Petsovits.
> Committed on 23/09/2024 at 21:48.
> Pushed by jpetso into branch 'Plasma/6.2'.
> 
> components/batterycontrol: React to D-Bus service (un)register events
> 
> Previously, the "Power and Battery" applet only checked for the
> presence of PowerDevil's D-Bus services once when it starts up.
> This appears to (mostly?) work for applets embedded in a panel,
> but does not work for applets on the desktop itself.
> Likely there's a timing issue and applets on the desktop start
> sooner than PowerDevil will advertise its services.
> 
> A better way to work is for the applet to monitor the bus for when
> the relevant services appear or disappear. When observing a service
> registered or unregistered event, the applet gets set up accordingly.
> 
> This fixes the race condition for one out of three applet parts
> (battery state) but does not fix power profiles & inhibitions;
> these were fixed separately in the powerdevil repository
> via commit 8e698dbc (master branch) / commit 5e8cd380 (Plasma/6.2).
> Related: bug 488915, bug 489003, bug 492945
> 
> M  +82   -15   components/batterycontrol/batterycontrol.cpp
> M  +6    -1    components/batterycontrol/batterycontrol.h
> 
> https://invent.kde.org/plasma/plasma-workspace/-/commit/
> 43ca4f3bf083651c2ac8b803596e3827ed8d5e76

Hi Jacob, were you able to get this reviewed, by any chance?

I'm affected by this issue, and while it's not as bad as I initially feared (PPD is still running in the end, so my battery won't get killed), it's surely a lack of polish.

Thanks!

https://discuss.kde.org/t/power-and-battery-widget-fails-to-see-power-profiles-daemon-as-running/24716
https://forums.opensuse.org/t/kde-power-profiles-daemon-does-not-start-correctly/179921
Comment 18 Bug Janitor Service 2024-11-01 10:36:30 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/454
Comment 19 Méven 2024-11-04 09:41:21 UTC
Git commit 46a49ded6e4020e1ae2b0287e01fabc8e527a070 by Méven Car.
Committed on 04/11/2024 at 09:37.
Pushed by meven into branch 'master'.

applets: react to power-profile-daemon dbus registration

Made tlpInstalled a bindable property as it can change now.

M  +25   -13   applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +5    -3    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/46a49ded6e4020e1ae2b0287e01fabc8e527a070
Comment 20 Nate Graham 2024-11-04 20:41:06 UTC
Git commit e096c7e24b2e4a9167c735c27b58f709dec95922 by Nate Graham, on behalf of Méven Car.
Committed on 04/11/2024 at 20:41.
Pushed by ngraham into branch 'master'.

Applets/batterymonitor: correct dbus watcher

Amends 46a49ded

Now properly tested:

`sudo systemctl stop power-profiles-daemon.service` / \``sudo systemctl start power-profiles-daemon.service`\
is reflected by the applet immediately.

M  +18   -5    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +1    -0    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/e096c7e24b2e4a9167c735c27b58f709dec95922
Comment 21 Méven 2024-11-05 08:33:26 UTC
Git commit b159dec4edcb368d56b18dc1985b301ed40d6852 by Méven Car.
Committed on 05/11/2024 at 08:32.
Pushed by meven into branch 'cherry-pick-492859'.

applets: react to power-profile-daemon dbus registration

Made tlpInstalled a bindable property as it can change now.
(cherry picked from commit 46a49ded6e4020e1ae2b0287e01fabc8e527a070)

M  +25   -13   applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +5    -3    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/b159dec4edcb368d56b18dc1985b301ed40d6852
Comment 22 Méven 2024-11-05 08:33:34 UTC
Git commit b6ba7e1f3f7c04dfd75fe61d50ecb877742f6c6c by Méven Car.
Committed on 05/11/2024 at 08:33.
Pushed by meven into branch 'cherry-pick-492859'.

Applets/batterymonitor: correct dbus watcher

Amends 46a49ded

Now properly tested:

`sudo systemctl stop power-profiles-daemon.service` / \``sudo systemctl start power-profiles-daemon.service`\
is reflected by the applet immediately.
(cherry picked from commit e096c7e24b2e4a9167c735c27b58f709dec95922)

M  +18   -5    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +1    -0    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/b6ba7e1f3f7c04dfd75fe61d50ecb877742f6c6c
Comment 23 Méven 2024-11-05 11:03:19 UTC
Git commit fdaf3a64ca61c611178f9c3cb14d6bf91e884b31 by Méven Car.
Committed on 05/11/2024 at 09:47.
Pushed by meven into branch 'Plasma/6.2'.

Applets/batterymonitor: correct dbus watcher

Amends 46a49ded

Now properly tested:

`sudo systemctl stop power-profiles-daemon.service` / \``sudo systemctl start power-profiles-daemon.service`\
is reflected by the applet immediately.
(cherry picked from commit e096c7e24b2e4a9167c735c27b58f709dec95922)

M  +19   -6    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +1    -0    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/fdaf3a64ca61c611178f9c3cb14d6bf91e884b31