summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-07-26 08:51:01 +0200
committerAlex Blasche <alexander.blasche@qt.io>2016-08-01 15:05:18 +0000
commitf5fe6ce47841be34d4b851725d80133ff6d14fee (patch)
tree1d9e78e6802c1c8f05cf60d537e6cc12640efae4
parent66fc8db55e03648f1c65dcbeb58ff8f06e10f6f5 (diff)
Android: Avoid newDevice signal spamming in QBluetoothDeviceDiscoveryAgent
SDP based scans and LE scans can find the saame device (address) with different device names. This is caused by the fact that different channels are used to retrieve the information. Those two channels can advertise different device names. Before this patch the first entry was added to the list of discovered devices. When the second entry with different name came about, the entry was never added to the list of discovered devices. Nevertheless the deviceDiscovered() signal was triggered each time. This lead to a situation where application which were listening to the signal only never noticed the duplicated entries and showed a new discovered device each time the address matched but not the remainder of the device info. This problem was made worse by the fact that the LE scan on Android continues to fire the new device discovered signal once per second. This patch distinguishes devices with the same address but different names. They are treated as separate entries now. Change-Id: I77259a888708309338110831e86bb7ce9253f2a6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index d401fa58..e20fa723 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -221,6 +221,11 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(
Q_Q(QBluetoothDeviceDiscoveryAgent);
+ // Android Classic scan and LE scan can find the same device under different names
+ // The classic name finds the SDP based device name, the LE scan finds the name in
+ // the advertisement package.
+ // If address is same but name different then we keep both entries.
+
for (int i = 0; i < discoveredDevices.size(); i++) {
if (discoveredDevices[i].address() == info.address()) {
if (discoveredDevices[i] == info) {
@@ -229,11 +234,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(
return;
}
- // same device found -> avoid duplicates and update core configuration
- discoveredDevices[i].setCoreConfigurations(discoveredDevices[i].coreConfigurations() | info.coreConfigurations());
-
- emit q->deviceDiscovered(info);
- return;
+ if (discoveredDevices.at(i).name() == info.name()) {
+ qCDebug(QT_BT_ANDROID) << "Almost Duplicate "<< info.address()
+ << info.name() << "- replacing in place";
+ discoveredDevices.replace(i, info);
+ emit q->deviceDiscovered(info);
+ return;
+ }
}
}