power-profiles-daemon: Emit ProfileReleased when an holder is released

We used to send the signal only when cleaning up the holders, but we
should notify them also when an holder has been released for whatever
reason.
This commit is contained in:
Marco Trevisan (Treviño) 2024-02-14 05:25:49 +01:00 committed by Marco Trevisan
parent 91e907e11f
commit 40f3361473
2 changed files with 30 additions and 7 deletions

View file

@ -499,6 +499,21 @@ activate_target_profile (PpdApp *data,
return TRUE;
}
static void
release_hold_notify (PpdApp *data,
ProfileHold *hold,
guint cookie)
{
const char *req_path = POWER_PROFILES_DBUS_PATH;
if (g_strcmp0 (hold->requester_iface, POWER_PROFILES_LEGACY_IFACE_NAME) == 0)
req_path = POWER_PROFILES_LEGACY_DBUS_PATH;
g_dbus_connection_emit_signal (data->connection, hold->requester, req_path,
hold->requester_iface, "ProfileReleased",
g_variant_new ("(u)", cookie), NULL);
}
static void
release_all_profile_holds (PpdApp *data)
{
@ -509,14 +524,8 @@ release_all_profile_holds (PpdApp *data)
while (g_hash_table_iter_next (&iter, &key, &value)) {
ProfileHold *hold = value;
guint cookie = GPOINTER_TO_UINT (key);
const char *req_path = POWER_PROFILES_DBUS_PATH;
if (g_strcmp0 (hold->requester_iface, POWER_PROFILES_LEGACY_IFACE_NAME) == 0)
req_path = POWER_PROFILES_LEGACY_DBUS_PATH;
g_dbus_connection_emit_signal (data->connection, hold->requester, req_path,
hold->requester_iface, "ProfileReleased",
g_variant_new ("(u)", cookie), NULL);
release_hold_notify (data, hold, cookie);
g_bus_unwatch_name (cookie);
}
g_hash_table_remove_all (data->profile_holds);
@ -640,6 +649,7 @@ release_profile_hold (PpdApp *data,
g_bus_unwatch_name (cookie);
hold_profile = hold->profile;
release_hold_notify (data, hold, cookie);
g_hash_table_remove (data->profile_holds, GUINT_TO_POINTER (cookie));
if (g_hash_table_size (data->profile_holds) == 0 &&

View file

@ -1666,6 +1666,17 @@ class Tests(dbusmock.DBusTestCase):
]
)
released_cookie = None
def signal_cb(_, sender, signal, params):
nonlocal released_cookie
if signal == "ProfileReleased":
released_cookie = params
self.addCleanup(
self.proxy.disconnect, self.proxy.connect("g-signal", signal_cb)
)
self.assertEqual(self.get_dbus_property("ActiveProfile"), "performance")
profile_holds = self.get_dbus_property("ActiveProfileHolds")
self.assertEqual(len(profile_holds), 1)
@ -1674,6 +1685,7 @@ class Tests(dbusmock.DBusTestCase):
self.assertEqual(profile_holds[0]["ApplicationId"], "testApplication")
self.call_dbus_method("ReleaseProfile", GLib.Variant("(u)", cookie))
self.assert_eventually(lambda: released_cookie == cookie)
self.assert_eventually(
lambda: self.changed_properties.get("ActiveProfile") == "balanced"
)
@ -1725,6 +1737,7 @@ class Tests(dbusmock.DBusTestCase):
)
self.assertEqual(self.get_dbus_property("ActiveProfile"), "performance")
self.call_dbus_method("ReleaseProfile", GLib.Variant("(u)", cookie))
self.assert_eventually(lambda: released_cookie == cookie)
self.assert_eventually(
lambda: self.changed_properties.get("ActiveProfileHolds") == []
)