Add battery charge threshold setting inside gnome-control-center.
[Feature] Battery charge threshold control solution.
To increase battery lifespan for laptop users, we could add some system solution to control the /sys/class/power_supply/BAT*/charge_control_end_threshold
parameter through gnome-control-center
.
This topic was discussed in several issues, but as far as i know, nobody implemented a solution, so i have investigated this topic, and i came up with two solutions:
Solution 1 - temporary
- The non-invasive one, is to deploy external application for setting
charge_control_end_threshold
which reacts to gsetting-key changes (key is shipped with that application) - Then install
gnome-shell
extension, which controls that gsetting. - Then, it is required to change permission of
charge_control_end_threshold
file. Unfortunately, this permission resets with system startup. So two services have to be enabled - one to start up application (as user - to read user gsetting and write tocharge_control_end_threshold
), and second for that file permission change, which is done via udev (as root).
You can check possible implementation here.
Note: If someone wants to use this solution, but with gnome-control-center
insted of shell extension, i have provided modified version of control center here.
Solution 2 - the real one
The true solution involves changes in gnome-control-center
and gnome-settings-daemon
.
- First we need to add new keys to GSD schemas (maybe
battery-charge-threshold-switch
andbattery-charge-threshold-value
inside/org/gnome/settings-daemon/plugins/power
) - Modify GSD power plugin, which should allow GSD to change value of charge_control_end_threshold file.
- Make UI changes in
gnome-control-center
. This will require changes in upower (adding missing enum value)... - ... also update battery charge time counter in
gnome-shell
Known Problems
-
gnome-control-center
andgnome-shell
does not handle properly "charge counters" when charging is thresholded. To fix this, we can use ugly methods like checking requested threshold value with current value and alter counter text accordingly... The ideal solution would be to extendUpDeviceState
enum withinupower
(docs) allowing it to detect that situation and propagate that enum to GNOME applications.
Design Tasks
-
Decide if this feature is only for toggling or if should we add precise sliders etc. -
Create intuitive UI for parameters control.
Development Tasks
-
Adding two new keys to gsd schema battery-charge-threshold-enabled
andbattery-charge-threshold-value
-
Adding appropriate d-bus interface methods: IsThresholdEnabled
,IsAnyBatterySupported
,Enable
,Disable
,GetThresholdValue
,SetThresholdValue
-
Making gsd aware of schema keys changes. -
Creating helper for value set. -
Adding polkit policy for helper application. -
Make UI changes in gnome-control-center
and use new gsd-power plugin API to make file changes. -
Fix shell charge counter.
Edited by Arkadiusz Jarlaczyk