From 985f4fdb40dbb9381d2832d33d06a055e170c8a4 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 20 Aug 2021 12:49:44 +0200 Subject: [PATCH] Fix Bluetooth Discovery on Android again --- libnymea-app/wifisetup/bluetoothdiscovery.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libnymea-app/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp index 9c8d262c..10ec26ba 100644 --- a/libnymea-app/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app/wifisetup/bluetoothdiscovery.cpp @@ -178,11 +178,21 @@ void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice: void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo) { - qCDebug(dcBtWiFiSetup()) << "BluetoothDiscovery: Device discovered:" << deviceInfo.address().toString() << deviceInfo.deviceUuid(); + qCDebug(dcBtWiFiSetup()) << "BluetoothDiscovery: Device discovered:" << deviceInfo.name() << deviceInfo.address().toString() << deviceInfo.deviceUuid(); foreach (BluetoothDeviceInfo *di, m_deviceInfos->deviceInfos()) { - if (di->bluetoothDeviceInfo().deviceUuid() == deviceInfo.deviceUuid()) { - di->setBluetoothDeviceInfo(deviceInfo); - return; + // Some platforms only provide device UUID (e.g. Apple) and MAC address is 00:00:00:00:00 + // Others provide only a MAC address and the UUID is null. + // If we have a UUID, use that, otherwise use the MAC for comparison + if (!deviceInfo.deviceUuid().isNull()) { + if (di->bluetoothDeviceInfo().deviceUuid() == deviceInfo.deviceUuid()) { + di->setBluetoothDeviceInfo(deviceInfo); + return; + } + } else { + if (di->bluetoothDeviceInfo().address() == deviceInfo.address()) { + di->setBluetoothDeviceInfo(deviceInfo); + return; + } } }