diff --git a/src/ppd-driver-platform-profile.c b/src/ppd-driver-platform-profile.c index 1c1726b..28fc335 100644 --- a/src/ppd-driver-platform-profile.c +++ b/src/ppd-driver-platform-profile.c @@ -81,19 +81,23 @@ acpi_platform_profile_value_to_profile (const char *str) if (str == NULL) return PPD_PROFILE_UNSET; - switch (str[0]) { - case 'l': /* low-power */ - case 'q': /* quiet */ + if (g_str_equal (str, "custom")) + return PPD_PROFILE_UNSET; + + if (g_str_equal (str, "low-power") || + g_str_equal (str, "quiet")) return PPD_PROFILE_POWER_SAVER; - case 'c': /* cool */ - case 'b': + + if (g_str_equal (str, "balanced") || + g_str_equal (str, "balanced_performance") || + g_str_equal (str, "cool")) return PPD_PROFILE_BALANCED; - case 'p': + + if (g_str_equal (str, "performance")) return PPD_PROFILE_PERFORMANCE; - default: - g_debug ("Unhandled ACPI platform profile '%c'", str[0]); - g_return_val_if_reached (PPD_PROFILE_UNSET); - } + + g_debug ("Unhandled ACPI platform profile '%s'", str); + g_return_val_if_reached (PPD_PROFILE_UNSET); } static PpdProfile @@ -113,9 +117,9 @@ read_platform_profile (void) return PPD_PROFILE_UNSET; } - new_profile = acpi_platform_profile_value_to_profile (new_profile_str); - g_debug ("ACPI performance_profile is now %c, so profile is detected as %s", - new_profile_str[0], + new_profile = acpi_platform_profile_value_to_profile (g_strchomp (new_profile_str)); + g_debug ("ACPI performance_profile is now '%s', so profile is detected as %s", + g_strchomp (new_profile_str), ppd_profile_to_str (new_profile)); return new_profile; } diff --git a/tests/integration_test.py b/tests/integration_test.py index e9ce9b6..0994cf2 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -377,6 +377,15 @@ class Tests(dbusmock.DBusTestCase): "low-power balanced performance\n", ) + def create_custom_platform_profile(self): + acpi_dir = os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/") + os.makedirs(acpi_dir, exist_ok=True) + self.write_file_contents(os.path.join(acpi_dir, "platform_profile"), "custom\n") + self.write_file_contents( + os.path.join(acpi_dir, "platform_profile_choices"), + "low-power balanced performance custom\n", + ) + def remove_platform_profile(self): acpi_dir = os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/") os.remove(os.path.join(acpi_dir, "platform_profile_choices")) @@ -1984,6 +1993,18 @@ class Tests(dbusmock.DBusTestCase): self.read_sysfs_file("sys/firmware/acpi/platform_profile"), b"quiet" ) + def test_custom_acpi_platform_profile(self): + self.create_custom_platform_profile() + self.start_daemon() + profiles = self.get_dbus_property("Profiles") + self.assertEqual(len(profiles), 3) + self.assertEqual(profiles[0]["PlatformDriver"], "platform_profile") + + # make sure PPD overrides it + self.assertEqual( + self.read_sysfs_file("sys/firmware/acpi/platform_profile"), b"balanced" + ) + def test_hold_release_profile(self): self.create_platform_profile() self.start_daemon()