summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/bluetooth/scanner/scanner.qml2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp3
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_android.cpp24
-rw-r--r--src/bluetooth/qlowenergyservice.cpp15
-rw-r--r--src/imports/bluetooth/plugins.qmltypes3
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp27
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h3
7 files changed, 59 insertions, 18 deletions
diff --git a/examples/bluetooth/scanner/scanner.qml b/examples/bluetooth/scanner/scanner.qml
index 67aaecf0..543e19de 100644
--- a/examples/bluetooth/scanner/scanner.qml
+++ b/examples/bluetooth/scanner/scanner.qml
@@ -60,6 +60,8 @@ Item {
console.log("Error: Bluetooth device not turned on"); break;
case BluetoothDiscoveryModel.InputOutputError:
console.log("Error: Bluetooth I/O Error"); break;
+ case BluetoothDiscoveryModel.InvalidBluetoothAdapterError:
+ console.log("Error: Invalid Bluetooth Adapter Error"); break;
case BluetoothDiscoveryModel.NoError:
break;
default:
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index c800dc6d..ef28ef82 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -91,7 +91,8 @@ QT_BEGIN_NAMESPACE
\value PoweredOffError The Bluetooth adaptor is powered off, power it on before doing discovery.
\value InputOutputError Writing or reading from the device resulted in an error.
\value InvalidBluetoothAdapterError The passed local adapter address does not match the physical
- adapter address of any local Bluetooth device.
+ adapter address of any local Bluetooth device. This value
+ was introduced by Qt 5.3.
\value UnknownError An unknown error has occurred.
*/
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
index 01993f25..e10d2ffe 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
@@ -48,19 +48,20 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
- const QBluetoothAddress &deviceAdapter)
+ const QBluetoothAddress &/*deviceAdapter*/)
: error(QBluetoothServiceDiscoveryAgent::NoError),
state(Inactive), deviceDiscoveryAgent(0),
mode(QBluetoothServiceDiscoveryAgent::MinimalDiscovery),
singleDevice(false), receiver(0), localDeviceReceiver(0)
{
QList<QBluetoothHostInfo> devices = QBluetoothLocalDevice::allDevices();
- Q_ASSERT(devices.count() == 1); //Android only supports one device at the moment
+ Q_ASSERT(devices.count() <= 1); //Android only supports one device at the moment
- if (deviceAdapter.isNull() && devices.count() > 0 )
- m_deviceAdapterAddress = devices.at(0).address();
- else
- m_deviceAdapterAddress = deviceAdapter;
+ if (devices.isEmpty()) {
+ error = QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Invalid Bluetooth adapter address");
+ return;
+ }
if (QtAndroidPrivate::androidSdkVersion() < 15)
qCWarning(QT_BT_ANDROID)
@@ -69,13 +70,10 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
<< "Service discovery will return empty list.";
- /* We assume that the current local adapter has been passed.
- Android only supports one adapter at the moment. If m_deviceAdapterAddress
- doesn't match the local adapter then we won't get to this point since
- we have an InvalidBluetoothAdapter error.
-
- The logic below must change once there is more than one adapter.
- */
+ /*
+ We assume that the current local adapter has been passed.
+ The logic below must change once there is more than one adapter.
+ */
btAdapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
"getDefaultAdapter",
diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp
index 96c3bbeb..cfb1a599 100644
--- a/src/bluetooth/qlowenergyservice.cpp
+++ b/src/bluetooth/qlowenergyservice.cpp
@@ -151,6 +151,9 @@ QT_BEGIN_NAMESPACE
to be a secondary service. Each service may be included
by another service which is indicated by IncludedService.
\value IncludedService The service is included by another service.
+ On some platforms, this flag cannot be determined until
+ the service that includes the current service was
+ discovered.
*/
/*!
@@ -319,6 +322,9 @@ QLowEnergyService::~QLowEnergyService()
Returns the UUIDs of all services which are included by the
current service.
+ The returned list is empty if this service instance's \l discoverDetails()
+ was not yet called or there are no known characteristics.
+
It is possible that an included service contains yet another service. Such
second level includes have to be obtained via their relevant first level
QLowEnergyService instance. Technically, this could create
@@ -344,7 +350,6 @@ QList<QBluetoothUuid> QLowEnergyService::includedServices() const
Therefore any service object instance created after
the first one has a state equal to already existing instances.
-
A service becomes invalid if the \l QLowEnergyController disconnects
from the remote device. An invalid service retains its internal state
at the time of the disconnect event. This implies that once the service
@@ -367,9 +372,14 @@ QLowEnergyService::ServiceState QLowEnergyService::state() const
/*!
Returns the type of the service.
+ \note The type attribute cannot be relied upon until the service has
+ reached the \l ServiceDiscovered state. This field is initialised
+ with \l PrimaryService.
+
\note On Android, it is not possible to determine whether a service
is a primary or secondary service. Therefore all services
have the \l PrimaryService flag set.
+
*/
QLowEnergyService::ServiceTypes QLowEnergyService::type() const
{
@@ -380,6 +390,9 @@ QLowEnergyService::ServiceTypes QLowEnergyService::type() const
Returns the matching characteristic for \a uuid; otherwise an invalid
characteristic.
+ The returned characteristic is invalid if this service instance's \l discoverDetails()
+ was not yet called or there are no characteristics with a matching \a uuid.
+
\sa characteristics()
*/
QLowEnergyCharacteristic QLowEnergyService::characteristic(const QBluetoothUuid &uuid) const
diff --git a/src/imports/bluetooth/plugins.qmltypes b/src/imports/bluetooth/plugins.qmltypes
index f7d0d08d..cf2146e2 100644
--- a/src/imports/bluetooth/plugins.qmltypes
+++ b/src/imports/bluetooth/plugins.qmltypes
@@ -30,7 +30,8 @@ Module {
"NoError": 0,
"InputOutputError": 1,
"PoweredOffError": 2,
- "UnknownError": 3
+ "UnknownError": 3,
+ "InvalidBluetoothAdapterError": 4
}
}
Property { name: "error"; type: "Error"; isReadonly: true }
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
index 20f47f65..01a53bfa 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -151,7 +151,19 @@ void QDeclarativeBluetoothDiscoveryModel::componentComplete()
void QDeclarativeBluetoothDiscoveryModel::errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error)
{
- d->m_error = static_cast<QDeclarativeBluetoothDiscoveryModel::Error>(error);
+ switch (error) {
+ case QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::InvalidBluetoothAdapterError; break;
+ case QBluetoothServiceDiscoveryAgent::NoError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::NoError; break;
+ case QBluetoothServiceDiscoveryAgent::InputOutputError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::InputOutputError; break;
+ case QBluetoothServiceDiscoveryAgent::PoweredOffError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::PoweredOffError; break;
+ case QBluetoothServiceDiscoveryAgent::UnknownError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::UnknownError; break;
+ }
+
emit errorChanged();
}
@@ -187,6 +199,12 @@ void QDeclarativeBluetoothDiscoveryModel::clearModel()
\li An IO failure occurred during device discovery
\row \li \c BluetoothDiscoveryModel.PoweredOffError
\li The bluetooth device is not powered on.
+ \row \li \c BluetoothDiscoveryModel.InvalidBluetoothAdapterError
+ \li There is no default Bluetooth device to perform the
+ service discovery. The model always uses the local default adapter.
+ Specifying a default adapter is not possible. If that's required,
+ \l QBluetoothServiceDiscoveryAgent should be directly used. This
+ value was introduced by Qt 5.4.
\row \li \c BluetoothDiscoveryModel.UnknownError
\li An unknown error occurred.
\endtable
@@ -407,6 +425,13 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
//qDebug() << "Minimal Discovery";
d->m_serviceAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery);
}
+
+ // we could not start service discovery
+ if (!d->m_serviceAgent->isActive()) {
+ d->m_running = false;
+ errorDiscovery(d->m_serviceAgent->error());
+ return;
+ }
}
}
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
index 279fb063..1834ce36 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
@@ -94,7 +94,8 @@ public:
NoError,
InputOutputError,
PoweredOffError,
- UnknownError
+ UnknownError,
+ InvalidBluetoothAdapterError
};
Error error() const;