From c89fe961c26cf0d0865df48332b597eec82bf614 Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Sat, 18 Apr 2026 19:03:45 +0200 Subject: [PATCH 1/2] BluezAgent: request default agent on reply. This avoids the possibility we request default agent before an Agent is registered as reported by #3209. But unlike #3209 register is async. --- blueman/bluez/AgentManager.py | 14 +++++++++----- blueman/main/applet/BluezAgent.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/blueman/bluez/AgentManager.py b/blueman/bluez/AgentManager.py index 9f266e1b5..fc891054f 100644 --- a/blueman/bluez/AgentManager.py +++ b/blueman/bluez/AgentManager.py @@ -11,12 +11,16 @@ class AgentManager(Base): def __init__(self) -> None: super().__init__(obj_path=self._obj_path) - def register_agent(self, agent_path: str, capability: str = "", default: bool = False) -> None: + def register_agent(self, agent_path: ObjectPath, capability: str = "") -> None: + def on_reply() -> None: + self.request_default_agent(agent_path) + param = GLib.Variant('(os)', (agent_path, capability)) - self._call('RegisterAgent', param) - if default: - default_param = GLib.Variant('(o)', (agent_path,)) - self._call('RequestDefaultAgent', default_param) + self._call('RegisterAgent', param=param, reply_handler=on_reply) + + def request_default_agent(self, agent_path: ObjectPath) -> None: + default_param = GLib.Variant('(o)', (agent_path,)) + self._call('RequestDefaultAgent', default_param) def unregister_agent(self, agent_path: str) -> None: param = GLib.Variant('(o)', (agent_path,)) diff --git a/blueman/main/applet/BluezAgent.py b/blueman/main/applet/BluezAgent.py index 121b59a50..c019c98e0 100644 --- a/blueman/main/applet/BluezAgent.py +++ b/blueman/main/applet/BluezAgent.py @@ -30,7 +30,7 @@ class BluezErrorRejected(DbusError): class BluezAgent(DbusService): - __agent_path = '/org/bluez/agent/blueman' + __agent_path = ObjectPath('/org/bluez/agent/blueman') def __init__(self) -> None: super().__init__(None, "org.bluez.Agent1", self.__agent_path, Gio.BusType.SYSTEM) @@ -54,7 +54,7 @@ def __init__(self) -> None: def register_agent(self) -> None: logging.info("Register Agent") self.register() - AgentManager().register_agent(self.__agent_path, "KeyboardDisplay", default=True) + AgentManager().register_agent(self.__agent_path, "KeyboardDisplay") def unregister_agent(self) -> None: logging.info("Unregister Agent") From 692822f903ee07866cca34cb8a56504258c4a6fd Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Sat, 18 Apr 2026 19:10:56 +0200 Subject: [PATCH 2/2] BluezAgent: Make the log more useful Before it would show "register_agent: Register Agent" which is kinda useless as it just repeats the method name. Also "promote" this to debug as this is mostly useful for debugging. --- blueman/main/applet/BluezAgent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blueman/main/applet/BluezAgent.py b/blueman/main/applet/BluezAgent.py index c019c98e0..93a9c56f6 100644 --- a/blueman/main/applet/BluezAgent.py +++ b/blueman/main/applet/BluezAgent.py @@ -52,12 +52,12 @@ def __init__(self) -> None: self._service_notifications: list[_NotificationBubble | _NotificationDialog] = [] def register_agent(self) -> None: - logging.info("Register Agent") + logging.debug(self.__agent_path) self.register() AgentManager().register_agent(self.__agent_path, "KeyboardDisplay") def unregister_agent(self) -> None: - logging.info("Unregister Agent") + logging.debug(self.__agent_path) self.unregister() AgentManager().unregister_agent(self.__agent_path)