aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-connectivity/blueman/blueman/0002-fix-fail-to-enable-bluetooth.patch
blob: 282d821374938558dae07456f49c5edca7ee0d85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Fix fail to enable bluetooth issue

When launch blueman-manager while bluetooth is disable, it may fails
with error:

  Failed to enable bluetooth

Because when get bluetooth status right after change its status, the
status may not be updated that plugin applet/KillSwitch.py sets the
bluetooth status via method of another dbus service which doesn't return
immediately.

Provides a new dbus method for PowerManager which checks whether dbus
method SetBluetoothStatus() has finished. Then it makes sure to get
right bluetooth status.

Upstream-Status: Inappropriate
Send to upstream but not accepted:
https://github.com/blueman-project/blueman/pull/1121

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 blueman/Functions.py                   | 10 ++++++++++
 blueman/plugins/applet/PowerManager.py |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/blueman/Functions.py b/blueman/Functions.py
index 3917f42..b4d5eae 100644
--- a/blueman/Functions.py
+++ b/blueman/Functions.py
@@ -80,6 +80,16 @@ def check_bluetooth_status(message: str, exitfunc: Callable[[], Any]) -> None:
             return
 
     applet.SetBluetoothStatus('(b)', True)
+
+    timeout = time.time() + 10
+    while applet.GetRequestStatus():
+        time.sleep(0.1)
+        if time.time() > timeout:
+            # timeout 5s has been set in applet/PowerManager.py
+            # so it should NOT reach timeout here
+            logging.warning('Should NOT reach timeout.')
+            break
+
     if not applet.GetBluetoothStatus():
         print('Failed to enable bluetooth')
         exitfunc()
diff --git a/blueman/plugins/applet/PowerManager.py b/blueman/plugins/applet/PowerManager.py
index c2f7bc3..bf6c99f 100644
--- a/blueman/plugins/applet/PowerManager.py
+++ b/blueman/plugins/applet/PowerManager.py
@@ -63,6 +63,7 @@ class PowerManager(AppletPlugin, StatusIconProvider):
         self._add_dbus_signal("BluetoothStatusChanged", "b")
         self._add_dbus_method("SetBluetoothStatus", ("b",), "", self.request_power_state)
         self._add_dbus_method("GetBluetoothStatus", (), "b", self.get_bluetooth_status)
+        self._add_dbus_method("GetRequestStatus", (), "b", self.get_request_status)
 
     def on_unload(self) -> None:
         self.parent.Plugins.Menu.unregister(self)
@@ -196,6 +197,9 @@ class PowerManager(AppletPlugin, StatusIconProvider):
     def get_bluetooth_status(self) -> bool:
         return self.current_state
 
+    def get_request_status(self):
+        return self.request_in_progress
+
     def on_adapter_property_changed(self, _path: str, key: str, value: Any) -> None:
         if key == "Powered":
             if value and not self.current_state:
-- 
2.31.1