diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2013-06-27 17:43:03 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-28 08:39:01 +0200 |
commit | 42e8371600155bcff620929d5bf4dff998f3324f (patch) | |
tree | a0b89ad51f07f50eca28903212049423bddc58c5 /src/bluetooth/qbluetoothlocaldevice_qnx.cpp | |
parent | 06533c66b54f2ac9a9911e093723b71e27bd677d (diff) |
Fix broken QBluetoothLocalDevice::isValid() behavior
The Bluez and QNX backend always returned true. They should only
return true if the local device is truly available or if the
passed QBluetoothAddress is indeed one of the local bluetooth
devices.
The related unit test was extended to ensure common bahvior of
invalid QBluetoothLocalDevice instance on all platforms.
Task-number: QTBUG-32068
Change-Id: I40ab4db48dc82ba0d1c0bb5275e96a3ee812b01a
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Reviewed-by: Alex <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_qnx.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_qnx.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp index 767e7682..02fe647b 100644 --- a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp @@ -50,23 +50,30 @@ QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : QObject(parent) { this->d_ptr = new QBluetoothLocalDevicePrivate(); + this->d_ptr->isValidDevice = true; //assume single local device on QNX } QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) : QObject(parent) { - Q_UNUSED(address) this->d_ptr = new QBluetoothLocalDevicePrivate(); + + //works since we assume a single local device on QNX + this->d_ptr->isValidDevice = (QBluetoothLocalDevicePrivate::address() == address); } QString QBluetoothLocalDevice::name() const { - return this->d_ptr->name(); + if (this->d_ptr->isValid()) + return this->d_ptr->name(); + return QString(); } QBluetoothAddress QBluetoothLocalDevice::address() const { - return this->d_ptr->address(); + if (this->d_ptr->isValid()) + return this->d_ptr->address(); + return QBluetoothAddress(); } void QBluetoothLocalDevice::powerOn() @@ -98,11 +105,15 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) { Q_UNUSED(pairing); - ppsSendControlMessage("initiate_pairing", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), 0); + if (isValid()) + ppsSendControlMessage("initiate_pairing", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), 0); } QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const { + if (!isValid()) + return Unpaired; + QVariant status = ppsRemoteDeviceStatus(address.toString().toLocal8Bit(), "paired"); if (status.toBool()) return Paired; @@ -126,6 +137,11 @@ QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate() ppsUnreguisterForEvent(QString("access_changed"), this); } +bool QBluetoothLocalDevicePrivate::isValid() const +{ + return isValidDevice; +} + QBluetoothAddress QBluetoothLocalDevicePrivate::address() { return QBluetoothAddress(ppsReadSetting("btaddr").toString()); @@ -138,16 +154,21 @@ QString QBluetoothLocalDevicePrivate::name() void QBluetoothLocalDevicePrivate::powerOn() { - ppsSendControlMessage("radio_init", this); + if (isValid()) + ppsSendControlMessage("radio_init", this); } void QBluetoothLocalDevicePrivate::powerOff() { - ppsSendControlMessage("radio_shutdown", this); + if (isValid()) + ppsSendControlMessage("radio_shutdown", this); } void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode mode) { + if (!isValid()) + return; + QBluetoothLocalDevice::HostMode currentHostMode = hostMode(); if (currentHostMode == mode){ return; @@ -173,6 +194,9 @@ void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode m } QBluetoothLocalDevice::HostMode QBluetoothLocalDevicePrivate::hostMode() const { + if (!isValid()) + return QBluetoothLocalDevice::HostPoweredOff; + if (!ppsReadSetting("enabled").toBool()) return QBluetoothLocalDevice::HostPoweredOff; |