Draft: components/batterycontrol: add per-battery charge limit info

Depends on frameworks/solid!217 (closed) being merged and included in an official release. Marking as draft until that's the case. Review & testing is encouraged already.

Reason for the change

Solid from KF 6.18 provides this through UPower's relatively new D-Bus API, which allows re-applying charge limits on every boot.

So far, the BatteryControl component has been using PowerDevil's D-Bus getter method for a single stop threshold value. That is not ideal: in rare edge cases batteries might use different values, and Plasma's battery applet shows per-battery items anyway.

However, migrating from PowerDevil's charge threshold functionality to UPower will take some more work. UPower does not yet allow customizing charge thresholds so an immediate switch would be a regression; also, more work needs to happen for a clean migration of the current battery state to initialize UPower's configuration.

So, until further notice, BatteryControl continues using PowerDevil's stop threshold value unless PowerDevil advertises by itself that this value is obsolete. If it is, the newly introduced per-battery values from UPower (via Solid) are used.

Test plan

When plugged in and charge limits are enabled, the battery applet will show the text "Battery is configured to charge up to approximately N%.". When discharging or charge thresholds are set to 100%, this text will not appear. Testing is to ensure that this behavior continues to work as it currently does.

On a laptop with charge threshold support, test that an unchanged charge threshold setup will continue to work. Set charge limits like PowerDevil currently does, before we change it to use UPower later on.

sudo bash -c "echo -n 85 > /sys/class/power_supply/BAT0/charge_control_end_threshold"
sudo bash -c "echo -n 80 > /sys/class/power_supply/BAT0/charge_control_start_threshold"
sudo bash -c "echo -n Custom > /sys/class/power_supply/BAT0/charge_types" # may be required if the charge_types file exists, e.g. on Dell Latitudes
systemctl restart --user plasma-powerdevil # re-read charge thresholds - yes, it's not monitoring these right now, not even when configured via KCM
systemctl restart --user plasma-plasmashell # update the widget to this MR

Ensure that the aforementioned text appears in the applet when plugging in.


On a laptop with charge threshold support and UPower >= 1.90.5, apply the matching PowerDevil MR (pending submission), configure a preference for UPower charge limits, and enable charge limits in the KCM (a.k.a. "Battery protection"). Ensure that the aforementioned text still appears in the applet when plugging in.

Screenshots or screen recordings

No visual changes intended.

Bugs fixed

CCBUG: 450551

Merge request reports

Loading