From f5fe6ce47841be34d4b851725d80133ff6d14fee Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 26 Jul 2016 08:51:01 +0200 Subject: 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../qbluetoothdevicediscoveryagent_android.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp') 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; + } } } -- cgit v1.2.3