Add support for POWER_PROFILE_DAEMON_ACTION_BLOCK

This can let people avoid loading actions that on their system
in the event of a problem or desire not to use.
This commit is contained in:
Mario Limonciello 2024-01-26 23:38:45 -06:00 committed by Marco Trevisan
parent 41ed5d33a8
commit 07a77652b1
2 changed files with 43 additions and 0 deletions

View file

@ -976,6 +976,21 @@ stop_profile_drivers (PpdApp *data)
g_clear_object (&data->platform_driver);
}
static gboolean
action_blocked (PpdAction *action)
{
const gchar *action_name = ppd_action_get_action_name (action);
const gchar *env = g_getenv ("POWER_PROFILE_DAEMON_ACTION_BLOCK");
if (env == NULL)
return FALSE;
g_auto(GStrv) actions = NULL;
actions = g_strsplit (env, ",", -1);
return g_strv_contains ((const gchar *const *)actions, action_name);
}
static gboolean
driver_blocked (PpdDriver *driver)
{
@ -1063,6 +1078,11 @@ start_profile_drivers (PpdApp *data)
g_debug ("Handling action '%s'", ppd_action_get_action_name (action));
if (action_blocked (action)) {
g_debug ("Action '%s' is blocked, skipping", ppd_action_get_action_name (action));
continue;
}
if (ppd_action_probe (action) == PPD_PROBE_RESULT_FAIL) {
g_debug ("probe () failed for action '%s', skipping",
ppd_action_get_action_name (action));

View file

@ -809,6 +809,29 @@ class Tests(dbusmock.DBusTestCase):
self.stop_daemon()
def test_action_blocklist(self):
"""Test action blocklist works"""
self.testbed.add_device(
"drm",
"card1-eDP",
None,
["amdgpu/panel_power_savings", "0"],
["DEVTYPE", "drm_connector"],
)
self.create_amd_apu()
self.spawn_server_template(
"upower",
{"DaemonVersion": "0.99", "OnBattery": False},
stdout=subprocess.PIPE,
)
# Block panel_power action
os.environ["POWER_PROFILE_DAEMON_ACTION_BLOCK"] = "amdgpu_panel_power"
self.start_daemon()
self.assertNotIn("amdgpu_panel_power", self.get_dbus_property("Actions"))
def test_driver_blocklist(self):
"""Test driver blocklist works"""
# Create 2 CPUs with preferences