1Fix fail to enable bluetooth issue 2 3When launch blueman-manager while bluetooth is disable, it may fails 4with error: 5 6 Failed to enable bluetooth 7 8Because when get bluetooth status right after change its status, the 9status may not be updated that plugin applet/KillSwitch.py sets the 10bluetooth status via method of another dbus service which doesn't return 11immediately. 12 13Provides a new dbus method for PowerManager which checks whether dbus 14method SetBluetoothStatus() has finished. Then it makes sure to get 15right bluetooth status. 16 17Upstream-Status: Inappropriate 18Send to upstream but not accepted: 19https://github.com/blueman-project/blueman/pull/1121 20 21Signed-off-by: Kai Kang <kai.kang@windriver.com> 22--- 23 blueman/Functions.py | 10 ++++++++++ 24 blueman/plugins/applet/PowerManager.py | 4 ++++ 25 2 files changed, 14 insertions(+) 26 27diff --git a/blueman/Functions.py b/blueman/Functions.py 28index 3917f42..b4d5eae 100644 29--- a/blueman/Functions.py 30+++ b/blueman/Functions.py 31@@ -80,6 +80,16 @@ def check_bluetooth_status(message: str, exitfunc: Callable[[], Any]) -> None: 32 return 33 34 applet.SetBluetoothStatus('(b)', True) 35+ 36+ timeout = time.time() + 10 37+ while applet.GetRequestStatus(): 38+ time.sleep(0.1) 39+ if time.time() > timeout: 40+ # timeout 5s has been set in applet/PowerManager.py 41+ # so it should NOT reach timeout here 42+ logging.warning('Should NOT reach timeout.') 43+ break 44+ 45 if not applet.GetBluetoothStatus(): 46 print('Failed to enable bluetooth') 47 exitfunc() 48diff --git a/blueman/plugins/applet/PowerManager.py b/blueman/plugins/applet/PowerManager.py 49index c2f7bc3..bf6c99f 100644 50--- a/blueman/plugins/applet/PowerManager.py 51+++ b/blueman/plugins/applet/PowerManager.py 52@@ -63,6 +63,7 @@ class PowerManager(AppletPlugin, StatusIconProvider): 53 self._add_dbus_signal("BluetoothStatusChanged", "b") 54 self._add_dbus_method("SetBluetoothStatus", ("b",), "", self.request_power_state) 55 self._add_dbus_method("GetBluetoothStatus", (), "b", self.get_bluetooth_status) 56+ self._add_dbus_method("GetRequestStatus", (), "b", self.get_request_status) 57 58 def on_unload(self) -> None: 59 self.parent.Plugins.Menu.unregister(self) 60@@ -196,6 +197,9 @@ class PowerManager(AppletPlugin, StatusIconProvider): 61 def get_bluetooth_status(self) -> bool: 62 return self.current_state 63 64+ def get_request_status(self): 65+ return self.request_in_progress 66+ 67 def on_adapter_property_changed(self, _path: str, key: str, value: Any) -> None: 68 if key == "Powered": 69 if value and not self.current_state: 70-- 712.31.1 72 73