Skip to content

Commit

Permalink
use device UUID instead of hardware address for BT devices on iOS and…
Browse files Browse the repository at this point in the history
… macOS

The hardware address is not exposed on iOS and macOS due to security/privacy considerations
  • Loading branch information
lachlanhurst committed Jun 8, 2018
1 parent f2e637f commit 1e5cfcf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bleuart.cpp
Expand Up @@ -55,8 +55,18 @@ void BleUart::startConnect(QString addr)
mUartServiceFound = false;
mConnectDone = false;

#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
// Create BT Controller from unique device UUID stored as addr. Creating
// a controller using a devices address is not supported on macOS or iOS.
QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo();
deviceInfo.setDeviceUuid(QBluetoothUuid(addr));
mControl = new QLowEnergyController(deviceInfo);

#else
mControl = new QLowEnergyController(QBluetoothAddress(addr));

#endif

mControl->setRemoteAddressType(QLowEnergyController::RandomAddress);

connect(mControl, SIGNAL(serviceDiscovered(QBluetoothUuid)),
Expand Down Expand Up @@ -122,8 +132,15 @@ void BleUart::addDevice(const QBluetoothDeviceInfo &dev)
if (dev.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) {
qDebug() << "BLE scan found device:" << dev.name();

#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
// macOS and iOS do not expose the hardware address of BLTE devices, must use
// the OS generated UUID.
mDevs.insert(dev.deviceUuid().toString(), dev.name());
#else
mDevs.insert(dev.address().toString(), dev.name());

#endif

emit scanDone(mDevs, false);
}
}
Expand Down

0 comments on commit 1e5cfcf

Please sign in to comment.