diff options
author | Sonny Sasaka <sonnysasaka@chromium.org> | 2022-05-12 22:27:07 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-14 00:19:16 +0000 |
commit | 22e252646c5a875a8f6f1889128bf0c84b96cf2a (patch) | |
tree | 2d4d5d61372f42ac49470e26fa738523815c11c3 | |
parent | b16365ce92edd1c058ec8c465b4c4565a7be43d1 (diff) | |
download | autotest-22e252646c5a875a8f6f1889128bf0c84b96cf2a.tar.gz |
bluetooth: Avoid duplicate PairingObserver name
ObserverBase does not accept multiple observers with the same name, so
when adding observer we should disambiguate PairingObserver by appending
its remote address. Otherwise, PairingObserver of multiple devices
cannot all be registered.
Also added a warning when observers are not added to help catch similar
bugs in the future more easily.
BUG=b:216352373
TEST=test_that bluetooth_AdapterMDHealth.md_two_connections_test.floss
Change-Id: Ib9c3e00e5ce41c979a553268ea1f7c33c8817833
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/3647077
Tested-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@google.com>
Commit-Queue: Sonny Sasaka <sonnysasaka@chromium.org>
-rw-r--r-- | client/cros/bluetooth/floss/observer_base.py | 2 | ||||
-rw-r--r-- | client/cros/multimedia/bluetooth_facade.py | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/client/cros/bluetooth/floss/observer_base.py b/client/cros/bluetooth/floss/observer_base.py index bb95db693a..92373806fa 100644 --- a/client/cros/bluetooth/floss/observer_base.py +++ b/client/cros/bluetooth/floss/observer_base.py @@ -8,6 +8,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import logging class ObserverBase: """Simple observer base class that provides the observer pattern.""" @@ -26,6 +27,7 @@ class ObserverBase: self.observers[name] = observer return True + logging.warn('Observer {} already exists, not adding'.format(name)) return False def remove_observer(self, name, observer): diff --git a/client/cros/multimedia/bluetooth_facade.py b/client/cros/multimedia/bluetooth_facade.py index 12704a1ca4..a96e849936 100644 --- a/client/cros/multimedia/bluetooth_facade.py +++ b/client/cros/multimedia/bluetooth_facade.py @@ -4568,7 +4568,7 @@ class FlossFacadeLocal(BluetoothBaseFacadeLocal): def __init__(self, adapter_client, done_event, address, pin): self.adapter_client = adapter_client self.adapter_client.register_callback_observer( - 'PairingObserver', self) + 'PairingObserver' + address, self) # Event to trigger once we are paired and connected. self.done_event = done_event @@ -4585,7 +4585,7 @@ class FlossFacadeLocal(BluetoothBaseFacadeLocal): def cleanup(self): """Clean up after this observer.""" self.adapter_client.unregister_callback_observer( - 'PairingObserver', self) + 'PairingObserver' + address, self) self.adapter_client = None def on_bond_state_changed(self, status, device_address, state): |