Avoid touching the trickle charge action if other software configured 'Custom'

When configured as 'Custom' PPD will stomp on other software's changes.
Check explicitly for this value and avoid making changes while it's set.

This is a short term solution.  Longer term a new upower API will be used.

Closes: https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/issues/177
This commit is contained in:
Mario Limonciello 2025-02-11 13:42:25 -06:00 committed by Marco Trevisan (Treviño)
parent c47fea05d4
commit aeff8be3aa
2 changed files with 52 additions and 1 deletions

View file

@ -67,6 +67,12 @@ set_charge_type (PpdActionTrickleCharge *action,
if (!value)
continue;
if (g_strcmp0 (value, "Custom") == 0) {
g_debug ("Not setting charge type for '%s' due to 'Custom'",
g_udev_device_get_sysfs_path (dev));
continue;
}
if (g_strcmp0 (charge_type, value) == 0)
continue;
@ -115,7 +121,7 @@ uevent_cb (GUdevClient *client,
g_debug ("Updating charge type for '%s' to '%s'",
g_udev_device_get_sysfs_path (device),
charge_type);
ppd_utils_write_sysfs (device, CHARGE_TYPE_SYSFS_NAME, charge_type, NULL);
set_charge_type (self, charge_type);
}
static void

View file

@ -314,6 +314,16 @@ class Tests(dbusmock.DBusTestCase):
contents if isinstance(contents, bytes) else contents.encode("utf-8")
)
def write_sysfs_file(self, path, contents):
"""Writes a sysfs file"""
return self.write_file_contents(
self.testbed.get_root_dir() + "/" + path, contents
)
def write_sysfs_attr(self, device, attribute, contents):
"""Writes a sysfs attribute"""
return self.write_sysfs_file(device + "/" + attribute, contents)
def change_immutable(self, fname, enable):
attr = "-"
if enable:
@ -1776,6 +1786,41 @@ class Tests(dbusmock.DBusTestCase):
# verify power saver didn't get updated for it
self.assert_sysfs_attr_eventually_is(edp3, amdgpu_panel_power_savings, "0")
def test_custom_trickle_charge_device(self):
"""Attempt to Trickle power_supply charge type, but already set to Custom"""
fastcharge = self.testbed.add_device(
"power_supply",
"bq24190-charger",
None,
["charge_type", "Custom", "scope", "Device"],
[],
)
self.start_daemon()
self.assert_action_enabled("trickle_charge")
# Verify that charge-type stays untouched
self.assertEqual(self.read_sysfs_attr(fastcharge, "charge_type"), b"Custom")
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("power-saver"))
self.assert_sysfs_attr_eventually_is(fastcharge, "charge_type", "Custom")
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("balanced"))
self.assert_sysfs_attr_eventually_is(fastcharge, "charge_type", "Custom")
# verify charge type is touched again
self.write_sysfs_attr(fastcharge, "charge_type", "Fast")
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("power-saver"))
self.assert_sysfs_attr_eventually_is(fastcharge, "charge_type", "Trickle")
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("balanced"))
self.assert_sysfs_attr_eventually_is(fastcharge, "charge_type", "Fast")
# verify it's not touched again
self.write_sysfs_attr(fastcharge, "charge_type", "Custom")
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("power-saver"))
self.assert_sysfs_attr_eventually_is(fastcharge, "charge_type", "Custom")
def test_trickle_charge_system(self):
"""Trickle power_supply charge type"""